Skip to content

Commit 839b419

Browse files
cgutmanBtbN
authored andcommitted
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 <[email protected]> Signed-off-by: Timo Rothenpieler <[email protected]>
1 parent c1a2da7 commit 839b419

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

libavcodec/nvenc.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,12 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
13041304
h264->idrPeriod = cc->gopLength;
13051305

13061306
if (IS_CBR(cc->rcParams.rateControlMode)) {
1307-
h264->outputBufferingPeriodSEI = 1;
1307+
/* Older SDKs use outputBufferingPeriodSEI to control filler data */
1308+
h264->outputBufferingPeriodSEI = ctx->cbr_padding;
1309+
1310+
#ifdef NVENC_HAVE_FILLER_DATA
1311+
h264->enableFillerDataInsertion = ctx->cbr_padding;
1312+
#endif
13081313
}
13091314

13101315
h264->outputPictureTimingSEI = 1;
@@ -1503,7 +1508,12 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
15031508
hevc->idrPeriod = cc->gopLength;
15041509

15051510
if (IS_CBR(cc->rcParams.rateControlMode)) {
1506-
hevc->outputBufferingPeriodSEI = 1;
1511+
/* Older SDKs use outputBufferingPeriodSEI to control filler data */
1512+
hevc->outputBufferingPeriodSEI = ctx->cbr_padding;
1513+
1514+
#ifdef NVENC_HAVE_FILLER_DATA
1515+
hevc->enableFillerDataInsertion = ctx->cbr_padding;
1516+
#endif
15071517
}
15081518

15091519
hevc->outputPictureTimingSEI = 1;
@@ -1625,7 +1635,7 @@ static av_cold int nvenc_setup_av1_config(AVCodecContext *avctx)
16251635
av1->idrPeriod = cc->gopLength;
16261636

16271637
if (IS_CBR(cc->rcParams.rateControlMode)) {
1628-
av1->enableBitstreamPadding = 1;
1638+
av1->enableBitstreamPadding = ctx->cbr_padding;
16291639
}
16301640

16311641
if (ctx->tile_cols >= 0)

libavcodec/nvenc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ typedef void ID3D11Device;
6161
#define NVENC_HAVE_MULTIPLE_REF_FRAMES
6262
#define NVENC_HAVE_CUSTREAM_PTR
6363
#define NVENC_HAVE_GETLASTERRORSTRING
64+
#define NVENC_HAVE_FILLER_DATA
6465
#endif
6566

6667
// SDK 10.0 compile time feature checks
@@ -309,6 +310,7 @@ typedef struct NvencContext
309310
int unidir_b;
310311
int split_encode_mode;
311312
int mdm, cll;
313+
int cbr_padding;
312314
} NvencContext;
313315

314316
int ff_nvenc_encode_init(AVCodecContext *avctx);

libavcodec/nvenc_av1.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ static const AVOption options[] = {
156156
OFFSET(extra_sei), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE },
157157
{ "a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE },
158158
{ "s12m_tc", "Use timecode (if available)", OFFSET(s12m_tc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE },
159+
{ "cbr_padding", "Pad the bitstream to ensure bitrate does not drop below the target in CBR mode",
160+
OFFSET(cbr_padding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
159161
#ifdef NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER
160162
{ "tf_level", "Specifies the strength of the temporal filtering",
161163
OFFSET(tf_level), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "tf_level" },

libavcodec/nvenc_h264.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ static const AVOption options[] = {
231231
OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
232232
{ "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
233233
OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
234+
#ifdef NVENC_HAVE_FILLER_DATA
235+
{ "cbr_padding", "Pad the bitstream to ensure bitrate does not drop below the target in CBR mode",
236+
OFFSET(cbr_padding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
237+
#endif
234238
#ifdef NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER
235239
{ "tf_level", "Specifies the strength of the temporal filtering",
236240
OFFSET(tf_level), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "tf_level" },

libavcodec/nvenc_hevc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ static const AVOption options[] = {
206206
OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
207207
{ "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
208208
OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
209+
#ifdef NVENC_HAVE_FILLER_DATA
210+
{ "cbr_padding", "Pad the bitstream to ensure bitrate does not drop below the target in CBR mode",
211+
OFFSET(cbr_padding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
212+
#endif
209213
#ifdef NVENC_HAVE_TEMPORAL_FILTER
210214
{ "tf_level", "Specifies the strength of the temporal filtering",
211215
OFFSET(tf_level), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "tf_level" },

libavcodec/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "version_major.h"
3131

3232
#define LIBAVCODEC_VERSION_MINOR 0
33-
#define LIBAVCODEC_VERSION_MICRO 100
33+
#define LIBAVCODEC_VERSION_MICRO 101
3434

3535
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
3636
LIBAVCODEC_VERSION_MINOR, \

0 commit comments

Comments
 (0)