diff mbox series

[FFmpeg-devel] avformat/mxfdec: Read video range from PictureDescriptor

Message ID E8C39E3F-2938-4802-B9A2-88F73CE1ABA0@codex.online
State Superseded
Headers show
Series [FFmpeg-devel] avformat/mxfdec: Read video range from PictureDescriptor
Related show

Checks

Context Check Description
andriy/default pending
andriy/configure warning Failed to apply patch

Commit Message

Harry Mallon Aug. 12, 2020, 9:35 a.m. UTC
Thanks to Tomas for reviewing these MXF patches. Here is another. FFMPEG already writes out the three range tags. This just reads them in.

Best,
Harry

From c49f77d1e887d8c84752df11213dcf5afa8f761e Mon Sep 17 00:00:00 2001

From: Harry Mallon <harry.mallon@codex.online>
Date: Wed, 12 Aug 2020 10:26:23 +0100
Subject: [PATCH] avformat/mxfdec: Read video range from PictureDescriptor

* Capture black_ref, white_ref and color_range and recognise
  full and narrow range.

Signed-off-by: Harry Mallon <harry.mallon@codex.online>
---
 libavformat/mxfdec.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index fa9dcab658..9d2563239e 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -201,6 +201,9 @@  typedef struct MXFDescriptor {
     int bits_per_sample;
     int64_t duration; /* ContainerDuration optional property */
     unsigned int component_depth;
+    unsigned int black_ref_level;
+    unsigned int white_ref_level;
+    unsigned int color_range;
     unsigned int horiz_subsampling;
     unsigned int vert_subsampling;
     UID *sub_descriptors_refs;
@@ -1230,6 +1233,15 @@  static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int
     case 0x3302:
         descriptor->horiz_subsampling = avio_rb32(pb);
         break;
+    case 0x3304:
+        descriptor->black_ref_level = avio_rb32(pb);
+        break;
+    case 0x3305:
+        descriptor->white_ref_level = avio_rb32(pb);
+        break;
+    case 0x3306:
+        descriptor->color_range = avio_rb32(pb);
+        break;
     case 0x3308:
         descriptor->vert_subsampling = avio_rb32(pb);
         break;
@@ -2557,6 +2569,16 @@  static int mxf_parse_structural_metadata(MXFContext *mxf)
             st->codecpar->color_primaries = mxf_get_codec_ul(ff_mxf_color_primaries_uls, &descriptor->color_primaries_ul)->id;
             st->codecpar->color_trc       = mxf_get_codec_ul(ff_mxf_color_trc_uls, &descriptor->color_trc_ul)->id;
             st->codecpar->color_space     = mxf_get_codec_ul(ff_mxf_color_space_uls, &descriptor->color_space_ul)->id;
+            if (descriptor->black_ref_level == 0 &&
+                descriptor->white_ref_level == ((1<<descriptor->component_depth) - 1) &&
+                descriptor->color_range     == ((1<<descriptor->component_depth) - 1)) {
+                    st->codecpar->color_range = AVCOL_RANGE_JPEG;
+            }
+            else if (descriptor->black_ref_level == (1  <<(descriptor->component_depth - 4)) &&
+                     descriptor->white_ref_level == (235<<(descriptor->component_depth - 8)) &&
+                     descriptor->color_range     == ((14<<(descriptor->component_depth - 4)) + 1)) {
+                    st->codecpar->color_range = AVCOL_RANGE_MPEG;
+            }
             if (descriptor->mastering) {
                 ret = av_stream_add_side_data(st, AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
                                               (uint8_t *)descriptor->mastering,