summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Rothenpieler <timo@rothenpieler.org>2022-08-06 20:58:48 +0200
committerTimo Rothenpieler <timo@rothenpieler.org>2022-08-06 22:23:33 +0200
commitb71069879010426ef8d7dce614086f8fb90eb0f3 (patch)
treeacf321fed294d31f808c7b907b709e2004eab9db
parent611f8435341bf928e8b129a16657be5792571780 (diff)
avcodec/nvenc: hardcode color characteristics for internal RGB2YUV conversion
nvenc does not appear to use these values as inputs for its built in RGB to YUV conversion, but instead sets them on the output as-is. Testing indicates the input is expected to be sRGB, with the output ending up as limited range bt.470.
-rw-r--r--libavcodec/nvenc.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index e19378736f..11bd21f365 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1096,11 +1096,20 @@ static av_cold int nvenc_setup_h264_config(AVCodecContext *avctx)
NV_ENC_CONFIG_H264 *h264 = &cc->encodeCodecConfig.h264Config;
NV_ENC_CONFIG_H264_VUI_PARAMETERS *vui = &h264->h264VUIParameters;
- vui->colourMatrix = IS_GBRP(ctx->data_pix_fmt) ? AVCOL_SPC_RGB : avctx->colorspace;
- vui->colourPrimaries = avctx->color_primaries;
- vui->transferCharacteristics = avctx->color_trc;
- vui->videoFullRangeFlag = (avctx->color_range == AVCOL_RANGE_JPEG
- || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ420P || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ422P || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ444P);
+ const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(ctx->data_pix_fmt);
+
+ if ((pixdesc->flags & AV_PIX_FMT_FLAG_RGB) && !IS_GBRP(ctx->data_pix_fmt)) {
+ vui->colourMatrix = AVCOL_SPC_BT470BG;
+ vui->colourPrimaries = avctx->color_primaries;
+ vui->transferCharacteristics = avctx->color_trc;
+ vui->videoFullRangeFlag = 0;
+ } else {
+ vui->colourMatrix = IS_GBRP(ctx->data_pix_fmt) ? AVCOL_SPC_RGB : avctx->colorspace;
+ vui->colourPrimaries = avctx->color_primaries;
+ vui->transferCharacteristics = avctx->color_trc;
+ vui->videoFullRangeFlag = (avctx->color_range == AVCOL_RANGE_JPEG
+ || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ420P || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ422P || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ444P);
+ }
vui->colourDescriptionPresentFlag =
(vui->colourMatrix != 2 || vui->colourPrimaries != 2 || vui->transferCharacteristics != 2);
@@ -1208,11 +1217,20 @@ static av_cold int nvenc_setup_hevc_config(AVCodecContext *avctx)
NV_ENC_CONFIG_HEVC *hevc = &cc->encodeCodecConfig.hevcConfig;
NV_ENC_CONFIG_HEVC_VUI_PARAMETERS *vui = &hevc->hevcVUIParameters;
- vui->colourMatrix = IS_GBRP(ctx->data_pix_fmt) ? AVCOL_SPC_RGB : avctx->colorspace;
- vui->colourPrimaries = avctx->color_primaries;
- vui->transferCharacteristics = avctx->color_trc;
- vui->videoFullRangeFlag = (avctx->color_range == AVCOL_RANGE_JPEG
- || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ420P || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ422P || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ444P);
+ const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(ctx->data_pix_fmt);
+
+ if ((pixdesc->flags & AV_PIX_FMT_FLAG_RGB) && !IS_GBRP(ctx->data_pix_fmt)) {
+ vui->colourMatrix = AVCOL_SPC_BT470BG;
+ vui->colourPrimaries = avctx->color_primaries;
+ vui->transferCharacteristics = avctx->color_trc;
+ vui->videoFullRangeFlag = 0;
+ } else {
+ vui->colourMatrix = IS_GBRP(ctx->data_pix_fmt) ? AVCOL_SPC_RGB : avctx->colorspace;
+ vui->colourPrimaries = avctx->color_primaries;
+ vui->transferCharacteristics = avctx->color_trc;
+ vui->videoFullRangeFlag = (avctx->color_range == AVCOL_RANGE_JPEG
+ || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ420P || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ422P || ctx->data_pix_fmt == AV_PIX_FMT_YUVJ444P);
+ }
vui->colourDescriptionPresentFlag =
(vui->colourMatrix != 2 || vui->colourPrimaries != 2 || vui->transferCharacteristics != 2);