[FFmpeg-devel] [PATCH] extends Generic/CDDI/MPEG2 essence descriptors

Maksym Veremeyenko verem at m1stereo.tv
Thu Apr 21 16:03:01 CEST 2016


Hi,

attached patches extends Generic/CDDI/MPEG2 essence descriptors with 
additional items. These items required by AMWA AS-10 MXF specification.

-- 
Maksym Veremeyenko

-------------- next part --------------
From 937b1e3f14d641b83a40c9dc5e64e227121dddfa Mon Sep 17 00:00:00 2001
From: Maksym Veremeyenko <verem at m1.tv>
Date: Thu, 21 Apr 2016 01:18:39 +0300
Subject: [PATCH 2/2] Extend mpeg2 video descriptor with additional items

---
 libavformat/mxfenc.c |   47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 46 insertions(+), 1 deletions(-)

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index ec42cf5..c658624 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -50,6 +50,7 @@
 #include "libavcodec/dnxhddata.h"
 #include "libavcodec/h264.h"
 #include "libavcodec/internal.h"
+#include "libavcodec/mpegvideo.h"
 #include "audiointerleave.h"
 #include "avformat.h"
 #include "avio_internal.h"
@@ -458,6 +459,14 @@ static const MXFLocalTagPair mxf_local_tag_batch[] = {
     // MPEG video Descriptor
     { 0x8000, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0B,0x00,0x00}}, /* BitRate */
     { 0x8007, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x0A,0x00,0x00}}, /* ProfileAndLevel */
+    { 0x8001, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x02,0x00,0x00}}, /* Single Sequence Flag */
+    { 0x8002, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x03,0x00,0x00}}, /* Constant B Picture Flag */
+    { 0x8003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x04,0x00,0x00}}, /* Coded Content Scanning Kind */
+    { 0x8004, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x05,0x00,0x00}}, /* Low Delay Indicator */
+    { 0x8005, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x06,0x00,0x00}}, /* Closed GOP Indicator */
+    { 0x8006, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x07,0x00,0x00}}, /* Identical GOP */
+    { 0x8008, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x08,0x00,0x00}}, /* Maximum GOP Size */
+    { 0x8009, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x06,0x02,0x01,0x09,0x00,0x00}}, /* Maximum B Picture Count */
     // Wave Audio Essence Descriptor
     { 0x3D09, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x03,0x05,0x00,0x00,0x00}}, /* Average Bytes Per Second */
     { 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */
@@ -1203,7 +1212,10 @@ static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st)
     int profile_and_level = (st->codecpar->profile<<4) | st->codecpar->level;
 
     if (st->codecpar->codec_id != AV_CODEC_ID_H264) {
-        mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5);
+        AVCodecContext *avctx = st->codec;
+        MpegEncContext *mpeg = (avctx)?avctx->priv_data:NULL;
+
+        mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5+5+5+5+5+5+5+6+6);
 
         // bit rate
         mxf_write_local_tag(pb, 4, 0x8000);
@@ -1214,6 +1226,39 @@ static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st)
         if (!st->codecpar->profile)
             profile_and_level |= 0x80; // escape bit
         avio_w8(pb, profile_and_level);
+
+        // Single Sequence Flag
+        mxf_write_local_tag(pb, 1, 0x8001);
+        avio_w8(pb, 0);
+
+        // Constant B Picture Flag
+        mxf_write_local_tag(pb, 1, 0x8002);
+        avio_w8(pb, (!mpeg)?0:(mpeg->b_frame_strategy)?0:1);
+
+        // Coded Content Scanning Kind
+        mxf_write_local_tag(pb, 1, 0x8003);
+        avio_w8(pb, (sc->interlaced)?2:1);
+
+        // Low Delay Indicator
+        mxf_write_local_tag(pb, 1, 0x8004);
+        avio_w8(pb, (avctx && avctx->flags & AV_CODEC_FLAG_LOW_DELAY)?1:0);
+
+        // Closed GOP Indicator
+        mxf_write_local_tag(pb, 1, 0x8005);
+        avio_w8(pb, (avctx && avctx->flags & AV_CODEC_FLAG_CLOSED_GOP)?1:sc->closed_gop);
+
+        // Identical GOP
+        mxf_write_local_tag(pb, 1, 0x8006);
+        avio_w8(pb, (mpeg && mpeg->mpv_flags & FF_MPV_FLAG_STRICT_GOP)?1:0);
+
+        // Maximum GOP Size
+        mxf_write_local_tag(pb, 2, 0x8008);
+        avio_wb16(pb, (avctx)?avctx->gop_size:0);
+
+        // Maximum B Picture Count
+        mxf_write_local_tag(pb, 2, 0x8009);
+        avio_wb16(pb, (mpeg)?mpeg->max_b_frames:0);
+
     } else {
         mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 0);
     }
-- 
1.7.7.6

-------------- next part --------------
From eb3ef1f423864bd8d79d6170bbc137ac0be62f0b Mon Sep 17 00:00:00 2001
From: Maksym Veremeyenko <verem at m1.tv>
Date: Wed, 20 Apr 2016 14:24:40 +0300
Subject: [PATCH 1/2] Extend Generic/CDCI picture essence descriptors with
 additional items

---
 libavformat/mxfenc.c |   91 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 90 insertions(+), 1 deletions(-)

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 36a43e4..ec42cf5 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -419,10 +419,27 @@ static const MXFLocalTagPair mxf_local_tag_batch[] = {
     { 0x3201, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x06,0x01,0x00,0x00,0x00,0x00}}, /* Picture Essence Coding */
     { 0x3212, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x03,0x01,0x06,0x00,0x00,0x00}}, /* Field Dominance (Opt) */
     { 0x3215, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x05,0x01,0x13,0x00,0x00,0x00,0x00}}, /* Signal Standard */
+    { 0x3216, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x03,0x02,0x08,0x00,0x00,0x00}}, /* StoredF2Offset */
+    { 0x3205, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x08,0x00,0x00,0x00}}, /* Sampled Width */
+    { 0x3204, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x07,0x00,0x00,0x00}}, /* Sampled Height */
+    { 0x3206, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x09,0x00,0x00,0x00}}, /* SampledXOffset */
+    { 0x3207, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0A,0x00,0x00,0x00}}, /* SampledYOffset */
+    { 0x320A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x0D,0x00,0x00,0x00}}, /* DisplayXOffset */
+    { 0x3217, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x01,0x03,0x02,0x07,0x00,0x00,0x00}}, /* DisplayF2Offset */
+    { 0x3210, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x02,0x01,0x01,0x01,0x02,0x00}}, /* Capture Gamma */
+    { 0x3211, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x01,0x00,0x00,0x00,0x00}}, /* Image Alignment Offset */
+    { 0x3213, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x02,0x00,0x00,0x00,0x00}}, /* Image Start Offset */
+    { 0x3214, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x03,0x00,0x00,0x00,0x00}}, /* Image End Offset */
     // CDCI Picture Essence Descriptor
     { 0x3301, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x0A,0x00,0x00,0x00}}, /* Component Depth */
     { 0x3302, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x05,0x00,0x00,0x00}}, /* Horizontal Subsampling */
     { 0x3303, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x01,0x06,0x00,0x00,0x00}}, /* Color Siting */
+    { 0x3308, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x01,0x10,0x00,0x00,0x00}}, /* Vertical Subsampling */
+    { 0x330B, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x03,0x01,0x02,0x01,0x0A,0x00,0x00,0x00}}, /* ReversedByteOrder */
+    { 0x3307, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x18,0x01,0x04,0x00,0x00,0x00,0x00}}, /* PaddingBits */
+    { 0x3304, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x03,0x03,0x00,0x00,0x00}}, /* Black Ref Level */
+    { 0x3305, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x01,0x04,0x01,0x05,0x03,0x04,0x00,0x00,0x00}}, /* White Ref level */
+    { 0x3306, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x04,0x01,0x05,0x03,0x05,0x00,0x00,0x00}}, /* Color Range */
     // Generic Sound Essence Descriptor
     { 0x3D02, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x04,0x04,0x02,0x03,0x01,0x04,0x00,0x00,0x00}}, /* Locked/Unlocked */
     { 0x3D03, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x01,0x01,0x01,0x00,0x00}}, /* Audio sampling rate */
@@ -452,6 +469,11 @@ static const MXFLocalTagPair mxf_user_comments_local_tag[] = {
     { 0x5003, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x02,0x03,0x02,0x01,0x02,0x0A,0x01,0x00,0x00}}, /* Value */
 };
 
+static const uint8_t capture_gamma_ITU470[] = // MXF-Profile ARD_ZDF_SDF02 - v1.0.pdf
+    {06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x01,0x00,0x00};
+static const uint8_t capture_gamma_ITU709[] = // MXF-Profile ARD_ZDF_HDF01a - v1.1.pdf, also used in SMPTE 170M, 274M and 296M
+    {06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x01,0x01,0x01,0x02,0x00,0x00};
+
 static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int value)
 {
     avio_write(pb, uuid_base, 12);
@@ -1013,7 +1035,7 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke
     int stored_height = (st->codecpar->height+15)/16*16;
     int display_height;
     int f1, f2;
-    unsigned desc_size = size+8+8+8+8+8+8+8+5+16+4+12+20+5;
+    unsigned desc_size = size+8+8+8+8+8+8+8+5+16+4+12+20+5+8+8+8+8+8+8+8+20+8+8+8+8+5+6+8+8+8;
     if (sc->interlaced && sc->field_dominance)
         desc_size += 5;
     if (sc->signal_standard)
@@ -1100,6 +1122,73 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke
         avio_w8(pb, sc->field_dominance);
     }
 
+    /* StoredF2Offset */
+    mxf_write_local_tag(pb, 4, 0x3216);
+    avio_wb32(pb, 0);
+
+    /* Sampled Width */
+    mxf_write_local_tag(pb, 4, 0x3205);
+    avio_wb32(pb, st->codecpar->width);
+
+    /* Sampled Height */
+    mxf_write_local_tag(pb, 4,  0x3204);
+    avio_wb32(pb, display_height);
+
+    /* SampledXOffset */
+    mxf_write_local_tag(pb, 4,  0x3206);
+    avio_wb32(pb, 0);
+
+    /* SampledYOffset */
+    mxf_write_local_tag(pb, 4,  0x3207);
+    avio_wb32(pb, 0);
+
+    /* DisplayXOffset */
+    mxf_write_local_tag(pb, 4, 0x320A);
+    avio_wb32(pb, 0);
+
+    /* DisplayF2Offset */
+    mxf_write_local_tag(pb, 4, 0x3217);
+    avio_wb32(pb, 0);
+
+    /* Capture Gamma */
+    mxf_write_local_tag(pb, 16, 0x3210);
+    avio_write(pb, (720 == st->codecpar->height || 1080 == st->codecpar->height)?capture_gamma_ITU709:capture_gamma_ITU470, 16);
+
+    /* Image Alignment Offset */
+    mxf_write_local_tag(pb, 4, 0x3211);
+    avio_wb32(pb, 0);
+
+    /* Image Start Offset */
+    mxf_write_local_tag(pb, 4, 0x3213);
+    avio_wb32(pb, 0);
+
+    /* Image End Offset */
+    mxf_write_local_tag(pb, 4, 0x3214);
+    avio_wb32(pb, 0);
+
+    /* Vertical Subsampling */
+    mxf_write_local_tag(pb, 4, 0x3308);
+    avio_wb32(pb, (AV_PIX_FMT_YUV422P == st->codecpar->format)?1:(AV_PIX_FMT_YUV420P == st->codecpar->format)?2:0);
+
+    /* ReversedByteOrder */
+    mxf_write_local_tag(pb, 1, 0x330B);
+    avio_w8(pb, 0);
+
+    /* PaddingBits */
+    mxf_write_local_tag(pb, 2, 0x3307);
+    avio_wb16(pb, 0);
+
+    /* Black Ref Level */
+    mxf_write_local_tag(pb, 4, 0x3304);
+    avio_wb32(pb, (8 == sc->component_depth)?16:64);
+
+    /* White Ref level */
+    mxf_write_local_tag(pb, 4, 0x3305);
+    avio_wb32(pb, (8 == sc->component_depth)?235:940);
+
+    /* Color Range */
+    mxf_write_local_tag(pb, 4, 0x3306);
+    avio_wb32(pb, (8 == sc->component_depth)?225:897);
 }
 
 static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st)
-- 
1.7.7.6



More information about the ffmpeg-devel mailing list