aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorLimin Wang <lance.lmwang@gmail.com>2021-09-02 18:38:58 +0800
committerTimo Rothenpieler <timo@rothenpieler.org>2021-09-06 14:25:26 +0200
commit75001ae8440d819d23443709091fca4c39e395a1 (patch)
tree4c21f37c98190d5c31e25a5f0b4a7d6717f6101f /libavcodec
parent3756525a59cc63db431fc301ea3748958964af16 (diff)
downloadffmpeg-75001ae8440d819d23443709091fca4c39e395a1.tar.gz
avcodec/nvenc: add constrainedFrame encoding support
Signed-off-by: Limin Wang <lance.lmwang@gmail.com> Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/nvenc.c21
-rw-r--r--libavcodec/nvenc.h2
-rw-r--r--libavcodec/nvenc_h264.c2
-rw-r--r--libavcodec/nvenc_hevc.c2
-rw-r--r--libavcodec/version.h2
5 files changed, 28 insertions, 1 deletions
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, \