1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/nvenc: unify CBR filler data insertion for all codecs

Previously, AV1 used filler data with CBR by default while H.264
and HEVC may or may not depending on driver version. Make this
consistent by using not filler data in CBR mode for all codecs.

Since there are valid reasons to use CBR with or without filler,
also add a cbr_padding option to allow users to override this.

Signed-off-by: Cameron Gutman <aicommander@gmail.com>
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
This commit is contained in:
Cameron Gutman
2025-03-31 17:40:11 -05:00
committed by Timo Rothenpieler
parent c1a2da72cc
commit 839b41991d
6 changed files with 26 additions and 4 deletions

View File

@ -1304,7 +1304,12 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
h264->idrPeriod = cc->gopLength;
if (IS_CBR(cc->rcParams.rateControlMode)) {
h264->outputBufferingPeriodSEI = 1;
/* Older SDKs use outputBufferingPeriodSEI to control filler data */
h264->outputBufferingPeriodSEI = ctx->cbr_padding;
#ifdef NVENC_HAVE_FILLER_DATA
h264->enableFillerDataInsertion = ctx->cbr_padding;
#endif
}
h264->outputPictureTimingSEI = 1;
@ -1503,7 +1508,12 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
hevc->idrPeriod = cc->gopLength;
if (IS_CBR(cc->rcParams.rateControlMode)) {
hevc->outputBufferingPeriodSEI = 1;
/* Older SDKs use outputBufferingPeriodSEI to control filler data */
hevc->outputBufferingPeriodSEI = ctx->cbr_padding;
#ifdef NVENC_HAVE_FILLER_DATA
hevc->enableFillerDataInsertion = ctx->cbr_padding;
#endif
}
hevc->outputPictureTimingSEI = 1;
@ -1625,7 +1635,7 @@ static av_cold int nvenc_setup_av1_config(AVCodecContext *avctx)
av1->idrPeriod = cc->gopLength;
if (IS_CBR(cc->rcParams.rateControlMode)) {
av1->enableBitstreamPadding = 1;
av1->enableBitstreamPadding = ctx->cbr_padding;
}
if (ctx->tile_cols >= 0)

View File

@ -61,6 +61,7 @@ typedef void ID3D11Device;
#define NVENC_HAVE_MULTIPLE_REF_FRAMES
#define NVENC_HAVE_CUSTREAM_PTR
#define NVENC_HAVE_GETLASTERRORSTRING
#define NVENC_HAVE_FILLER_DATA
#endif
// SDK 10.0 compile time feature checks
@ -309,6 +310,7 @@ typedef struct NvencContext
int unidir_b;
int split_encode_mode;
int mdm, cll;
int cbr_padding;
} NvencContext;
int ff_nvenc_encode_init(AVCodecContext *avctx);

View File

@ -156,6 +156,8 @@ static const AVOption options[] = {
OFFSET(extra_sei), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE },
{ "a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE },
{ "s12m_tc", "Use timecode (if available)", OFFSET(s12m_tc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE },
{ "cbr_padding", "Pad the bitstream to ensure bitrate does not drop below the target in CBR mode",
OFFSET(cbr_padding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
#ifdef NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER
{ "tf_level", "Specifies the strength of the temporal filtering",
OFFSET(tf_level), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "tf_level" },

View File

@ -231,6 +231,10 @@ static const AVOption options[] = {
OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
{ "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
#ifdef NVENC_HAVE_FILLER_DATA
{ "cbr_padding", "Pad the bitstream to ensure bitrate does not drop below the target in CBR mode",
OFFSET(cbr_padding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
#endif
#ifdef NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER
{ "tf_level", "Specifies the strength of the temporal filtering",
OFFSET(tf_level), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "tf_level" },

View File

@ -206,6 +206,10 @@ static const AVOption options[] = {
OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
{ "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
#ifdef NVENC_HAVE_FILLER_DATA
{ "cbr_padding", "Pad the bitstream to ensure bitrate does not drop below the target in CBR mode",
OFFSET(cbr_padding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
#endif
#ifdef NVENC_HAVE_TEMPORAL_FILTER
{ "tf_level", "Specifies the strength of the temporal filtering",
OFFSET(tf_level), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "tf_level" },

View File

@ -30,7 +30,7 @@
#include "version_major.h"
#define LIBAVCODEC_VERSION_MINOR 0
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_MICRO 101
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \