ffmpeg x264 编码时 avcodec_open报错

96 篇文章 0 订阅
80 篇文章 1 订阅


在翻阅了无数的文章后,发现其原因是在于x264内部的参数检测,归要到底还是由于自己在ffmpeg中设置的参数不正确导致的。以下是x264针对此判断代码如下:

相关判断位于encoder/encoder.c 393行:

/* Detect default ffmpeg settings and terminate with an error. */ { 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 (vpre)\n" ); return -1; } } 

应用X264进行H.264编码,如果编码不能成功,大部分情况是编码参数选择不正确



使用ffmpeg x264进行编码的时候,avcodec_open报错:
[libx264 @ 00021bb0]broken ffmpeg default settings detected
[libx264 @ 00021bb0]use an encoding preset (vpre)

[cpp]  view plain copy
  1. 解决方法:在 x264 的source file encoder/encoder.c 中找到该报错的地方  
  2. /* Detect default ffmpeg settings and terminate with an error. */  
  3.     {  
  4.         int score = 0;  
  5.         score += h->param.analyse.i_me_range == 0;  
  6.         score += h->param.rc.i_qp_step == 3;  
  7.         score += h->param.i_keyint_max == 12;  
  8.         score += h->param.rc.i_qp_min == 2;  
  9.         score += h->param.rc.i_qp_max == 31;  
  10.         score += h->param.rc.f_qcompress == 0.5;  
  11.         score += fabs(h->param.rc.f_ip_factor - 1.25) < 0.01;  
  12.         score += fabs(h->param.rc.f_pb_factor - 1.25) < 0.01;  
  13.         score += h->param.analyse.inter == 0 && h->param.analyse.i_subpel_refine == 8;  
  14.         if( score >= 5 )  
  15.         {  
  16.             x264_log( h, X264_LOG_ERROR, "broken ffmpeg default settings detected\n" );  
  17.             x264_log( h, X264_LOG_ERROR, "use an encoding preset (vpre)\n" );  
  18.             return -1;  
  19.         }  
  20.     }  
  21.   
  22. We can see that if score >= 5,the function to open the codec will fail.  
  23. We must at least set 4 param of the AVCodecContext before open it.  
  24. 在avcodec_open函数之间增加如下几个AVCodecContext 的初始化:  
  25. /*default settings for x264*/  
  26.         ctx->me_range = 16;  
  27.         ctx->max_qdiff = 4;  
  28.         ctx->qmin = 10;  
  29.         ctx->qmax = 51;  
  30.         ctx->qcompress = 0.6;   


OK,解决。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值