最近在做h264编码,一直报这个错误:
broken ffmpeg default settings detected
use an encoding preset (e.g. -vpre medium)
preset usage: -vpre <speed> -vpre <profile>
speed presets are listed in x264 --help
profile is optional; x264 defaults to high
周折了好几天在网上查了大量的资料,结合libx264的源码发现是参数配置的问题,源码在libx264的encoder/encoder.c中:
/* Detect default ffmpeg settings and terminate with an error. */ if( b_open ) { int score = 0; score += h->param.analyse.i_me_range == 0; score += h->param.rc.i_qp_step == 3; score += h->param.i_keyint_max == 12; score += h->param.rc.i_qp_min == 2; score += h->param.rc.i_qp_max == 31; score += h->param.rc.f_qcompress == 0.5; score += fabs(h->param.rc.f_ip_factor - 1.25) < 0.01; score += fabs(h->param.rc.f_pb_factor - 1.25) < 0.01; score += h->param.analyse.inter == 0 && h->param.analyse.i_subpel_refine == 8; if( score >= 5 ) { x264_log( h, X264_LOG_ERROR, "broken ffmpeg default settings detected\n" ); x264_log( h, X264_LOG_ERROR, "use an encoding preset (e.g. -vpre medium)\n" ); x264_log( h, X264_LOG_ERROR, "preset usage: -vpre <speed> -vpre <profile>\n" ); x264_log( h, X264_LOG_ERROR, "speed presets are listed in x264 --help\n" ); x264_log( h, X264_LOG_ERROR, "profile is optional; x264 defaults to high\n" ); return -1; } }
解决方法就是在avcodec_open2之前设置AVCodecontex中的几个参数:
ctx->me_range = 16;
ctx->max_qdiff = 4;
ctx->qmin = 0;
ctx->qmax = 69;
ctx->qcompress = 0.6;
这几个是libx264默认的参数。
x264编码参数设置可参考http://mewiki.project357.com/wiki/X264_Settings