当前位置: 首页 > news >正文

做网站月收入网站开发用什么字体

做网站月收入,网站开发用什么字体,怎么找需要做推广的公司,义乌公司网站封装层 封装格式(container format)可以看作是编码流(音频流、视频流等)数据的一层外壳#xff0c;将编码后的数据存储于此封装格式的文件之内。 封装又称容器#xff0c;容器的称法更为形象#xff0c;所谓容器#xff0c;就是存放内容的器具#xff0c;饮料是内容将编码后的数据存储于此封装格式的文件之内。 封装又称容器容器的称法更为形象所谓容器就是存放内容的器具饮料是内容那么装饮料的瓶子就是容器。 avformat_open_input()avformat_find_stream_info()av_read_frame()av_write_frame()av_interleaved_write_frame()avio_open()avformat_write_header()av_write_trailer() 1.解封装 1.分配解复用器上下文 avformat_alloc_context 2.根据 url 打开本地文件或网络流 avformat_open_input 3.读取媒体的部分数据包以获取码流信息 avformat_find_stream_info 4.读取码流信息循环处理 4.1 从文件中读取数据包 av_read_frame 4.2 定位文件 avformat_seek_file 或 av_seek_frame 5.关闭解复用器 avformat_close_input 本例子实现的是将音视频分离例如将封装格式为 FLV、MKV、MP4、AVI 等封装格式的文件将音频、视频读取出来并打印。 实现的过程可以大致用如下图表示 #include stdio.h extern C {#include libavformat/avformat.h } /** * brief 将一个AVRational类型的分数转换为double类型的浮点数 * param r:r为一个AVRational类型的结构体变量成员num表示分子成员den表示分母r的值即为(double)r.num / (double)r.den。用这种方法表示可以最大程度地避免精度的损失 * return 如果变量r的分母den为0则返回0为了避免除数为0导致程序死掉;其余情况返回(double)r.num / (double)r.den */ static double r2d(AVRational r) {return r.den 0 ? 0 : (double)r.num / (double)r.den; }int main() {//需要读取的本地媒体文件相对路径为video1.mp4这里由于文件video1.mp4就在工程目录下所以相对路径为video1.mp4const char *path ande_10s.mp4;//const char *path audio1.mp3;///av_register_all(); //初始化所有组件只有调用了该函数才能使用复用器和编解码器。否则调用函数avformat_open_input会失败无法获取媒体文件的信息avformat_network_init(); //打开网络流。这里如果只需要读取本地媒体文件不需要用到网络功能可以不用加上这一句AVDictionary *opts NULL;//AVFormatContext是描述一个媒体文件或媒体流的构成和基本信息的结构体AVFormatContext *ic NULL;//媒体打开函数调用该函数可以获得路径为path的媒体文件的信息并把这些信息保存到指针ic指向的空间中调用该函数后会分配一个空间让指针ic指向该空间int re avformat_open_input(ic, path, NULL, opts);if (re ! 0) //如果打开媒体文件失败打印失败原因。比如如果上面没有调用函数av_register_all则会打印“XXX failed!:Invaliddata found when processing input”{char buf[1024] { 0 };av_strerror(re, buf, sizeof(buf) - 1);printf(open %s failed!:%s, path, buf);}else //打开媒体文件成功{printf(打开媒体文件 %s 成功!\n, path);//调用该函数可以进一步读取一部分视音频数据并且获得一些相关的信息。//调用avformat_open_input之后我们无法获取到正确和所有的媒体参数所以还得要调用avformat_find_stream_info进一步的去获取。avformat_find_stream_info(ic, NULL);//调用avformat_open_input读取到的媒体文件的路径/名字printf(媒体文件名称:%s\n, ic-filename);//视音频流的个数如果一个媒体文件既有音频又有视频则nb_streams的值为2。如果媒体文件只有音频则值为1printf(视音频流的个数:%d\n, ic-nb_streams);//媒体文件的平均码率,单位为bpsprintf(媒体文件的平均码率:%lldbps\n, ic-bit_rate);printf(duration:%d\n, ic-duration);int tns, thh, tmm, tss;tns (ic-duration) / AV_TIME_BASE;thh tns / 3600;tmm (tns % 3600) / 60;tss (tns % 60);printf(媒体文件总时长%d时%d分%d秒\n, thh, tmm, tss); //通过上述运算可以得到媒体文件的总时长printf(\n);//通过遍历的方式读取媒体文件视频和音频的信息//新版本的FFmpeg新增加了函数av_find_best_stream也可以取得同样的效果但这里为了兼容旧版本还是用这种遍历的方式for (int i 0; i ic-nb_streams; i){AVStream *as ic-streams[i];if (AVMEDIA_TYPE_AUDIO as-codecpar-codec_type) //如果是音频流则打印音频的信息{printf(音频信息:\n);printf(index:%d\n, as-index); //如果一个媒体文件既有音频又有视频则音频index的值一般为1。但该值不一定准确所以还是得通过as-codecpar-codec_type判断是视频还是音频printf(音频采样率:%dHz\n, as-codecpar-sample_rate); //音频编解码器的采样率单位为Hzif (AV_SAMPLE_FMT_FLTP as-codecpar-format) //音频采样格式{printf(音频采样格式:AV_SAMPLE_FMT_FLTP\n);}else if (AV_SAMPLE_FMT_S16P as-codecpar-format){printf(音频采样格式:AV_SAMPLE_FMT_S16P\n);}printf(音频信道数目:%d\n, as-codecpar-channels); //音频信道数目if (AV_CODEC_ID_AAC as-codecpar-codec_id) //音频压缩编码格式{printf(音频压缩编码格式:AAC\n);}else if (AV_CODEC_ID_MP3 as-codecpar-codec_id){printf(音频压缩编码格式:MP3\n);}int DurationAudio (as-duration) * r2d(as-time_base); //音频总时长单位为秒。注意如果把单位放大为毫秒或者微妙音频总时长跟视频总时长不一定相等的printf(音频总时长%d时%d分%d秒\n, DurationAudio / 3600, (DurationAudio % 3600) / 60, (DurationAudio % 60)); //将音频总时长转换为时分秒的格式打印到控制台上printf(\n);}else if (AVMEDIA_TYPE_VIDEO as-codecpar-codec_type) //如果是视频流则打印视频的信息{printf(视频信息:\n);printf(index:%d\n, as-index); //如果一个媒体文件既有音频又有视频则视频index的值一般为0。但该值不一定准确所以还是得通过as-codecpar-codec_type判断是视频还是音频printf(视频帧率:%lffps\n, r2d(as-avg_frame_rate)); //视频帧率,单位为fps表示每秒出现多少帧if (AV_CODEC_ID_MPEG4 as-codecpar-codec_id) //视频压缩编码格式{printf(视频压缩编码格式:MPEG4\n);}printf(帧宽度:%d 帧高度:%d\n, as-codecpar-width, as-codecpar-height); //视频帧宽度和帧高度int DurationVideo (as-duration) * r2d(as-time_base); //视频总时长单位为秒。注意如果把单位放大为毫秒或者微妙音频总时长跟视频总时长不一定相等的printf(视频总时长%d时%d分%d秒\n, DurationVideo / 3600, (DurationVideo % 3600) / 60, (DurationVideo % 60)); //将视频总时长转换为时分秒的格式打印到控制台上printf(\n);}}//av_dump_format(ic, 0, path, 0);}if (ic){avformat_close_input(ic); //关闭一个AVFormatContext,和函数avformat_open_input()成对使用}avformat_network_deinit();getchar(); //加上这一句防止程序打印完信息就马上退出了return 0; }int mainsdf3324sf(int argc, char **argv) {// 1. 打开文件const char *ifilename ande_10s.mp4;printf(in_filename %s\n, ifilename);avformat_network_init();// AVFormatContext是描述一个媒体文件或媒体流的构成和基本信息的结构体AVFormatContext *ifmt_ctx NULL; // 输入文件的demux// 打开文件主要是探测协议类型如果是网络文件则创建网络链接int ret avformat_open_input(ifmt_ctx, ifilename, NULL, NULL);if (ret 0) {char buf[1024] {0};av_strerror(ret, buf, sizeof (buf) - 1);printf(open %s failed: %s\n, ifilename, buf);return -1;}// 2. 读取码流信息ret avformat_find_stream_info(ifmt_ctx, NULL);if (ret 0) //如果打开媒体文件失败打印失败原因{char buf[1024] { 0 };av_strerror(ret, buf, sizeof(buf) - 1);printf(avformat_find_stream_info %s failed:%s\n, ifilename, buf);avformat_close_input(ifmt_ctx);return -1;}// 3.打印总体信息printf_s(\n av_dump_format in_filename:%s \n, ifilename);av_dump_format(ifmt_ctx, 0, ifilename, 0);printf_s(\n av_dump_format finish \n\n);printf(media name:%s\n, ifmt_ctx-url);printf(stream number:%d\n, ifmt_ctx-nb_streams); // nb_streams媒体流数量printf(media average ratio:%lldkbps\n,(int64_t)(ifmt_ctx-bit_rate/1024)); // 媒体文件的码率,单位为bps/1000Kbps// duration: 媒体文件时长单位微妙int total_seconds (ifmt_ctx-duration) / AV_TIME_BASE; // 1000us 1ms, 1000ms 1秒printf(audio duration: %02d:%02d:%02d\n,total_seconds / 3600, (total_seconds % 3600) / 60, (total_seconds % 60));printf(\n);// 4.读取码流信息// 音频int audioindex av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);if (audioindex 0) {printf(av_find_best_stream %s eror., av_get_media_type_string(AVMEDIA_TYPE_AUDIO));return -1;}AVStream *audio_stream ifmt_ctx-streams[audioindex];printf(----- Audio info:\n);printf(index: %d\n, audio_stream-index); // 序列号printf(samplarate: %d Hz\n, audio_stream-codecpar-sample_rate); // 采样率printf(sampleformat: %d\n, audio_stream-codecpar-format); // 采样格式 AV_SAMPLE_FMT_FLTP:8printf(audio codec: %d\n, audio_stream-codecpar-codec_id); // 编码格式 AV_CODEC_ID_MP3:86017 AV_CODEC_ID_AAC:86018if (audio_stream-duration ! AV_NOPTS_VALUE) {int audio_duration audio_stream-duration * av_q2d(audio_stream-time_base);printf(audio duration: %02d:%02d:%02d\n,audio_duration / 3600, (audio_duration % 3600) / 60, (audio_duration % 60));}// 视频int videoindex av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);if (videoindex 0) {printf(av_find_best_stream %s eror., av_get_media_type_string(AVMEDIA_TYPE_VIDEO));return -1;}AVStream *video_stream ifmt_ctx-streams[videoindex];printf(----- Video info:\n);printf(index: %d\n, video_stream-index); // 序列号printf(fps: %lf\n, av_q2d(video_stream-avg_frame_rate)); // 帧率printf(width: %d, height:%d \n, video_stream-codecpar-width, video_stream-codecpar-height);printf(video codec: %d\n, video_stream-codecpar-codec_id); // 编码格式 AV_CODEC_ID_H264: 27if (video_stream-duration ! AV_NOPTS_VALUE) {int video_duration video_stream-duration * av_q2d(video_stream-time_base);printf(audio duration: %02d:%02d:%02d\n,video_duration / 3600, (video_duration % 3600) / 60, (video_duration % 60));}// 5.提取码流AVPacket *pkt av_packet_alloc();int pkt_count 0;int print_max_count 100;printf(\n-----av_read_frame start\n);while (1){ret av_read_frame(ifmt_ctx, pkt);if (ret 0) {printf(av_read_frame end\n);break;}if(pkt_count print_max_count){if (pkt-stream_index audioindex){printf(audio pts: %lld\n, pkt-pts);printf(audio dts: %lld\n, pkt-dts);printf(audio size: %d\n, pkt-size);printf(audio pos: %lld\n, pkt-pos);printf(audio duration: %lf\n\n,pkt-duration * av_q2d(ifmt_ctx-streams[audioindex]-time_base));}else if (pkt-stream_index videoindex){printf(video pts: %lld\n, pkt-pts);printf(video dts: %lld\n, pkt-dts);printf(video size: %d\n, pkt-size);printf(video pos: %lld\n, pkt-pos);printf(video duration: %lf\n\n,pkt-duration * av_q2d(ifmt_ctx-streams[videoindex]-time_base));}else{printf(unknown stream_index:\n, pkt-stream_index);}}av_packet_unref(pkt);}// 6.结束if(pkt)av_packet_free(pkt);if(ifmt_ctx)avformat_close_input(ifmt_ctx);avformat_network_deinit();//getchar(); //加上这一句防止程序打印完信息马上退出return 0; }2.转封装 从一种视频容器转成另一种视频容器 所谓的封 装格 式转 换就是在 AVIFLVMKV MP4 这些格式 之间转换对应.avi.flv.mkv.mp4 文件。需要注意的是本程序并不进行视音频的编码和解码工作。而是直接将视音频压缩码流从一种封装格式文件中获取出来然后打包成另外一种封装格式的文件。 上图例举了一个举例FLV视频H.264音频AAC转码为 AVI视频MPEG2音频 MP3的例子。可见视频转码的过程通俗地讲相当于把视频和音频重新“录”了一遍。 /*** file* libavformat/libavcodec demuxing and muxing API example.** Remux streams from one container format to another.* example remuxing.c*/#include libavutil/timestamp.h #include libavformat/avformat.hstatic void log_packet(const AVFormatContext *fmt_ctx, const AVPacket *pkt, const char *tag) {AVRational *time_base fmt_ctx-streams[pkt-stream_index]-time_base;printf(%s: pts:%s pts_time:%s dts:%s dts_time:%s duration:%s duration_time:%s stream_index:%d\n,tag,av_ts2str(pkt-pts), av_ts2timestr(pkt-pts, time_base),av_ts2str(pkt-dts), av_ts2timestr(pkt-dts, time_base),av_ts2str(pkt-duration), av_ts2timestr(pkt-duration, time_base),pkt-stream_index); }int main234ssfdx(int argc, char **argv) {AVOutputFormat *ofmt NULL;AVFormatContext *ifmt_ctx NULL, *ofmt_ctx NULL;AVPacket pkt;const char *in_filename, *out_filename;int ret, i;int stream_index 0;int *stream_mapping NULL;int stream_mapping_size 0;if (argc 3) {printf(usage: %s input output\nAPI example program to remux a media file with libavformat and libavcodec.\nThe output format is guessed according to the file extension.\n\n, argv[0]);return 1;}in_filename argv[1];out_filename argv[2];if ((ret avformat_open_input(ifmt_ctx, in_filename, 0, 0)) 0) {fprintf(stderr, Could not open input file %s, in_filename);goto end;}if ((ret avformat_find_stream_info(ifmt_ctx, 0)) 0) {fprintf(stderr, Failed to retrieve input stream information);goto end;}printf(\n\n-------av_dump_format:ifmt_ctx----------------\n);av_dump_format(ifmt_ctx, 0, in_filename, 0);avformat_alloc_output_context2(ofmt_ctx, NULL, NULL, out_filename);if (!ofmt_ctx) {fprintf(stderr, Could not create output context\n);ret AVERROR_UNKNOWN;goto end;}stream_mapping_size ifmt_ctx-nb_streams;stream_mapping av_mallocz_array(stream_mapping_size, sizeof(*stream_mapping));if (!stream_mapping) {ret AVERROR(ENOMEM);goto end;}ofmt ofmt_ctx-oformat;for (i 0; i ifmt_ctx-nb_streams; i) {AVStream *out_stream;AVStream *in_stream ifmt_ctx-streams[i];AVCodecParameters *in_codecpar in_stream-codecpar;if (in_codecpar-codec_type ! AVMEDIA_TYPE_AUDIO in_codecpar-codec_type ! AVMEDIA_TYPE_VIDEO in_codecpar-codec_type ! AVMEDIA_TYPE_SUBTITLE) {stream_mapping[i] -1;continue;}stream_mapping[i] stream_index;out_stream avformat_new_stream(ofmt_ctx, NULL);if (!out_stream) {fprintf(stderr, Failed allocating output stream\n);ret AVERROR_UNKNOWN;goto end;}ret avcodec_parameters_copy(out_stream-codecpar, in_codecpar);if (ret 0) {fprintf(stderr, Failed to copy codec parameters\n);goto end;}out_stream-codecpar-codec_tag 0;}printf(\n\n-------av_dump_format:ofmt_ctx----------------\n);av_dump_format(ofmt_ctx, 0, out_filename, 1);if (!(ofmt-flags AVFMT_NOFILE)) {ret avio_open(ofmt_ctx-pb, out_filename, AVIO_FLAG_WRITE);if (ret 0) {fprintf(stderr, Could not open output file %s, out_filename);goto end;}}ret avformat_write_header(ofmt_ctx, NULL);if (ret 0) {fprintf(stderr, Error occurred when opening output file\n);goto end;}while (1) {AVStream *in_stream, *out_stream;/// 读取音视频压缩包ret av_read_frame(ifmt_ctx, pkt);if (ret 0)break;in_stream ifmt_ctx-streams[pkt.stream_index];if (pkt.stream_index stream_mapping_size ||stream_mapping[pkt.stream_index] 0) {av_packet_unref(pkt);continue;}pkt.stream_index stream_mapping[pkt.stream_index];out_stream ofmt_ctx-streams[pkt.stream_index];log_packet(ifmt_ctx, pkt, in);/* copy packet */pkt.pts av_rescale_q_rnd(pkt.pts, in_stream-time_base, out_stream-time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);pkt.dts av_rescale_q_rnd(pkt.dts, in_stream-time_base, out_stream-time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);pkt.duration av_rescale_q(pkt.duration, in_stream-time_base, out_stream-time_base);pkt.pos -1;log_packet(ofmt_ctx, pkt, out);/// 交织写音视频包ret av_interleaved_write_frame(ofmt_ctx, pkt);if (ret 0) {fprintf(stderr, Error muxing packet\n);break;}av_packet_unref(pkt);//包需要解引用}av_write_trailer(ofmt_ctx); end:avformat_close_input(ifmt_ctx);/* close output */if (ofmt_ctx !(ofmt-flags AVFMT_NOFILE))avio_closep(ofmt_ctx-pb);avformat_free_context(ofmt_ctx);av_freep(stream_mapping);if (ret 0 ret ! AVERROR_EOF) {fprintf(stderr, Error occurred: %s\n, av_err2str(ret));return 1;}return 0; }
http://www.tj-hxxt.cn/news/138929.html

相关文章:

  • 常州发布信息的有什么网站网络营销作业策划方案
  • wordpress建站不好用wordpress怎么设置
  • 能打开的a站广东网站设计哪家好
  • 注册网站会员有风险吗app免费软件
  • 如何建立一个带论坛的网站安徽住房和城乡建设厅官网
  • 门户网站栏目维护建设方案衡阳seo外包
  • wordpress站长工作什么专业学网页设计制作
  • 谷歌怎么做公司网站如何解析后用二级域名做网站
  • 泌阳专业网站建设注册电子邮箱免费注册
  • 镇江做网站哪家公司好做企业网站需要什么文件
  • 网站建设 网络推广广州市设计院官网
  • 护肤网站的功能设计咸宁抖音seo收费标准
  • 盐城市建设局网站网站架构设计师有哪些学校可以报考
  • 如何搭建一个个人网站哪个网站简历做的好
  • 西部数码网站助手教程网页设计师培训哪个好
  • 广州网站制作是什么漯河网站建设 千弘网络
  • 做擦边球网站会不会违法呢莱芜一中贴吧
  • 广州设计网站建设怎么修改网站后台权限
  • 自己做的网站怎么发布上如何进行网站性能优化
  • 网站seo方案策划书网站建设的方式有哪些
  • 电子政务网站建设的步骤一般为四川手机网站建设公司
  • 网站建设证书海南七星彩网站开发
  • 海报在线制作免费网站长春设计网站
  • 微型企业网络设计方案seo网站建设公司
  • 企业集团网站源码固定ip做网站和域名区别
  • 怎样申请自己企业的网站化州网络推广
  • 网站的运作流程wordpress 登陆才能看
  • 高端网站哪种好网页游戏排行力荐新壹玩
  • 怎么管理网站的内容吗云主机网站的空间在哪里
  • 深圳网站外包深圳中高端网站建设