[FFmpeg-cvslog] avcodec/nvenc: add constrainedFrame encoding support
Limin Wang
git at videolan.org
Mon Sep 6 15:48:01 EEST 2021
ffmpeg | branch: master | Limin Wang <lance.lmwang at gmail.com> | Thu Sep 2 18:38:58 2021 +0800| [75001ae8440d819d23443709091fca4c39e395a1] | committer: Timo Rothenpieler
avcodec/nvenc: add constrainedFrame encoding support
Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
Signed-off-by: Timo Rothenpieler <timo at rothenpieler.org>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=75001ae8440d819d23443709091fca4c39e395a1
---
libavcodec/nvenc.c | 21 +++++++++++++++++++++
libavcodec/nvenc.h | 2 ++
libavcodec/nvenc_h264.c | 2 ++
libavcodec/nvenc_hevc.c | 2 ++
libavcodec/version.h | 2 +-
5 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index ff7c9d6542..ae25afd7f8 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -548,6 +548,19 @@ static int nvenc_check_capabilities(AVCodecContext *avctx)
return AVERROR(ENOSYS);
}
+#ifndef NVENC_HAVE_HEVC_CONSTRAINED_ENCODING
+ if (ctx->constrained_encoding && avctx->codec->id == AV_CODEC_ID_HEVC) {
+ av_log(avctx, AV_LOG_WARNING, "HEVC constrained encoding needs SDK 10.0 at build time\n");
+ return AVERROR(ENOSYS);
+ }
+#endif
+
+ ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_CONSTRAINED_ENCODING);
+ if(ctx->constrained_encoding && ret <= 0) {
+ av_log(avctx, AV_LOG_WARNING, "Constrained encoding not supported by the device\n");
+ return AVERROR(ENOSYS);
+ }
+
ctx->support_dyn_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
return 0;
@@ -1104,6 +1117,9 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
#endif
}
+ if (ctx->constrained_encoding)
+ h264->enableConstrainedEncoding = 1;
+
h264->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0;
h264->repeatSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1;
h264->outputAUD = ctx->aud;
@@ -1213,6 +1229,11 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
#endif
}
+#ifdef NVENC_HAVE_HEVC_CONSTRAINED_ENCODING
+ if (ctx->constrained_encoding)
+ hevc->enableConstrainedEncoding = 1;
+#endif
+
hevc->disableSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0;
hevc->repeatSPSPPS = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) ? 0 : 1;
hevc->outputAUD = ctx->aud;
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index 1e756a6f72..08531e1be3 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -68,6 +68,7 @@ typedef void ID3D11Device;
#define NVENC_HAVE_MULTIPASS
#define NVENC_HAVE_LDKFS
#define NVENC_HAVE_H264_LVL6
+#define NVENC_HAVE_HEVC_CONSTRAINED_ENCODING
#endif
// SDK 11.1 compile time feature checks
@@ -233,6 +234,7 @@ typedef struct NvencContext
int extra_sei;
int intra_refresh;
int single_slice_intra_refresh;
+ int constrained_encoding;
} NvencContext;
int ff_nvenc_encode_init(AVCodecContext *avctx);
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index ab5263368e..7d78aa0d87 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -192,6 +192,8 @@ static const AVOption options[] = {
OFFSET(intra_refresh),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "single-slice-intra-refresh", "Use single slice intra refresh",
OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, 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 },
{ NULL }
};
diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c
index d8cfeca7a9..a13ac5a395 100644
--- a/libavcodec/nvenc_hevc.c
+++ b/libavcodec/nvenc_hevc.c
@@ -173,6 +173,8 @@ static const AVOption options[] = {
OFFSET(intra_refresh),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "single-slice-intra-refresh", "Use single slice intra refresh",
OFFSET(single_slice_intra_refresh), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, 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 },
{ NULL }
};
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 7faf18a497..7839bf945d 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
#define LIBAVCODEC_VERSION_MAJOR 59
#define LIBAVCODEC_VERSION_MINOR 7
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
More information about the ffmpeg-cvslog
mailing list