diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 316e4a3679..158e304a0c 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -949,9 +949,9 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx) h264->repeatSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1; h264->outputAUD = ctx->aud; - if (avctx->refs >= 0) { + if (ctx->dpb_size >= 0) { /* 0 means "let the hardware decide" */ - h264->maxNumRefFrames = avctx->refs; + h264->maxNumRefFrames = ctx->dpb_size; } if (avctx->gop_size >= 0) { h264->idrPeriod = cc->gopLength; @@ -1041,9 +1041,9 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx) hevc->repeatSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1; hevc->outputAUD = ctx->aud; - if (avctx->refs >= 0) { + if (ctx->dpb_size >= 0) { /* 0 means "let the hardware decide" */ - hevc->maxNumRefFramesInDPB = avctx->refs; + hevc->maxNumRefFramesInDPB = ctx->dpb_size; } if (avctx->gop_size >= 0) { hevc->idrPeriod = cc->gopLength; @@ -1175,7 +1175,7 @@ static av_cold int nvenc_setup_encoder(AVCodecContext *avctx) if (ctx->bluray_compat) { ctx->aud = 1; - avctx->refs = FFMIN(FFMAX(avctx->refs, 0), 6); + ctx->dpb_size = FFMIN(FFMAX(avctx->refs, 0), 6); avctx->max_b_frames = FFMIN(avctx->max_b_frames, 3); switch (avctx->codec->id) { case AV_CODEC_ID_H264: diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index ddd6168409..892a001f69 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -192,6 +192,7 @@ typedef struct NvencContext int coder; int b_ref_mode; int a53_cc; + int dpb_size; } NvencContext; int ff_nvenc_encode_init(AVCodecContext *avctx); diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c index a6623f5f35..d5c7370aaa 100644 --- a/libavcodec/nvenc_h264.c +++ b/libavcodec/nvenc_h264.c @@ -138,6 +138,8 @@ static const AVOption options[] = { { "middle", "", 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, VE, "b_ref_mode" }, #endif { "a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE }, + { "dpb_size", "Specifies the DPB size used for encoding (0 means automatic)", + OFFSET(dpb_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE }, { NULL } }; diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c index d567d960ba..c668b97f86 100644 --- a/libavcodec/nvenc_hevc.c +++ b/libavcodec/nvenc_hevc.c @@ -127,6 +127,8 @@ static const AVOption options[] = { { "each", "", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, VE, "b_ref_mode" }, { "middle", "", 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, VE, "b_ref_mode" }, #endif + { "dpb_size", "Specifies the DPB size used for encoding (0 means automatic)", + OFFSET(dpb_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE }, { NULL } };