History

avcodec/nvenc: add support for HEVC temporal filtering

Timo Rothenpieler committed 2 years ago

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

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
594 return AVERROR(ENOSYS);594 return AVERROR(ENOSYS);
595 }595 }
596 596
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
597 ctx->support_dyn_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);605 ctx->support_dyn_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
598 606
599 return 0;607 return 0;
@@ -1396,6 +1404,25 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx) · 796 unmodified lines
1396 hevc->numRefL1 = avctx->refs;1404 hevc->numRefL1 = avctx->refs;
1397#endif1405#endif
1398 1406
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
1399 return 0;1426 return 0;
1400}1427}
1401 1428
libavcodec/nvenc.h+2−0
@@ -86,6 +86,7 @@ typedef void ID3D11Device; · 85 unmodified lines
86// SDK 12.2 compile time feature checks86// SDK 12.2 compile time feature checks
87#if NVENCAPI_CHECK_VERSION(12, 2)87#if NVENCAPI_CHECK_VERSION(12, 2)
88#define NVENC_HAVE_NEW_BIT_DEPTH_API88#define NVENC_HAVE_NEW_BIT_DEPTH_API
89#define NVENC_HAVE_TEMPORAL_FILTER
89#endif90#endif
90 91
91typedef struct NvencSurface92typedef struct NvencSurface
@@ -271,6 +272,7 @@ typedef struct NvencContext · 179 unmodified lines
271 int highbitdepth;272 int highbitdepth;
272 int max_slice_size;273 int max_slice_size;
273 int rgb_mode;274 int rgb_mode;
275 int tf_level;
274} NvencContext;276} NvencContext;
275 277
276int ff_nvenc_encode_init(AVCodecContext *avctx);278int ff_nvenc_encode_init(AVCodecContext *avctx);
libavcodec/nvenc_hevc.c+6−0
@@ -196,6 +196,12 @@ static const AVOption options[] = { · 195 unmodified lines
196 OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },196 OFFSET(max_slice_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
197 { "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",197 { "constrained-encoding", "Enable constrainedFrame encoding where each slice in the constrained picture is independent of other slices",
198 OFFSET(constrained_encoding), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },198 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
199 { NULL }205 { NULL }
200};206};
201 207

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