1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

avcodec/nvenc: add constrainedFrame encoding support

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
This commit is contained in:
Limin Wang 2021-09-02 18:38:58 +08:00 committed by Timo Rothenpieler
parent 3756525a59
commit 75001ae844
5 changed files with 28 additions and 1 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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 }
};

View File

@ -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 }
};

View File

@ -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, \