From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <ffmpeg-devel-bounces@ffmpeg.org> Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id A7E0F4BF89 for <ffmpegdev@gitmailbox.com>; Tue, 1 Apr 2025 08:28:00 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D2852687C95; Tue, 1 Apr 2025 11:27:55 +0300 (EEST) Received: from btbn.de (btbn.de [144.76.60.213]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AA71687B53 for <ffmpeg-devel@ffmpeg.org>; Tue, 1 Apr 2025 11:27:49 +0300 (EEST) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id 913B828191260; Tue, 01 Apr 2025 10:27:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1743496068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9qmTwTDOamLPptkHjpoddBx4z0V/eioGfFmIfzMdsSI=; b=Ahq5ChanIC+23MKIAO9rYvgGK12cCf3U8GNTMmDlMBKztYYO4dN/FximydBB9nsxZNfQiq ZPFB1a4jILPVXj+feu5rGCyQ3sza+jVQBaJNwz9xVAH9cKbpY5mhhpsjHuJz8/BmwgeFre UFCqjH0XstPPKcRSizMQDM8ufzjOBK4scgglsvMzeL23UGOILcJBxdw0FeIxRnOqxZ1W6h hFiyhWIEE5FCv42/oeFlheSVDxdsXxRFLe6p6EWUQq1KYyc5ozhKboXC2WORTSQDIM6BHq ZnJ/srDvFObL3YYyGrjlx7Rg+jLkhKc2gL7d2r8Dd1dYqlGydnq6Nfc2SJ4amg== Message-ID: <403bc44a-3ad7-4b12-884a-3de6e938fb6b@rothenpieler.org> Date: Tue, 1 Apr 2025 10:28:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Cameron Gutman <aicommander@gmail.com>, ffmpeg-devel@ffmpeg.org References: <20250331224147.314846-1-aicommander@gmail.com> Content-Language: en-US, de-DE From: Timo Rothenpieler <timo@rothenpieler.org> In-Reply-To: <20250331224147.314846-1-aicommander@gmail.com> Subject: Re: [FFmpeg-devel] [PATCH v2] avcodec/nvenc: Unify CBR filler data insertion for all codecs X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org> List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe> List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel> List-Post: <mailto:ffmpeg-devel@ffmpeg.org> List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help> List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe> Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org> Archived-At: <https://master.gitmailbox.com/ffmpegdev/403bc44a-3ad7-4b12-884a-3de6e938fb6b@rothenpieler.org/> List-Archive: <https://master.gitmailbox.com/ffmpegdev/> List-Post: <mailto:ffmpegdev@gitmailbox.com> On 01/04/2025 00:40, Cameron Gutman wrote: > 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> > --- > v2: Changed cbr_padding default to 0 and rewrote commit text > --- > libavcodec/nvenc.c | 16 +++++++++++++--- > libavcodec/nvenc.h | 2 ++ > libavcodec/nvenc_av1.c | 2 ++ > libavcodec/nvenc_h264.c | 4 ++++ > libavcodec/nvenc_hevc.c | 4 ++++ > 5 files changed, 25 insertions(+), 3 deletions(-) > > diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c > index 0f5e772b3e..41a4dc55f4 100644 > --- a/libavcodec/nvenc.c > +++ b/libavcodec/nvenc.c > @@ -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) > diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h > index e035e123c6..4b12846ed7 100644 > --- a/libavcodec/nvenc.h > +++ b/libavcodec/nvenc.h > @@ -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); > diff --git a/libavcodec/nvenc_av1.c b/libavcodec/nvenc_av1.c > index 01626113ab..df6a93edcb 100644 > --- a/libavcodec/nvenc_av1.c > +++ b/libavcodec/nvenc_av1.c > @@ -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" }, > diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c > index 21d25d643a..842e4eef60 100644 > --- a/libavcodec/nvenc_h264.c > +++ b/libavcodec/nvenc_h264.c > @@ -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" }, > diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c > index c74eca9bb3..d74314f245 100644 > --- a/libavcodec/nvenc_hevc.c > +++ b/libavcodec/nvenc_hevc.c > @@ -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" }, Looks good to me, will test later tonight and then apply. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".