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 7E6694BC94 for <ffmpegdev@gitmailbox.com>; Sun, 30 Mar 2025 00:04:38 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DBF13687CAA; Sun, 30 Mar 2025 02:04:24 +0200 (EET) Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4968F687CA7 for <ffmpeg-devel@ffmpeg.org>; Sun, 30 Mar 2025 02:04:18 +0200 (EET) Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3f9a7cbc8f1so986803b6e.0 for <ffmpeg-devel@ffmpeg.org>; Sat, 29 Mar 2025 17:04:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743293056; x=1743897856; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=pt5II6HH5M36WaGpzn9Zkxr+iPkepkP4/haTJU16njk=; b=dwbBI2QWtdO6uVP2IcAbfHofjGj40g6vA/ToHTd1ebyJoJ89IG5jIeZhrq3ckqRMTj 7pDJo2xQIq3SG+23mpq2QVbAuP9AuRzaKPnonO1rxWR5xFpLNIXGhwSe06jopKFv++qm m+JGnxwdVDDoIqqoyvqpmsL7rXczm26ph6kfTr1906EJhNIvnbdMIQkzRxDx0oMXXjzZ sspcTaPzDSCujbzKrFeEm1dapcRGn1rk/pm2H7u29+jmknv37rYFImc+6bA4RncgxSAV B6Ke0EF4ifrdikgPWGknEQsrPicCT559r6z1oDf8B3r0oikiXPMcHJ6BKBHrzy34i5PA pAzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743293056; x=1743897856; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pt5II6HH5M36WaGpzn9Zkxr+iPkepkP4/haTJU16njk=; b=jbGCNPULj1Cg8hEduyMbhcxdo39IcTAIBDMgiysy6wToqg2oM2E5FxwZXxvsqANd5r GlZTbtR2cCUSTR+ghG9fJmgtc1bw5lKQfvW2u8lINBOvPBxGoaAIaftRqd6JbDQGaavI HW9MZ51OlosP9pCHsdKTvz3x6NtE/Ocq0giExgu+L9cTkRMAMFLB+nzgCNYtYMLU0uyN lsn4zPXAR1N9QHBYQagVVFfOTinbVhUzlS7bJQTnzrz2QaCQHpc8nJZ4Y5V6P+9oluMG dTccF5/MLFZ8ai3cqkNEVhhgfJkd/Lc2tXgXgq1Q3pIP1V3sVMEv9JLzI8ZYwZvq3XXM gmFw== X-Forwarded-Encrypted: i=1; AJvYcCX4cr5NubGHrYepDTOzdWDbsMAR/fnZcceMg5lUnvDrub3gz1GU96ILR0tp2OMQ7dV8NBawCdncFzRJf3g=@ffmpeg.org X-Gm-Message-State: AOJu0YyWtkQymGZYo6ApgS8XetIJvmZtH1v3nOtM38GMjyDfvANFWRdS rYM+V+MimzvkFtLa4zFfnrrnhcxAWaZ1uOD7Zou+WQGL98yRvULN X-Gm-Gg: ASbGnctbVavL8NEEbKdRr4sXpP41fGFKU14qg+zWETGmlUoehLLYmxySkyjk2WpS7pa l4QSXWr4k5vjqQ0lD1i97haizQmcQRa1xJMdhKBLirVuud0RlBRh2pXwk65B+OfsKxK8/0TxDaX Kx+IIF5AvJo32FWk4kJMHlbf93m5oVwargcPj6f4hTI2NjzsHtAqHJN8lEOmpIw0WiQwHEuYHdS 2xzzt+8pLfjP32/42YLXd+Xsi10vcZbU4IfcJkpBwC/VNHEZa2+tlA1qN5tR3cCmR/noxL9s9Dc vRYtXdAVrAfdw02vT6s1LB1HFfKTM+2IOFCQ6bRSbMH4CeWKM/hCkuQJ2F3riA== X-Google-Smtp-Source: AGHT+IEH+QkvU/xUgcMr1xHQvOZ4y+h3EPt5N4DkyFflsQwStgWtpVv8i0XD4I7pt8Junvv8xATkLQ== X-Received: by 2002:a05:6808:1495:b0:3f9:53b4:9999 with SMTP id 5614622812f47-3ff0f5cc5d4mr2463992b6e.34.1743293056609; Sat, 29 Mar 2025 17:04:16 -0700 (PDT) Received: from cassini.localdomain ([2600:1702:50c6:cf10:38b3:1353:266b:b701]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3ff05279bb3sm890542b6e.31.2025.03.29.17.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Mar 2025 17:04:16 -0700 (PDT) From: Cameron Gutman <aicommander@gmail.com> To: timo@rothenpieler.org, ffmpeg-devel@ffmpeg.org Date: Sat, 29 Mar 2025 19:04:03 -0500 Message-ID: <20250330000414.300619-1-aicommander@gmail.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/nvenc: Use CBR filler data consistently across 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org> Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250330000414.300619-1-aicommander@gmail.com/> List-Archive: <https://master.gitmailbox.com/ffmpegdev/> List-Post: <mailto:ffmpegdev@gitmailbox.com> Previously, AV1 used filler data with CBR by default while H.264 and HEVC did not. Make this consistent by using filler data in CBR mode across all codecs. Since there are valid reasons to use CBR with or without filler, also add a cbr_padding option to allow users to opt out. Signed-off-by: Cameron Gutman <aicommander@gmail.com> --- 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..b1b95672f2 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 = 1 }, 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..4845d0422d 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 = 1 }, 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..8648f4f3a9 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 = 1 }, 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" }, -- 2.49.0 _______________________________________________ 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".