[FFmpeg-devel] [PATCH 2/2] avcodec/dnxhdenc: properly store colorspace info

Paul B Mahol onemda at gmail.com
Fri Jan 24 14:39:52 EET 2020


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavcodec/dnxhdenc.c | 10 +++++++++-
 libavcodec/dnxhdenc.h |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index 2feb8baf21..c1b493a604 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -406,6 +406,14 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
     }
 
     ctx->is_444 = ctx->profile == FF_PROFILE_DNXHR_444;
+
+    switch (avctx->colorspace) {
+    case AVCOL_SPC_BT709:      ctx->colorspace = 0; break;
+    case AVCOL_SPC_BT2020_NCL: ctx->colorspace = 1; break;
+    case AVCOL_SPC_BT2020_CL:  ctx->colorspace = 2; break;
+    default:                   ctx->colorspace = 3; break;
+    }
+
     avctx->profile = ctx->profile;
     ctx->cid = ff_dnxhd_find_cid(avctx, ctx->bit_depth);
     if (!ctx->cid) {
@@ -576,7 +584,7 @@ static int dnxhd_write_header(AVCodecContext *avctx, uint8_t *buf)
     buf[0x21] = ctx->bit_depth == 10 ? 0x58 : 0x38;
     buf[0x22] = 0x88 + (ctx->interlaced << 2);
     AV_WB32(buf + 0x28, ctx->cid); // CID
-    buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) | (avctx->pix_fmt == AV_PIX_FMT_YUV444P10);
+    buf[0x2c] = (!ctx->interlaced << 7) | (ctx->is_444 << 6) | (ctx->colorspace << 1) | (avctx->pix_fmt == AV_PIX_FMT_YUV444P10);
 
     buf[0x5f] = 0x01; // UDL
 
diff --git a/libavcodec/dnxhdenc.h b/libavcodec/dnxhdenc.h
index 7b0d862e28..4d5f457e33 100644
--- a/libavcodec/dnxhdenc.h
+++ b/libavcodec/dnxhdenc.h
@@ -50,6 +50,7 @@ typedef struct DNXHDEncContext {
     int profile;
     int bit_depth;
     int is_444;
+    int colorspace;
     const CIDEntry *cid_table;
     uint8_t *msip; ///< Macroblock Scan Indexes Payload
     uint32_t *slice_size;
-- 
2.17.1



More information about the ffmpeg-devel mailing list