相關(guān)
概念
h264編碼算法復(fù)雜、參數(shù)眾多钝计,單碼率控制又分為三種模式恋博。
- VBR(Variable Bit Rate)即動(dòng)態(tài)比特率,其碼率可以隨著圖像的復(fù)雜程度的不同而變化私恬,因此其編碼效率比較高债沮,Motion發(fā)生時(shí),馬賽克很少本鸣。碼率控制算法根據(jù)圖像內(nèi)容確定使用的比特率疫衩,圖像內(nèi)容比較簡(jiǎn)單則分配較少的碼率(似乎碼字更合適),圖像內(nèi)容復(fù)雜則分配較多的碼字荣德,這樣既保證了質(zhì)量闷煤,又兼顧帶寬限制。這種算法優(yōu)先考慮圖像質(zhì)量涮瞻。
- CBR(Constant Bit Rate)是以恒定比特率方式進(jìn)行編碼鲤拿,有Motion發(fā)生時(shí),由于碼率恒定署咽,只能通過(guò)增大QP來(lái)減少碼字大小近顷,圖像質(zhì)量變差生音,當(dāng)場(chǎng)景靜止時(shí),圖像質(zhì)量又變好窒升,因此圖像質(zhì)量不穩(wěn)定缀遍。這種算法優(yōu)先考慮碼率(帶寬)。
- CVBR(Constrained VariableBit Rate)它是VBR的一種改進(jìn)方法饱须。這種方法的兼顧了以上兩種方法的優(yōu)點(diǎn):在圖像內(nèi)容靜止時(shí)域醇,節(jié)省帶寬,有Motion發(fā)生時(shí)蓉媳,利用前期節(jié)省的帶寬來(lái)盡可能的提高圖像質(zhì)量譬挚,達(dá)到同時(shí)兼顧帶寬和圖像質(zhì)量的目的。同時(shí)i_bitrate也需要設(shè)置督怜。
碼率控制
間接影響
除了視頻質(zhì)量外有效影響視頻碼率的有
- 關(guān)鍵幀間隔
碼率∝關(guān)鍵幀間隔(視頻質(zhì)量其他參數(shù)恒定)
- 分辨率
碼率∝分辨率(視頻質(zhì)量其他參數(shù)恒定)
- 幀率
碼率∝幀率(視頻質(zhì)量其他參數(shù)恒定)
注:
x264:i_fps_num = 15;i_fps_den= 1 ;//幀率15殴瘦。
ffmpeg:time_base.num=1;time_den=1;//幀率15。
等等視頻質(zhì)量的參數(shù)号杠,無(wú)可厚非蚪腋,視頻質(zhì)量提升,要么編碼速度降低姨蟋,要么碼率增大屉凯。
- B幀數(shù)
碼率∝1/b幀數(shù)(視頻質(zhì)量其他參數(shù)恒定)
直接影響
X264_RC_CQP 動(dòng)態(tài)比特率
X264_RC_CRF 恒定比特率
X264_RC_ABR 平均比特率
未選擇時(shí),優(yōu)先選擇的順序是 bitrate > QP > CRF眼溶,會(huì)按照該順序排查參數(shù)悠砚,直到發(fā)現(xiàn)某種類型參數(shù)合法時(shí)確定類型。
if( bitrate ) rc_method = ABR; else if ( qp || qp_constant ) rc_method = CQP; else rc_method = CRF;
附:
x264中x264_param_t->rc 結(jié)構(gòu)體
struct
{
int i_rc_method; /* X264_RC_* */
int i_qp_constant; /* 0 to (51 + 6*(x264_bit_depth-8)). 0=lossless */
int i_qp_min; /* min allowed QP value */
int i_qp_max; /* max allowed QP value */
int i_qp_step; /* max QP step between frames */
int i_bitrate;
float f_rf_constant; /* 1pass VBR, nominal QP */
float f_rf_constant_max; /* In CRF mode, maximum CRF as caused by VBV */
float f_rate_tolerance;
int i_vbv_max_bitrate;
int i_vbv_buffer_size;
float f_vbv_buffer_init; /* <=1: fraction of buffer_size. >1: kbit */
float f_ip_factor;
float f_pb_factor;
/* VBV filler: force CBR VBV and use filler bytes to ensure hard-CBR.
* Implied by NAL-HRD CBR. */
int b_filler;
int i_aq_mode; /* psy adaptive QP. (X264_AQ_*) */
float f_aq_strength;
int b_mb_tree; /* Macroblock-tree ratecontrol. */
int i_lookahead;
/* 2pass */
int b_stat_write; /* Enable stat writing in psz_stat_out */
char *psz_stat_out; /* output filename (in UTF-8) of the 2pass stats file */
int b_stat_read; /* Read stat from psz_stat_in and use it */
char *psz_stat_in; /* input filename (in UTF-8) of the 2pass stats file */
/* 2pass params (same as ffmpeg ones) */
float f_qcompress; /* 0.0 => cbr, 1.0 => constant qp */
float f_qblur; /* temporally blur quants */
float f_complexity_blur; /* temporally blur complexity */
x264_zone_t *zones; /* ratecontrol overrides */
int i_zones; /* number of zone_t's */
char *psz_zones; /* alternate method of specifying zones */
} rc;