同碼率下的圖像質量或同圖像質量下的碼率。
AVCodecContext?
/**
???? * the average bitrate
???? * - encoding: Set by user; unused for constant quantizer encoding.
???? * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream.
???? */
// ?? int bit_rate;
??? /**
???? * CODEC_FLAG_*.
???? * - encoding: Set by user.
???? * - decoding: Set by user.
???? */
??? int flags;
/**
???? * CODEC_FLAG2_*
???? * - encoding: Set by user.
???? * - decoding: Set by user.
???? */
??? int flags2;
}
static int
X264_init(AVCodecContext *avctx)函數中,libx264.c中
??? x4->params.i_keyint_max = avctx->gop_size;
??? x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
??? x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
??? x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
??? x4->params.rc.b_stat_write = (avctx->flags & CODEC_FLAG_PASS1);
//#define CODEC_FLAG_PASS1?????????? 0x0200?? ///< Use internal 2pass ratecontrol in first pass mode.
//#define CODEC_FLAG_PASS2?????????? 0x0400?? ///< Use internal 2pass ratecontrol in second pass mode.
??? if(avctx->flags & CODEC_FLAG_PASS2) x4->params.rc.b_stat_read = 1;//h->param.rc.i_rc_method == X264_RC_ABR && h->param.rc.b_stat_read;
??? else{
??????? if(avctx->crf){//crf的默認值為24或是26;
??????????? x4->params.rc.i_rc_method = X264_RC_CRF;//參數i_rc_method表示碼率控制,CQP(恒定質量),CRF(恒定碼率),ABR(平均碼率)
??????????? x4->params.rc.f_rf_constant = avctx->crf;
??????? }else if(avctx->cqp > -1){
??????????? x4->params.rc.i_rc_method = X264_RC_CQP;//CQP生效,必須要設置crf=0 //固定量化模式并設置使用的量化值,范圍0~51,0為無損壓縮,默認26
??????????? x4->params.rc.i_qp_constant = avctx->cqp;
??????? }
??? }
??? // if neither crf nor cqp modes are selected we have to enable the RC
??? // we do it this way because we cannot check if the bitrate has been set
??? if(!(avctx->crf || (avctx->cqp > -1))) //只有設置CRF=0和cqb為-1時,ABR才有效
????? x4->params.rc.i_rc_method = X264_RC_ABR;//#define X264_RC_ABR?? 平均碼率 ????????????? 2
??? x4->params.i_bframe = avctx->max_b_frames;