ffmpeg參數設置,AVCodecContext設置, h264 profile


 c->profile  =FF_PROFILE_H264_MAIN                 ;

 

FFmpeg and x264 Encoding Guide 參數說明:http://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide

preset 與編碼速度和質量相關

av_opt_set(c->priv_data, "preset", "slow", 0);  Current presets in descending order of speed are: ultrafast,superfastveryfastfasterfastmediumslowslowerveryslow,placebo.

priv_data  屬於每個編碼器特有的設置域,用av_opt_set 設置

 

 

2014/5/29 :今天發現 av_opt_set(enc_ctx->priv_data, "preset", "slow", 0);   slow的編碼質量比medium(默認值)好多了。

固定碼率150K,設置slow時:編碼速度:245 fps 4ms

[libx264 @ 014bbb40] frame I:38 Avg QP:33.69 size: 3763
[libx264 @ 014bbb40] frame P:262 Avg QP:35.79 size: 381

meidum 時:編碼速度:335 fps 2ms,

[libx264 @ 018dbb40] frame I:38 Avg QP:34.33 size: 3234
[libx264 @ 018dbb40] frame P:262 Avg QP:37.83 size: 455

veryslow 時:編碼速度:140 fps 7ms

[libx264 @ 0187cb40] frame I:38 Avg QP:35.10 size: 3582
[libx264 @ 0187cb40] frame P:262 Avg QP:37.24 size: 405

 

如何設置固定碼率編碼 

CBR (Constant Bit Rate)

There is no native CBR mode, but you can "simulate" a constant bit rate setting by tuning the parameters of ABR, like

ffmpeg -i input -c:v libx264 -b:v 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v

in this example, -bufsize is the "rate control buffer" so it will enforce your requested "average" (4000k in this case) across each 1835k worth of video. So basically it is assumed that the receiver/end player will buffer that much data so it's ok to fluctuate within that much.

Of course, if it's all just empty/black frames then it will still serve less than that many bits/s (but it will raise the quality level as much as it can, up to the crf level).

 

只設置bit_rate是平均碼率,不一定能控制住

c->bit_rate = 400000;
c->rc_max_rate = 400000;
c->rc_min_rate = 400000;

提示  [libx264 @ 00c70be0] VBV maxrate specified, but no bufsize, ignored   

再設置  c->rc_buffer_size = 200000;  即可。

如此控制后編碼質量明顯差了。。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM