History

avcodec/nvenc: add support for HEVC temporal filtering

Timo Rothenpieler committed 2 years ago

Commit 64e3fc91 parent 06c2a2c3 files · +35 −0Browse files

Showing the changes to libavcodec (3 of 3 files). Show all

Unified · Split

3 files
  1. libavcodec/nvenc.c +27 −0
  2. libavcodec/nvenc.h +2 −0
  3. libavcodec/nvenc_hevc.c +6 −0
libavcodec/nvenc.c+27−0
@@ -594,6 +594,14 @@ static int nvenc_check_capabilities(AVCodecContext *avctx) · 593 unmodified lines
594594 return AVERROR(ENOSYS);
595595 }
596596
597+#ifdef NVENC_HAVE_TEMPORAL_FILTER
598+ ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_TEMPORAL_FILTER);
599+ if(ctx->tf_level > 0 && ret <= 0) {
600+ av_log(avctx, AV_LOG_WARNING, "Temporal filtering not supported by the device\n");
601+ return AVERROR(ENOSYS);
602+ }
603+#endif
604+
597605 ctx->support_dyn_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
598606
599607 return 0;
@@ -1396,6 +1404,25 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx) · 796 unmodified lines
13961404 hevc->numRefL1 = avctx->refs;
13971405 #endif
13981406
1407+#ifdef NVENC_HAVE_TEMPORAL_FILTER
1408+ if (ctx->tf_level >= 0) {
1409+ hevc->tfLevel = ctx->tf_level;
1410+
1411+ switch (ctx->tf_level)
1412+ {
1413+ case NV_ENC_TEMPORAL_FILTER_LEVEL_0:
1414+ case NV_ENC_TEMPORAL_FILTER_LEVEL_4:
1415+ break;
1416+ default:
1417+ av_log(avctx, AV_LOG_ERROR, "Invalid temporal filtering level.\n");
1418+ return AVERROR(EINVAL);
1419+ }
1420+
1421+ if (ctx->encode_config.frameIntervalP < 5)
1422+ av_log(avctx, AV_LOG_WARNING, "Temporal filtering needs at least 4 B-Frames (-bf 4).\n");
1423+ }
1424+#endif
1425+
13991426 return 0;
14001427 }
14011428
libavcodec/nvenc.h+2−0
@@ -86,6 +86,7 @@ typedef void ID3D11Device; · 85 unmodified lines
8686 // SDK 12.2 compile time feature checks
8787 #if NVENCAPI_CHECK_VERSION(12, 2)
8888 #define NVENC_HAVE_NEW_BIT_DEPTH_API
89+#define NVENC_HAVE_TEMPORAL_FILTER
8990 #endif
9091
9192 typedef struct NvencSurface
@@ -271,6 +272,7 @@ typedef struct NvencContext · 179 unmodified lines
271272 int highbitdepth;
272273 int max_slice_size;
273274 int rgb_mode;
275+ int tf_level;
274276 } NvencContext;
275277
276278 int ff_nvenc_encode_init(AVCodecContext *avctx);
libavcodec/nvenc_hevc.c+6−0
@@ -196,6 +196,12 @@ static const AVOption options[] = { · 195 unmodified lines
196196 OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
197197 { "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
198198 OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
199+#ifdef NVENC_HAVE_TEMPORAL_FILTER
200+ { "tf_level", "Specifies the strength of the temporal filtering",
201+ OFFSET(tf_level), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, VE, .unit = "tf_level" },
202+ { "0", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_TEMPORAL_FILTER_LEVEL_0 }, 0, 0, VE, .unit = "tf_level" },
203+ { "4", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_TEMPORAL_FILTER_LEVEL_4 }, 0, 0, VE, .unit = "tf_level" },
204+#endif
199205 { NULL }
200206 };
201207

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t