相關
概念
h264編碼算法復雜、參數眾多,單碼率控制又分為三種模式。
- VBR(Variable Bit Rate)即動態比特率,其碼率可以隨著圖像的復雜程度的不同而變化,因此其編碼效率比較高,Motion發生時,馬賽克很少。碼率控制算法根據圖像內容確定使用的比特率,圖像內容比較簡單則分配較少的碼率(似乎碼字更合適),圖像內容復雜則分配較多的碼字,這樣既保證了質量,又兼顧帶寬限制。這種算法優先考慮圖像質量。
- CBR(Constant Bit Rate)是以恒定比特率方式進行編碼,有Motion發生時,由于碼率恒定,只能通過增大QP來減少碼字大小,圖像質量變差,當場景靜止時,圖像質量又變好,因此圖像質量不穩定。這種算法優先考慮碼率(帶寬)。
- CVBR(Constrained VariableBit Rate)它是VBR的一種改進方法。這種方法的兼顧了以上兩種方法的優點:在圖像內容靜止時,節省帶寬,有Motion發生時,利用前期節省的帶寬來盡可能的提高圖像質量,達到同時兼顧帶寬和圖像質量的目的。同時i_bitrate也需要設置。
碼率控制
間接影響
除了視頻質量外有效影響視頻碼率的有
- 關鍵幀間隔
碼率∝關鍵幀間隔(視頻質量其他參數恒定)
- 分辨率
碼率∝分辨率(視頻質量其他參數恒定)
- 幀率
碼率∝幀率(視頻質量其他參數恒定)
注:
x264:i_fps_num = 15;i_fps_den= 1 ;//幀率15。
ffmpeg:time_base.num=1;time_den=1;//幀率15。
等等視頻質量的參數,無可厚非,視頻質量提升,要么編碼速度降低,要么碼率增大。
- B幀數
碼率∝1/b幀數(視頻質量其他參數恒定)
直接影響
X264_RC_CQP 動態比特率
X264_RC_CRF 恒定比特率
X264_RC_ABR 平均比特率
未選擇時,優先選擇的順序是 bitrate > QP > CRF,會按照該順序排查參數,直到發現某種類型參數合法時確定類型。
if( bitrate ) rc_method = ABR; else if ( qp || qp_constant ) rc_method = CQP; else rc_method = CRF;
附:
x264中x264_param_t->rc 結構體
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;