diff options
author | Timo Rothenpieler <timo@rothenpieler.org> | 2023-10-03 17:31:11 +0200 |
---|---|---|
committer | Timo Rothenpieler <timo@rothenpieler.org> | 2023-10-09 20:17:44 +0200 |
commit | e006680d8ef0c7cdcbc18a4c6d83d5dac48bea75 (patch) | |
tree | 4704f1b0bdb5e85f6584b1bd0a63d543fa0c72d5 /libavcodec | |
parent | 3914abf76e3d1e65c41f7483ba76bc61f5057670 (diff) | |
download | ffmpeg-e006680d8ef0c7cdcbc18a4c6d83d5dac48bea75.tar.gz |
avcodec/nvenc: add option to control subsampling of packed rgb input
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/nvenc.c | 15 | ||||
-rw-r--r-- | libavcodec/nvenc.h | 7 | ||||
-rw-r--r-- | libavcodec/nvenc_av1.c | 5 | ||||
-rw-r--r-- | libavcodec/nvenc_h264.c | 5 | ||||
-rw-r--r-- | libavcodec/nvenc_hevc.c | 5 | ||||
-rw-r--r-- | libavcodec/version.h | 2 |
6 files changed, 37 insertions, 2 deletions
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 02486c2043..626f10d20a 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -92,10 +92,18 @@ const AVCodecHWConfigInternal *const ff_nvenc_hw_configs[] = { pix_fmt == AV_PIX_FMT_X2BGR10 || \ pix_fmt == AV_PIX_FMT_GBRP16) +#define IS_RGB(pix_fmt) (pix_fmt == AV_PIX_FMT_0RGB32 || \ + pix_fmt == AV_PIX_FMT_RGB32 || \ + pix_fmt == AV_PIX_FMT_0BGR32 || \ + pix_fmt == AV_PIX_FMT_BGR32 || \ + pix_fmt == AV_PIX_FMT_X2RGB10 || \ + pix_fmt == AV_PIX_FMT_X2BGR10) + #define IS_YUV444(pix_fmt) (pix_fmt == AV_PIX_FMT_YUV444P || \ pix_fmt == AV_PIX_FMT_YUV444P16 || \ pix_fmt == AV_PIX_FMT_GBRP || \ - pix_fmt == AV_PIX_FMT_GBRP16) + pix_fmt == AV_PIX_FMT_GBRP16 || \ + (ctx->rgb_mode == NVENC_RGB_MODE_444 && IS_RGB(pix_fmt))) #define IS_GBRP(pix_fmt) (pix_fmt == AV_PIX_FMT_GBRP || \ pix_fmt == AV_PIX_FMT_GBRP16) @@ -1951,6 +1959,11 @@ av_cold int ff_nvenc_encode_init(AVCodecContext *avctx) ctx->data_pix_fmt = avctx->pix_fmt; } + if (ctx->rgb_mode == NVENC_RGB_MODE_DISABLED && IS_RGB(ctx->data_pix_fmt)) { + av_log(avctx, AV_LOG_ERROR, "Packed RGB input, but RGB support is disabled.\n"); + return AVERROR(EINVAL); + } + ctx->frame = av_frame_alloc(); if (!ctx->frame) return AVERROR(ENOMEM); diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index cf0e8e5946..e5b0eb8305 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -168,6 +168,12 @@ enum { ANY_DEVICE, }; +enum { + NVENC_RGB_MODE_DISABLED, + NVENC_RGB_MODE_420, + NVENC_RGB_MODE_444, +}; + typedef struct NvencContext { AVClass *avclass; @@ -263,6 +269,7 @@ typedef struct NvencContext int timing_info; int highbitdepth; int max_slice_size; + int rgb_mode; } NvencContext; int ff_nvenc_encode_init(AVCodecContext *avctx); diff --git a/libavcodec/nvenc_av1.c b/libavcodec/nvenc_av1.c index 43643f7bf1..9f36796c4b 100644 --- a/libavcodec/nvenc_av1.c +++ b/libavcodec/nvenc_av1.c @@ -96,6 +96,11 @@ static const AVOption options[] = { OFFSET(device), AV_OPT_TYPE_INT, { .i64 = ANY_DEVICE }, -2, INT_MAX, VE, "gpu" }, { "any", "Pick the first device available", 0, AV_OPT_TYPE_CONST, { .i64 = ANY_DEVICE }, 0, 0, VE, "gpu" }, { "list", "List the available devices", 0, AV_OPT_TYPE_CONST, { .i64 = LIST_DEVICES }, 0, 0, VE, "gpu" }, + { "rgb_mode", "Configure how nvenc handles packed RGB input.", + OFFSET(rgb_mode), AV_OPT_TYPE_INT, { .i64 = NVENC_RGB_MODE_420 }, 0, INT_MAX, VE, "rgb_mode" }, + { "yuv420", "Convert to yuv420", 0, AV_OPT_TYPE_CONST, { .i64 = NVENC_RGB_MODE_420 }, 0, 0, VE, "rgb_mode" }, + { "yuv444", "Convert to yuv444", 0, AV_OPT_TYPE_CONST, { .i64 = NVENC_RGB_MODE_444 }, 0, 0, VE, "rgb_mode" }, + { "disabled", "Disables support, throws an error.", 0, AV_OPT_TYPE_CONST, { .i64 = NVENC_RGB_MODE_DISABLED }, 0, 0, VE, "rgb_mode" }, { "delay", "Delay frame output by the given amount of frames", OFFSET(async_depth), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 0, INT_MAX, VE }, { "rc-lookahead", "Number of frames to look ahead for rate-control", diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c index 4440e49b25..85a13634a3 100644 --- a/libavcodec/nvenc_h264.c +++ b/libavcodec/nvenc_h264.c @@ -130,6 +130,11 @@ static const AVOption options[] = { OFFSET(device), AV_OPT_TYPE_INT, { .i64 = ANY_DEVICE }, -2, INT_MAX, VE, "gpu" }, { "any", "Pick the first device available", 0, AV_OPT_TYPE_CONST, { .i64 = ANY_DEVICE }, 0, 0, VE, "gpu" }, { "list", "List the available devices", 0, AV_OPT_TYPE_CONST, { .i64 = LIST_DEVICES }, 0, 0, VE, "gpu" }, + { "rgb_mode", "Configure how nvenc handles packed RGB input.", + OFFSET(rgb_mode), AV_OPT_TYPE_INT, { .i64 = NVENC_RGB_MODE_420 }, 0, INT_MAX, VE, "rgb_mode" }, + { "yuv420", "Convert to yuv420", 0, AV_OPT_TYPE_CONST, { .i64 = NVENC_RGB_MODE_420 }, 0, 0, VE, "rgb_mode" }, + { "yuv444", "Convert to yuv444", 0, AV_OPT_TYPE_CONST, { .i64 = NVENC_RGB_MODE_444 }, 0, 0, VE, "rgb_mode" }, + { "disabled", "Disables support, throws an error.", 0, AV_OPT_TYPE_CONST, { .i64 = NVENC_RGB_MODE_DISABLED }, 0, 0, VE, "rgb_mode" }, { "delay", "Delay frame output by the given amount of frames", OFFSET(async_depth), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 0, INT_MAX, VE }, { "no-scenecut", "When lookahead is enabled, set this to 1 to disable adaptive I-frame insertion at scene cuts", diff --git a/libavcodec/nvenc_hevc.c b/libavcodec/nvenc_hevc.c index e88f7e9783..840df6da8a 100644 --- a/libavcodec/nvenc_hevc.c +++ b/libavcodec/nvenc_hevc.c @@ -119,6 +119,11 @@ static const AVOption options[] = { OFFSET(device), AV_OPT_TYPE_INT, { .i64 = ANY_DEVICE }, -2, INT_MAX, VE, "gpu" }, { "any", "Pick the first device available", 0, AV_OPT_TYPE_CONST, { .i64 = ANY_DEVICE }, 0, 0, VE, "gpu" }, { "list", "List the available devices", 0, AV_OPT_TYPE_CONST, { .i64 = LIST_DEVICES }, 0, 0, VE, "gpu" }, + { "rgb_mode", "Configure how nvenc handles packed RGB input.", + OFFSET(rgb_mode), AV_OPT_TYPE_INT, { .i64 = NVENC_RGB_MODE_420 }, 0, INT_MAX, VE, "rgb_mode" }, + { "yuv420", "Convert to yuv420", 0, AV_OPT_TYPE_CONST, { .i64 = NVENC_RGB_MODE_420 }, 0, 0, VE, "rgb_mode" }, + { "yuv444", "Convert to yuv444", 0, AV_OPT_TYPE_CONST, { .i64 = NVENC_RGB_MODE_444 }, 0, 0, VE, "rgb_mode" }, + { "disabled", "Disables support, throws an error.", 0, AV_OPT_TYPE_CONST, { .i64 = NVENC_RGB_MODE_DISABLED }, 0, 0, VE, "rgb_mode" }, { "delay", "Delay frame output by the given amount of frames", OFFSET(async_depth), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 0, INT_MAX, VE }, { "no-scenecut", "When lookahead is enabled, set this to 1 to disable adaptive I-frame insertion at scene cuts", diff --git a/libavcodec/version.h b/libavcodec/version.h index a51282e33d..6b46100aae 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -30,7 +30,7 @@ #include "version_major.h" #define LIBAVCODEC_VERSION_MINOR 30 -#define LIBAVCODEC_VERSION_MICRO 101 +#define LIBAVCODEC_VERSION_MICRO 102 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ |