码率控制方式选择

同码率下的图像质量或同图像质量下的码率。

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;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值