ffmpeg x264 編碼時 avcodec_open報錯

來源:互聯網
上載者:User

在翻閱了無數的文章後,發現其原因是在於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)

解決方案:在 x264 的source file encoder/encoder.c 中找到該報錯的地方/* 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;        }    }We can see that if score >= 5,the function to open the codec will fail.We must at least set 4 param of the AVCodecContext before open it.在avcodec_open函數之間增加如下幾個AVCodecContext 的初始化:/*default settings for x264*/        ctx->me_range = 16;        ctx->max_qdiff = 4;        ctx->qmin = 10;        ctx->qmax = 51;        ctx->qcompress = 0.6; 

OK,解決。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.