@@ -550,6 +550,10 @@ static av_cold int nvenc_setup_device(AVCodecContext *avctx)
av_log(avctx, AV_LOG_FATAL, "Provided device doesn't support required NVENC features\n");
return ret;
}
+ ctx->dynamic_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
+ if (!ctx->dynamic_bitrate) {
+ av_log(avctx, AV_LOG_VERBOSE, "Dynamic Encode bitrate change not supported\n");
+ }
} else {
int i, nb_devices = 0;
@@ -1951,8 +1955,20 @@ static int reconfig_encoder(AVCodecContext *avctx, const AVFrame *frame)
params.reInitEncodeParams.darHeight = dh;
params.reInitEncodeParams.darWidth = dw;
+ ctx->init_encode_params.darHeight = dh;
+ ctx->init_encode_params.darWidth = dw;
+ needs_reconfig = 1;
+ }
+ if (ctx->dynamic_bitrate > 0 && ctx->rc != NV_ENC_PARAMS_RC_CONSTQP
+ && ctx->encode_config.rcParams.averageBitRate != avctx->bit_rate) {
+ params.version = NV_ENC_RECONFIGURE_PARAMS_VER;
+ params.resetEncoder = 1;
+ params.forceIDR = 1;
+ params.reInitEncodeParams = ctx->init_encode_params;
+ params.reInitEncodeParams.encodeConfig->rcParams.averageBitRate = avctx->bit_rate;
needs_reconfig = 1;
+ needs_encode_config = 1;
}
if (!needs_encode_config)
@@ -1963,8 +1979,7 @@ static int reconfig_encoder(AVCodecContext *avctx, const AVFrame *frame)
if (ret != NV_ENC_SUCCESS) {
nvenc_print_error(avctx, ret, "failed to reconfigure nvenc");
} else {
- ctx->init_encode_params.darHeight = dh;
- ctx->init_encode_params.darWidth = dw;
+ av_log(avctx, AV_LOG_INFO, "nvencReconfigureEncoder succeeded\n");
}
}
@@ -184,6 +184,7 @@ typedef struct NvencContext
int weighted_pred;
int coder;
int b_ref_mode;
+ int dynamic_bitrate;
} NvencContext;
int ff_nvenc_encode_init(AVCodecContext *avctx);