avcodec/nvenc: add option to control subsampling of packed rgb input

pull/390/head
Timo Rothenpieler 1 year ago
parent 3914abf76e
commit e006680d8e
  1. 15
      libavcodec/nvenc.c
  2. 7
      libavcodec/nvenc.h
  3. 5
      libavcodec/nvenc_av1.c
  4. 5
      libavcodec/nvenc_h264.c
  5. 5
      libavcodec/nvenc_hevc.c
  6. 2
      libavcodec/version.h

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

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

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

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

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

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

Loading…
Cancel
Save