学习ffmpeg官方示例代码transcoding.c遇到的问题
来源:互联网 发布:表格怎么把相同的数据 编辑:程序博客网 时间:2024/05/17 09:19
编译测试遇到问题,首先我的编译命令:
export PKG_CONFIG_PATH=~/ffmpeg_build/lib/pkgconfig:$PKG_CONFIG_PATH//将库的路径添加到PKG_CONFIG_PATH中gcc transcoding.c -o transcoding `pkg-config --libs --cflags libavcodec libavutil libavfilter`
编译完成,运行命令:
./transcoding input.ts output.avi
issue 1 - [libx264 @ 0x7fe4ac851600] broken ffmpeg default settings detected
这个错误及其下面的信息告诉我们,在打开输出文件的视频编码器时出现了错误,这通常是由于编码器参数设置不当造成的。通过搜索,发现了这篇文章对这个问题解释的比较清楚:
http://blog.csdn.net/cffishappy/article/details/7680097
解决方法:
在transcoding.c中的open_output_file函数中,修改的部分如下(只增加了13-17行):
if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) { enc_ctx->height = dec_ctx->height; enc_ctx->width = dec_ctx->width; enc_ctx->sample_aspect_ratio = dec_ctx->sample_aspect_ratio; /* take first format from list of supported formats */ if (encoder->pix_fmts) enc_ctx->pix_fmt = encoder->pix_fmts[0]; else enc_ctx->pix_fmt = dec_ctx->pix_fmt; /* video time_base can be set to whatever is handy and supported by encoder */ enc_ctx->time_base = dec_ctx->time_base; enc_ctx->me_range = 16; enc_ctx->max_qdiff = 4; enc_ctx->qmin = 10; enc_ctx->qmax = 51; enc_ctx->qcompress = 0.6; } else { enc_ctx->sample_rate = dec_ctx->sample_rate; enc_ctx->channel_layout = dec_ctx->channel_layout; enc_ctx->channels = av_get_channel_layout_nb_channels(enc_ctx->channel_layout); /* take first format from list of supported formats */ enc_ctx->sample_fmt = encoder->sample_fmts[0]; enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate}; }
这次的视频编码可以打开并正常编码了,可是音频部分又出现了问题,关于这个问题的解答可以看这个文章:
http://www.tuicool.com/articles/NNNVv2z
issue2 - [mp4 @ 0x7fbe86803e00] Malformed AAC bitstream detected
测试中本人未遇到这个错误,记下来以便以后使用吧。stackoverflow中提供了一种方法,可以使程序正常运行,但处理结果中只有音频被保留,
其实,只需要调整一下代码顺序就可以了。
解决方法
还是在transcoding.c中的open_output_file函数中,只是把for循环尾部的那句代码:
if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
提前到for循环中整个if判断结构的前面就行了,因为我们在打开编码器前,没有设置编码器上下文中enc_ctx->flags这个参数,所以把这句提前了就解决问题了。如下:
if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) { enc_ctx->height = dec_ctx->height; enc_ctx->width = dec_ctx->width; enc_ctx->sample_aspect_ratio = dec_ctx->sample_aspect_ratio; /* take first format from list of supported formats */ if (encoder->pix_fmts) enc_ctx->pix_fmt = encoder->pix_fmts[0]; else enc_ctx->pix_fmt = dec_ctx->pix_fmt; /* video time_base can be set to whatever is handy and supported by encoder */ enc_ctx->time_base = dec_ctx->time_base; enc_ctx->me_range = 16; enc_ctx->max_qdiff = 4; enc_ctx->qmin = 10; enc_ctx->qmax = 51; enc_ctx->qcompress = 0.6; } else { enc_ctx->sample_rate = dec_ctx->sample_rate; enc_ctx->channel_layout = dec_ctx->channel_layout; enc_ctx->channels = av_get_channel_layout_nb_channels(enc_ctx->channel_layout); /* take first format from list of supported formats */ enc_ctx->sample_fmt = encoder->sample_fmts[0]; enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate}; }
issue3 - 处理后的结果比原视频模糊
在经过以上两个问题的解决后,编译通过是没有问题了,不过你可能会不满意输出视频的质量,觉得它比原视频模糊了许多,这时我们可以调节#issue1中的代码:
enc_ctx->qmax = 51;
把这个参数改小点,可以减小编码时的量化间隔,提高编码视频的质量,不过你可能因此加长整个编码的时间。
例如我将其改为:
enc_ctx->qmax = 30;
阅读全文
2 0
- 学习ffmpeg官方示例代码transcoding.c遇到的问题
- 学习ffmpeg官方示例transcoding.c遇到的问题和解决方法
- ffmpeg遇到的问题
- ffmpeg学习(1)----下载及安装中遇到的问题
- 使用ffmpeg遇到的问题
- 编译ffmpeg遇到的问题
- 导入ffmpeg 遇到的问题
- c语言学习中遇到的问题
- 学习ffmpeg.c过程中遇上的系列问题
- 交叉编译ffmpeg遇到的问题
- wince+ffmpeg+sdl遇到的一些问题
- ffmpeg在编译中遇到的问题
- ffmpeg configure遇到的奇怪问题
- 编译FFmpeg遇到的问题,放弃了
- ffmpeg编译过程遇到的问题
- linux调用ffmpeg 遇到的问题
- 在VS2013编译FFmpeg遇到的问题
- ffmpeg Windows下编译遇到的问题
- WEB前端一些兼容IE8 浏览器的写法
- 20170605计算机视觉报告小结
- 通过Daffodil for VS使VS2010的IDE可以用VC6 VC7.1 VC9等编译器进行项目编译
- TextView
- javascript学习笔记一【预解释】
- 学习ffmpeg官方示例代码transcoding.c遇到的问题
- RecyclerView源码解析之缓存机制
- Android 利用Toolbar打造统一风格的标题栏
- Vue2项目问题汇总(一)
- 怎么解决java.lang.NoClassDefFoundError错误
- java解析xml汇总
- a标签中target属性
- TokenBucket(令牌桶算法) LeakBucket(漏桶算法) 两种限流算法
- 架构模式:MVC,MVP&MVVM