[x265] how to reconfigure x265 bitrate

qw applemax82 at 163.com
Tue Nov 17 11:44:38 CET 2020


Hi,


I use ffmpeg-4.0.1 and x265-3.1.1 to do transcoding. ffmpeg/libx264 supports reconfiguring encoder's bitrate, i.e. change bitrate without reopen x264 encoder.


ffmpeg/libx265 dosen't support reconfiguring x265's bitrate, but x265 has one api, i.e. x265_encoder_reconfig()/encoder_reconfig, which can reconfigure bitrate. I make one new function of reconfig_encoder() as libx264.c, but fail to update bitrate.


static void reconfig_encoder(AVCodecContext *avctx, const AVFrame *frame)
{
    libx265Context *ctx = avctx->priv_data;
    int ret;


    if (ctx->params->rc.rateControlMode == X265_RC_ABR &&
        (ctx->params->rc.bitrate != avctx->bit_rate / 1000 ||
         ctx->params->rc.vbvBufferSize != avctx->rc_buffer_size / 1000 ||
         ctx->params->rc.vbvMaxBitrate != avctx->rc_max_rate / 1000)) {
        av_log(avctx, AV_LOG_INFO, "x265 bitrate:%d->%d vbvBufferSize:%d->%d vbvMaxBitrate:%d->%d\n",
               ctx->params->rc.bitrate, (int)(avctx->bit_rate / 1000),
               ctx->params->rc.vbvBufferSize, (int)(avctx->rc_buffer_size / 1000),
               ctx->params->rc.vbvMaxBitrate, (int)(avctx->rc_max_rate / 1000));
        ctx->params->rc.bitrate = avctx->bit_rate / 1000;
        ctx->params->rc.vbvBufferSize = avctx->rc_buffer_size / 1000;
        ctx->params->rc.vbvMaxBitrate = avctx->rc_max_rate    / 1000;
        ret = ctx->api->encoder_reconfig(ctx->encoder, ctx->params);
        if (ret != 0) {
            av_log(avctx, AV_LOG_ERROR, "x265 encoder_reconfig() failed\n");
        }
    }
}


Is there something wrong with my usage about x265_encoder_reconfig()/encoder_reconfig?


Thanks!


Regards


andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20201117/7dd13b5a/attachment.html>


More information about the x265-devel mailing list