I found two problems with decoding of DNxHD encoded videos in MXF container.

1. The DNxHD codec signature in libavformat/mxf.c is wrong.
2. Frame height is calculated incorrectly for interlaced videos. What's stored in PictureEssenceDescriptor in MXF is not a frame height but field height. This is a general problem that should affect other codecs. I checked how D-10 (IMX) in MXF container ends up being handled correctly, and it turned out it's because of stream parsing.

The patches fixing the decoding problems are attached. Note that I didn't look at MXF encoding, which might or might not be affected by problem 2.


--
Joseph Artsimovich
Software Developer
MirriAd Ltd

>From 47cbc31c9b4584a0ce6bc01a102837ba8012afb5 Mon Sep 17 00:00:00 2001
From: Joseph Artsimovich <[email protected]>
Date: Wed, 26 Oct 2011 15:06:59 +0100
Subject: [PATCH 1/2] Don't confuse frame height with field height in MXF
 decoder.

---
 libavformat/mxfdec.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index 76a8329..78dbc27 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -95,6 +95,7 @@ typedef struct {
     AVRational aspect_ratio;
     int width;
     int height;
+    int frame_layout;
     int channels;
     int bits_per_sample;
     UID *sub_descriptors_refs;
@@ -585,6 +586,9 @@ static int mxf_read_generic_descriptor(void *arg, 
AVIOContext *pb, int tag, int
     case 0x3202:
         descriptor->height = avio_rb32(pb);
         break;
+    case 0x320C:
+        descriptor->frame_layout = avio_r8(pb);
+        break;
     case 0x320E:
         descriptor->aspect_ratio.num = avio_rb32(pb);
         descriptor->aspect_ratio.den = avio_rb32(pb);
@@ -817,7 +821,9 @@ static int mxf_parse_structural_metadata(MXFContext *mxf)
             if (st->codec->codec_id == CODEC_ID_NONE)
                 st->codec->codec_id = container_ul->id;
             st->codec->width = descriptor->width;
-            st->codec->height = descriptor->height;
+            st->codec->height = descriptor->height; /* field height, not frame 
height */
+            if (descriptor->frame_layout == 1) /* interlaced */
+                st->codec->height *= 2;
             if (st->codec->codec_id == CODEC_ID_RAWVIDEO)
                 st->codec->pix_fmt = descriptor->pix_fmt;
             st->need_parsing = AVSTREAM_PARSE_HEADERS;
-- 
1.7.5.4

>From fd7dbaf0d4acdccf231fe4a87ca0f9f971051b8e Mon Sep 17 00:00:00 2001
From: Joseph Artsimovich <[email protected]>
Date: Wed, 26 Oct 2011 15:08:46 +0100
Subject: [PATCH 2/2] Fix incorrect DNxHD codec signature in MXF container.

---
 libavformat/mxf.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavformat/mxf.c b/libavformat/mxf.c
index 029486f..3d5c65d 100644
--- a/libavformat/mxf.c
+++ b/libavformat/mxf.c
@@ -41,7 +41,7 @@ const MXFCodecUL ff_mxf_codec_uls[] = {
     { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x02,0x00 
}, 13,    CODEC_ID_DVVIDEO }, /* DV25 IEC PAL */
     { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 
}, 14,   CODEC_ID_JPEG2000 }, /* JPEG2000 Codestream */
     { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x01,0x7F,0x00,0x00,0x00 
}, 13,   CODEC_ID_RAWVIDEO }, /* Uncompressed */
-    { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x03,0x02,0x00,0x00 
}, 14,      CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */
+    { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x71,0x00,0x00,0x00 
}, 13,      CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */
     /* SoundEssenceCompression */
     { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 
}, 13,  CODEC_ID_PCM_S16LE }, /* Uncompressed */
     { { 
0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 
}, 13,  CODEC_ID_PCM_S16LE },
-- 
1.7.5.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to