From: Timo Rothenpieler <timo@rothenpieler.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Diego de Souza <ddesouza@nvidia.com>
Subject: [FFmpeg-devel] [PATCH 6/9] avcodec/nvenc: add Temporal Filtering for AV1 and H.264 in NVENC
Date: Thu, 30 Jan 2025 20:40:43 +0100
Message-ID: <20250130194124.21836-7-timo@rothenpieler.org> (raw)
In-Reply-To: <20250130194124.21836-1-timo@rothenpieler.org>
From: Diego de Souza <ddesouza@nvidia.com>
This commit extends the support for Temporal Filtering in NVENC for
AV1 and H.264 codecs. For natural videos with noise, NVENC temporal
filtering improves video coding efficiency by 4-5%.
Signed-off-by: Diego de Souza <ddesouza@nvidia.com>
---
libavcodec/nvenc.c | 40 +++++++++++++++++++++++++++++++++++++++-
libavcodec/nvenc.h | 1 +
libavcodec/nvenc_av1.c | 6 ++++++
libavcodec/nvenc_h264.c | 6 ++++++
4 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index f301269dbd..3403fa8996 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -627,7 +627,7 @@ static int nvenc_check_capabilities(AVCodecContext *avctx)
return AVERROR(ENOSYS);
}
-#ifdef NVENC_HAVE_TEMPORAL_FILTER
+#if defined(NVENC_HAVE_TEMPORAL_FILTER) || defined(NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER)
ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_TEMPORAL_FILTER);
if(ctx->tf_level > 0 && ret <= 0) {
av_log(avctx, AV_LOG_WARNING, "Temporal filtering not supported by the device\n");
@@ -1383,6 +1383,25 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
h264->numRefL1 = avctx->refs;
#endif
+#ifdef NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER
+ if (ctx->tf_level >= 0) {
+ h264->tfLevel = ctx->tf_level;
+
+ switch (ctx->tf_level)
+ {
+ case NV_ENC_TEMPORAL_FILTER_LEVEL_0:
+ case NV_ENC_TEMPORAL_FILTER_LEVEL_4:
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Invalid temporal filtering level.\n");
+ return AVERROR(EINVAL);
+ }
+
+ if (ctx->encode_config.frameIntervalP < 5)
+ av_log(avctx, AV_LOG_WARNING, "Temporal filtering needs at least 4 B-Frames (-bf 4).\n");
+ }
+#endif
+
return 0;
}
@@ -1608,6 +1627,25 @@ static av_cold int nvenc_setup_av1_config(AVCodecContext *avctx)
av1->numFwdRefs = avctx->refs;
av1->numBwdRefs = avctx->refs;
+#ifdef NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER
+ if (ctx->tf_level >= 0) {
+ av1->tfLevel = ctx->tf_level;
+
+ switch (ctx->tf_level)
+ {
+ case NV_ENC_TEMPORAL_FILTER_LEVEL_0:
+ case NV_ENC_TEMPORAL_FILTER_LEVEL_4:
+ break;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Invalid temporal filtering level.\n");
+ return AVERROR(EINVAL);
+ }
+
+ if (ctx->encode_config.frameIntervalP < 5)
+ av_log(avctx, AV_LOG_WARNING, "Temporal filtering needs at least 4 B-Frames (-bf 4).\n");
+ }
+#endif
+
return 0;
}
#endif
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index 2d8e8bef44..6f7f8d4e7f 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -98,6 +98,7 @@ typedef void ID3D11Device;
#define NVENC_HAVE_H264_10BIT_SUPPORT
#define NVENC_HAVE_422_SUPPORT
#define NVENC_HAVE_AV1_UHQ_TUNING
+#define NVENC_HAVE_H264_AND_AV1_TEMPORAL_FILTER
#endif
typedef struct NvencSurface
diff --git a/libavcodec/nvenc_av1.c b/libavcodec/nvenc_av1.c
index bccc63dd5b..5dd27fe872 100644
--- a/libavcodec/nvenc_av1.c
+++ b/libavcodec/nvenc_av1.c
@@ -152,6 +152,12 @@ 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 },
+#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" },
+ { "0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_TEMPORAL_FILTER_LEVEL_0 }, 0, 0, VE, .unit = "tf_level" },
+ { "4", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_TEMPORAL_FILTER_LEVEL_4 }, 0, 0, VE, .unit = "tf_level" },
+#endif
#ifdef NVENC_HAVE_LOOKAHEAD_LEVEL
{ "lookahead_level", "Specifies the lookahead level. Higher level may improve quality at the expense of performance.",
OFFSET(lookahead_level), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, NV_ENC_LOOKAHEAD_LEVEL_AUTOSELECT, VE, .unit = "lookahead_level" },
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index ca997da209..5e9f73412f 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -224,6 +224,12 @@ 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_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" },
+ { "0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_TEMPORAL_FILTER_LEVEL_0 }, 0, 0, VE, .unit = "tf_level" },
+ { "4", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_TEMPORAL_FILTER_LEVEL_4 }, 0, 0, VE, .unit = "tf_level" },
+#endif
#ifdef NVENC_HAVE_LOOKAHEAD_LEVEL
{ "lookahead_level", "Specifies the lookahead level. Higher level may improve quality at the expense of performance.",
OFFSET(lookahead_level), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, NV_ENC_LOOKAHEAD_LEVEL_AUTOSELECT, VE, .unit = "lookahead_level" },
--
2.45.2
_______________________________________________
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".
next prev parent reply other threads:[~2025-01-30 19:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 19:40 [FFmpeg-devel] [PATCH 0/9] Nvidia Video Codec SDK 13.0 support Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 1/9] avutil/hwcontext_cuda: add 4:2:2 pixel format support Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 2/9] avcodec/nvdec: add 4:2:2 decoding and 10-bit support Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 3/9] avcodec/cuviddec: add HEVC/H.264 4:2:2 and H.264 " Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 4/9] avcodec/nvenc: add 4:2:2 encoding " Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 5/9] avcodec/nvenc: add UHQ to AV1 for NVENC Timo Rothenpieler
2025-01-30 19:40 ` Timo Rothenpieler [this message]
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 7/9] avcodec/nvenc: add MV-HEVC encoding support Timo Rothenpieler
2025-01-30 20:17 ` James Almer
2025-01-30 23:23 ` [FFmpeg-devel] [PATCH v2 " Timo Rothenpieler
2025-01-31 3:26 ` James Almer
2025-02-24 20:52 ` [FFmpeg-devel] [PATCH " Jean-Baptiste Kempf
2025-02-24 20:54 ` Timo Rothenpieler
2025-02-25 22:00 ` Jean-Baptiste Kempf
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 8/9] avcodec/nvenc: use encoder level options for qmin/qmax Timo Rothenpieler
2025-01-31 6:16 ` Zhao Zhili
2025-01-31 13:20 ` Timo Rothenpieler
2025-01-30 19:40 ` [FFmpeg-devel] [PATCH 9/9] avcodec/nvenc: finalize SDK 13.0 support Timo Rothenpieler
2025-02-01 21:15 ` [FFmpeg-devel] [PATCH 0/9] Nvidia Video Codec " Timo Rothenpieler
2025-02-02 19:05 ` Timo Rothenpieler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250130194124.21836-7-timo@rothenpieler.org \
--to=timo@rothenpieler.org \
--cc=ddesouza@nvidia.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git