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

Harry Mallon harry.mallon at codex.online
Wed Aug 12 15:25:14 EEST 2020


Rebased the patch on master (it didn't build before) and fixed FATE.

>From ac8d7884b036b504d07f38815de1c163c5e1691e Mon Sep 17 00:00:00 2001

From: Harry Mallon <harry.mallon at codex.online>
Date: Wed, 12 Aug 2020 10:26:23 +0100
Subject: [PATCH v2] 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 at codex.online>
---
 libavformat/mxfdec.c           | 22 ++++++++++++++++++++++
 tests/ref/fate/mxf-probe-dnxhd |  2 +-
 tests/ref/fate/mxf-probe-dv25  |  2 +-
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 4b56984b77..7e77fbca10 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -199,6 +199,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;
@@ -1222,6 +1225,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;
@@ -2492,6 +2504,16 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
             }
             if (descriptor->aspect_ratio.num && descriptor->aspect_ratio.den)
                 st->display_aspect_ratio = descriptor->aspect_ratio;
+            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;
+            }
             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;
diff --git a/tests/ref/fate/mxf-probe-dnxhd b/tests/ref/fate/mxf-probe-dnxhd
index 012d3ea1d9..5a6221b1d5 100644
--- a/tests/ref/fate/mxf-probe-dnxhd
+++ b/tests/ref/fate/mxf-probe-dnxhd
@@ -124,7 +124,7 @@ sample_aspect_ratio=1:1
 display_aspect_ratio=4:3
 pix_fmt=yuv422p
 level=-99
-color_range=unknown
+color_range=tv
 color_space=bt709
 color_transfer=bt709
 color_primaries=bt709
diff --git a/tests/ref/fate/mxf-probe-dv25 b/tests/ref/fate/mxf-probe-dv25
index 810f145f41..ffd26c4dfd 100644
--- a/tests/ref/fate/mxf-probe-dv25
+++ b/tests/ref/fate/mxf-probe-dv25
@@ -16,7 +16,7 @@ sample_aspect_ratio=16:15
 display_aspect_ratio=4:3
 pix_fmt=yuv420p
 level=-99
-color_range=unknown
+color_range=tv
 color_space=unknown
 color_transfer=bt470m
 color_primaries=unknown
-- 
2.28.0




More information about the ffmpeg-devel mailing list