From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id BB9664B835 for ; Thu, 30 Jan 2025 19:42:46 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 907EC68C187; Thu, 30 Jan 2025 21:41:50 +0200 (EET) Received: from btbn.de (btbn.de [144.76.60.213]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 524D568C0FC for ; Thu, 30 Jan 2025 21:41:41 +0200 (EET) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id 8049A296C1112; Thu, 30 Jan 2025 20:41:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1738266097; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DRfzf3kCiplb2N+ex2RMGM79WusPTkQu1khVwMJauD8=; b=mIQGIIYSFnFVko8yIHvt7XBpjm2ki7hp3Hrx9obpSF6v1n0NpmLC+pw/AfVqdeHBukkpgh H1MDETCSM+JjbISIRL/GYjyZy71C9m0OVu7enTITLn8tNcy/kKwZtrDHpfsmn7Q8Drx0ms Le9LBJ/zhWF00pYq0//IhUSx4LrL0dF1hHLPTX3zhvOr29XRlHXIa327i+HEMvEr8H963f qNckp/zMw2T5qKLT5pvsS9g70DE7sSlakwif17pEqsMiSYJxTBN2ZVG/JgOXnOE2GOMWwr AsuYPtImUEtKzQgZuSfV9qcQn1lSjvdGo9vJJuxhftZzOtN/DvUC2tK/8Q13wA== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Thu, 30 Jan 2025 20:40:43 +0100 Message-ID: <20250130194124.21836-7-timo@rothenpieler.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250130194124.21836-1-timo@rothenpieler.org> References: <20250130194124.21836-1-timo@rothenpieler.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/9] avcodec/nvenc: add Temporal Filtering for AV1 and H.264 in NVENC X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Diego de Souza Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Diego de Souza 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 --- 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".