You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/nvenc: add 4:2:2 encoding and H.264 10-bit support
This commit adds support for 4:2:2 encoding for HEVC and H.264 on NVIDIA Blackwell GPUs. Additionally, it supports 10-bit encoding for H.264 on Blackwell GPUs. Signed-off-by: Diego de Souza <ddesouza@nvidia.com> Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
This commit is contained in:
committed by
Timo Rothenpieler
parent
7e9655800d
commit
2cfef29f97
@ -59,6 +59,11 @@ const enum AVPixelFormat ff_nvenc_pix_fmts[] = {
|
|||||||
AV_PIX_FMT_P010,
|
AV_PIX_FMT_P010,
|
||||||
AV_PIX_FMT_YUV444P,
|
AV_PIX_FMT_YUV444P,
|
||||||
AV_PIX_FMT_P016, // Truncated to 10bits
|
AV_PIX_FMT_P016, // Truncated to 10bits
|
||||||
|
#ifdef NVENC_HAVE_422_SUPPORT
|
||||||
|
AV_PIX_FMT_NV16,
|
||||||
|
AV_PIX_FMT_P210,
|
||||||
|
AV_PIX_FMT_P216,
|
||||||
|
#endif
|
||||||
AV_PIX_FMT_YUV444P16, // Truncated to 10bits
|
AV_PIX_FMT_YUV444P16, // Truncated to 10bits
|
||||||
AV_PIX_FMT_0RGB32,
|
AV_PIX_FMT_0RGB32,
|
||||||
AV_PIX_FMT_RGB32,
|
AV_PIX_FMT_RGB32,
|
||||||
@ -87,6 +92,8 @@ const AVCodecHWConfigInternal *const ff_nvenc_hw_configs[] = {
|
|||||||
|
|
||||||
#define IS_10BIT(pix_fmt) (pix_fmt == AV_PIX_FMT_P010 || \
|
#define IS_10BIT(pix_fmt) (pix_fmt == AV_PIX_FMT_P010 || \
|
||||||
pix_fmt == AV_PIX_FMT_P016 || \
|
pix_fmt == AV_PIX_FMT_P016 || \
|
||||||
|
pix_fmt == AV_PIX_FMT_P210 || \
|
||||||
|
pix_fmt == AV_PIX_FMT_P216 || \
|
||||||
pix_fmt == AV_PIX_FMT_YUV444P16 || \
|
pix_fmt == AV_PIX_FMT_YUV444P16 || \
|
||||||
pix_fmt == AV_PIX_FMT_X2RGB10 || \
|
pix_fmt == AV_PIX_FMT_X2RGB10 || \
|
||||||
pix_fmt == AV_PIX_FMT_X2BGR10 || \
|
pix_fmt == AV_PIX_FMT_X2BGR10 || \
|
||||||
@ -105,6 +112,10 @@ const AVCodecHWConfigInternal *const ff_nvenc_hw_configs[] = {
|
|||||||
pix_fmt == AV_PIX_FMT_GBRP16 || \
|
pix_fmt == AV_PIX_FMT_GBRP16 || \
|
||||||
(ctx->rgb_mode == NVENC_RGB_MODE_444 && IS_RGB(pix_fmt)))
|
(ctx->rgb_mode == NVENC_RGB_MODE_444 && IS_RGB(pix_fmt)))
|
||||||
|
|
||||||
|
#define IS_YUV422(pix_fmt) (pix_fmt == AV_PIX_FMT_NV16 || \
|
||||||
|
pix_fmt == AV_PIX_FMT_P210 || \
|
||||||
|
pix_fmt == AV_PIX_FMT_P216)
|
||||||
|
|
||||||
#define IS_GBRP(pix_fmt) (pix_fmt == AV_PIX_FMT_GBRP || \
|
#define IS_GBRP(pix_fmt) (pix_fmt == AV_PIX_FMT_GBRP || \
|
||||||
pix_fmt == AV_PIX_FMT_GBRP16)
|
pix_fmt == AV_PIX_FMT_GBRP16)
|
||||||
|
|
||||||
@ -477,6 +488,16 @@ static int nvenc_check_capabilities(AVCodecContext *avctx)
|
|||||||
return AVERROR(ENOSYS);
|
return AVERROR(ENOSYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NVENC_HAVE_422_SUPPORT
|
||||||
|
ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_YUV422_ENCODE);
|
||||||
|
#else
|
||||||
|
ret = 0;
|
||||||
|
#endif
|
||||||
|
if (IS_YUV422(ctx->data_pix_fmt) && ret <= 0) {
|
||||||
|
av_log(avctx, AV_LOG_WARNING, "YUV422P not supported\n");
|
||||||
|
return AVERROR(ENOSYS);
|
||||||
|
}
|
||||||
|
|
||||||
ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_LOSSLESS_ENCODE);
|
ret = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_LOSSLESS_ENCODE);
|
||||||
if (ctx->flags & NVENC_LOSSLESS && ret <= 0) {
|
if (ctx->flags & NVENC_LOSSLESS && ret <= 0) {
|
||||||
av_log(avctx, AV_LOG_WARNING, "Lossless encoding not supported\n");
|
av_log(avctx, AV_LOG_WARNING, "Lossless encoding not supported\n");
|
||||||
@ -1297,6 +1318,18 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
|
|||||||
cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
|
cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_GUID;
|
||||||
avctx->profile = AV_PROFILE_H264_HIGH;
|
avctx->profile = AV_PROFILE_H264_HIGH;
|
||||||
break;
|
break;
|
||||||
|
#ifdef NVENC_HAVE_H264_10BIT_SUPPORT
|
||||||
|
case NV_ENC_H264_PROFILE_HIGH_10:
|
||||||
|
cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_10_GUID;
|
||||||
|
avctx->profile = AV_PROFILE_H264_HIGH_10;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef NVENC_HAVE_422_SUPPORT
|
||||||
|
case NV_ENC_H264_PROFILE_HIGH_422:
|
||||||
|
cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_422_GUID;
|
||||||
|
avctx->profile = AV_PROFILE_H264_HIGH_422;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
case NV_ENC_H264_PROFILE_HIGH_444P:
|
case NV_ENC_H264_PROFILE_HIGH_444P:
|
||||||
cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
|
cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
|
||||||
avctx->profile = AV_PROFILE_H264_HIGH_444_PREDICTIVE;
|
avctx->profile = AV_PROFILE_H264_HIGH_444_PREDICTIVE;
|
||||||
@ -1304,21 +1337,37 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NVENC_HAVE_H264_10BIT_SUPPORT
|
||||||
|
// force setting profile as high10 if input is 10 bit or if it should be encoded as 10 bit
|
||||||
|
if (IS_10BIT(ctx->data_pix_fmt) || ctx->highbitdepth) {
|
||||||
|
cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_10_GUID;
|
||||||
|
avctx->profile = AV_PROFILE_H264_HIGH_10;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// force setting profile as high444p if input is AV_PIX_FMT_YUV444P
|
// force setting profile as high444p if input is AV_PIX_FMT_YUV444P
|
||||||
if (IS_YUV444(ctx->data_pix_fmt)) {
|
if (IS_YUV444(ctx->data_pix_fmt)) {
|
||||||
cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
|
cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_444_GUID;
|
||||||
avctx->profile = AV_PROFILE_H264_HIGH_444_PREDICTIVE;
|
avctx->profile = AV_PROFILE_H264_HIGH_444_PREDICTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef NVENC_HAVE_422_SUPPORT
|
||||||
|
// force setting profile as high422p if input is AV_PIX_FMT_YUV422P
|
||||||
|
if (IS_YUV422(ctx->data_pix_fmt)) {
|
||||||
|
cc->profileGUID = NV_ENC_H264_PROFILE_HIGH_422_GUID;
|
||||||
|
avctx->profile = AV_PROFILE_H264_HIGH_422;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
vui->bitstreamRestrictionFlag = cc->gopLength != 1 || avctx->profile < AV_PROFILE_H264_HIGH;
|
vui->bitstreamRestrictionFlag = cc->gopLength != 1 || avctx->profile < AV_PROFILE_H264_HIGH;
|
||||||
|
|
||||||
h264->chromaFormatIDC = avctx->profile == AV_PROFILE_H264_HIGH_444_PREDICTIVE ? 3 : 1;
|
h264->chromaFormatIDC = IS_YUV444(ctx->data_pix_fmt) ? 3 : IS_YUV422(ctx->data_pix_fmt) ? 2 : 1;
|
||||||
|
|
||||||
h264->level = ctx->level;
|
h264->level = ctx->level;
|
||||||
|
|
||||||
#ifdef NVENC_HAVE_NEW_BIT_DEPTH_API
|
#ifdef NVENC_HAVE_NEW_BIT_DEPTH_API
|
||||||
h264->inputBitDepth = h264->outputBitDepth =
|
h264->inputBitDepth = IS_10BIT(ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
|
||||||
IS_10BIT(ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
|
h264->outputBitDepth = (IS_10BIT(ctx->data_pix_fmt) || ctx->highbitdepth) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ctx->coder >= 0)
|
if (ctx->coder >= 0)
|
||||||
@ -1428,13 +1477,13 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
|
|||||||
avctx->profile = AV_PROFILE_HEVC_MAIN_10;
|
avctx->profile = AV_PROFILE_HEVC_MAIN_10;
|
||||||
}
|
}
|
||||||
|
|
||||||
// force setting profile as rext if input is yuv444
|
// force setting profile as rext if input is yuv444 or yuv422
|
||||||
if (IS_YUV444(ctx->data_pix_fmt)) {
|
if (IS_YUV444(ctx->data_pix_fmt) || IS_YUV422(ctx->data_pix_fmt)) {
|
||||||
cc->profileGUID = NV_ENC_HEVC_PROFILE_FREXT_GUID;
|
cc->profileGUID = NV_ENC_HEVC_PROFILE_FREXT_GUID;
|
||||||
avctx->profile = AV_PROFILE_HEVC_REXT;
|
avctx->profile = AV_PROFILE_HEVC_REXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
hevc->chromaFormatIDC = IS_YUV444(ctx->data_pix_fmt) ? 3 : 1;
|
hevc->chromaFormatIDC = IS_YUV444(ctx->data_pix_fmt) ? 3 : IS_YUV422(ctx->data_pix_fmt) ? 2 : 1;
|
||||||
|
|
||||||
#ifdef NVENC_HAVE_NEW_BIT_DEPTH_API
|
#ifdef NVENC_HAVE_NEW_BIT_DEPTH_API
|
||||||
hevc->inputBitDepth = IS_10BIT(ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
|
hevc->inputBitDepth = IS_10BIT(ctx->data_pix_fmt) ? NV_ENC_BIT_DEPTH_10 : NV_ENC_BIT_DEPTH_8;
|
||||||
@ -1821,6 +1870,13 @@ static NV_ENC_BUFFER_FORMAT nvenc_map_buffer_format(enum AVPixelFormat pix_fmt)
|
|||||||
return NV_ENC_BUFFER_FORMAT_ARGB10;
|
return NV_ENC_BUFFER_FORMAT_ARGB10;
|
||||||
case AV_PIX_FMT_X2BGR10:
|
case AV_PIX_FMT_X2BGR10:
|
||||||
return NV_ENC_BUFFER_FORMAT_ABGR10;
|
return NV_ENC_BUFFER_FORMAT_ABGR10;
|
||||||
|
#ifdef NVENC_HAVE_422_SUPPORT
|
||||||
|
case AV_PIX_FMT_NV16:
|
||||||
|
return NV_ENC_BUFFER_FORMAT_NV16;
|
||||||
|
case AV_PIX_FMT_P210:
|
||||||
|
case AV_PIX_FMT_P216:
|
||||||
|
return NV_ENC_BUFFER_FORMAT_P210;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
return NV_ENC_BUFFER_FORMAT_UNDEFINED;
|
return NV_ENC_BUFFER_FORMAT_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,12 @@ typedef void ID3D11Device;
|
|||||||
#define NVENC_HAVE_UNIDIR_B
|
#define NVENC_HAVE_UNIDIR_B
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// SDK 13.0 compile time feature checks
|
||||||
|
#if NVENCAPI_CHECK_VERSION(13, 0)
|
||||||
|
#define NVENC_HAVE_H264_10BIT_SUPPORT
|
||||||
|
#define NVENC_HAVE_422_SUPPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct NvencSurface
|
typedef struct NvencSurface
|
||||||
{
|
{
|
||||||
NV_ENC_INPUT_PTR input_surface;
|
NV_ENC_INPUT_PTR input_surface;
|
||||||
@ -151,6 +157,12 @@ enum {
|
|||||||
NV_ENC_H264_PROFILE_BASELINE,
|
NV_ENC_H264_PROFILE_BASELINE,
|
||||||
NV_ENC_H264_PROFILE_MAIN,
|
NV_ENC_H264_PROFILE_MAIN,
|
||||||
NV_ENC_H264_PROFILE_HIGH,
|
NV_ENC_H264_PROFILE_HIGH,
|
||||||
|
#ifdef NVENC_HAVE_H264_10BIT_SUPPORT
|
||||||
|
NV_ENC_H264_PROFILE_HIGH_10,
|
||||||
|
#endif
|
||||||
|
#ifdef NVENC_HAVE_422_SUPPORT
|
||||||
|
NV_ENC_H264_PROFILE_HIGH_422,
|
||||||
|
#endif
|
||||||
NV_ENC_H264_PROFILE_HIGH_444P,
|
NV_ENC_H264_PROFILE_HIGH_444P,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -61,6 +61,12 @@ static const AVOption options[] = {
|
|||||||
{ "baseline", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_BASELINE }, 0, 0, VE, .unit = "profile" },
|
{ "baseline", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_BASELINE }, 0, 0, VE, .unit = "profile" },
|
||||||
{ "main", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_MAIN }, 0, 0, VE, .unit = "profile" },
|
{ "main", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_MAIN }, 0, 0, VE, .unit = "profile" },
|
||||||
{ "high", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_HIGH }, 0, 0, VE, .unit = "profile" },
|
{ "high", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_HIGH }, 0, 0, VE, .unit = "profile" },
|
||||||
|
#ifdef NVENC_HAVE_H264_10BIT_SUPPORT
|
||||||
|
{ "high10", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_HIGH_10 }, 0, 0, VE, .unit = "profile" },
|
||||||
|
#endif
|
||||||
|
#ifdef NVENC_HAVE_422_SUPPORT
|
||||||
|
{ "high422", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_HIGH_422 }, 0, 0, VE, .unit = "profile" },
|
||||||
|
#endif
|
||||||
{ "high444p", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_HIGH_444P }, 0, 0, VE, .unit = "profile" },
|
{ "high444p", "", 0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_H264_PROFILE_HIGH_444P }, 0, 0, VE, .unit = "profile" },
|
||||||
#ifdef NVENC_HAVE_H264_LVL6
|
#ifdef NVENC_HAVE_H264_LVL6
|
||||||
{ "level", "Set the encoding level restriction", OFFSET(level), AV_OPT_TYPE_INT, { .i64 = NV_ENC_LEVEL_AUTOSELECT }, NV_ENC_LEVEL_AUTOSELECT, NV_ENC_LEVEL_H264_62, VE, .unit = "level" },
|
{ "level", "Set the encoding level restriction", OFFSET(level), AV_OPT_TYPE_INT, { .i64 = NV_ENC_LEVEL_AUTOSELECT }, NV_ENC_LEVEL_AUTOSELECT, NV_ENC_LEVEL_H264_62, VE, .unit = "level" },
|
||||||
@ -199,6 +205,9 @@ static const AVOption options[] = {
|
|||||||
{ "fullres", "Two Pass encoding is enabled where first Pass is full resolution",
|
{ "fullres", "Two Pass encoding is enabled where first Pass is full resolution",
|
||||||
0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_TWO_PASS_FULL_RESOLUTION }, 0, 0, VE, .unit = "multipass" },
|
0, AV_OPT_TYPE_CONST, { .i64 = NV_ENC_TWO_PASS_FULL_RESOLUTION }, 0, 0, VE, .unit = "multipass" },
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef NVENC_HAVE_H264_10BIT_SUPPORT
|
||||||
|
{ "highbitdepth", "Enable 10 bit encode for 8 bit input",OFFSET(highbitdepth),AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
|
||||||
|
#endif
|
||||||
#ifdef NVENC_HAVE_LDKFS
|
#ifdef NVENC_HAVE_LDKFS
|
||||||
{ "ldkfs", "Low delay key frame scale; Specifies the Scene Change frame size increase allowed in case of single frame VBV and CBR",
|
{ "ldkfs", "Low delay key frame scale; Specifies the Scene Change frame size increase allowed in case of single frame VBV and CBR",
|
||||||
OFFSET(ldkfs), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UCHAR_MAX, VE },
|
OFFSET(ldkfs), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, UCHAR_MAX, VE },
|
||||||
|
Reference in New Issue
Block a user