From 119a246e570ff346490aef88710d8c8b4aae34e7 Mon Sep 17 00:00:00 2001
From: Martin Vignali <martin.vignali@gmail.com>
Date: Sat, 24 Nov 2018 22:48:08 +0100
Subject: [PATCH 13/14] avcodec/prores_aw : only set color prim, trc, space 
 values if supported

set to unspecified if frame have another value
---
 libavcodec/proresenc_anatoliy.c | 49 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 3 deletions(-)

diff --git a/libavcodec/proresenc_anatoliy.c b/libavcodec/proresenc_anatoliy.c
index 8047f1c242..8098336b3b 100644
--- a/libavcodec/proresenc_anatoliy.c
+++ b/libavcodec/proresenc_anatoliy.c
@@ -656,6 +656,7 @@ static int prores_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                                const AVFrame *pict, int *got_packet)
 {
     ProresContext *ctx = avctx->priv_data;
+    int color_primaries = 0, color_trc = 0, colorspace = 0;/* unspecified by default */
     int header_size = 148;
     uint8_t *buf;
     int pic_size, ret;
@@ -686,9 +687,51 @@ static int prores_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         *buf++ = 0x82; // 422, not interlaced
     }
     *buf++ = 0; /* reserved */
-    *buf++ = pict->color_primaries;
-    *buf++ = pict->color_trc;
-    *buf++ = pict->colorspace;
+
+    switch (pict->color_primaries) {
+    case AVCOL_PRI_RESERVED0:
+    case AVCOL_PRI_BT709:
+    case AVCOL_PRI_UNSPECIFIED:
+    case AVCOL_PRI_BT470BG:
+    case AVCOL_PRI_SMPTE170M:
+    case AVCOL_PRI_BT2020:
+    case AVCOL_PRI_SMPTE431:
+    case AVCOL_PRI_SMPTE432:
+        color_primaries = pict->color_primaries;
+        break;
+    default:
+        av_log(avctx, AV_LOG_DEBUG,
+               "Frame color primaries %d are not supported in prores frame. Set prores frame value to unspecified\n", pict->color_primaries);
+        break;
+    }
+
+    switch (pict->color_trc) {
+    case AVCOL_TRC_RESERVED0:
+    case AVCOL_TRC_BT709:
+    case AVCOL_TRC_UNSPECIFIED:
+        color_trc = pict->color_trc;
+        break;
+    default:
+        av_log(avctx, AV_LOG_DEBUG,
+                "Frame color_trc %d are not supported in prores frame. Set prores frame value to unspecified\n", pict->color_trc);
+        break;
+    }
+
+    switch (pict->colorspace) {
+    case AVCOL_SPC_BT709:
+    case AVCOL_SPC_UNSPECIFIED:
+    case AVCOL_SPC_SMPTE170M:
+    case AVCOL_SPC_BT2020_NCL:
+        colorspace = pict->colorspace;
+        break;
+    default:
+        av_log(avctx, AV_LOG_DEBUG,
+                "Frame colorspace %d are not supported in prores frame. Set prores frame value to unspecified\n", pict->colorspace);
+        break;
+    }
+    *buf++ = color_primaries;
+    *buf++ = color_trc;
+    *buf++ = colorspace;
     if (avctx->profile >= FF_PROFILE_PRORES_4444) {
         if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10) {
             *buf++ = 0xA0;/* src b64a and no alpha */
-- 
2.14.3 (Apple Git-98)

