[FFmpeg-devel] [PATCH] Add channel label and bitmap values to metadata

Billy Shambrook billy.shambrook at gmail.com
Fri Oct 10 12:21:23 CEST 2014


---
 libavformat/mov_chan.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 1 deletion(-)

diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c
index 3b91ed7..aa369f2 100644
--- a/libavformat/mov_chan.c
+++ b/libavformat/mov_chan.c
@@ -133,6 +133,66 @@ enum MovChannelLayoutTag {
     MOV_CH_LAYOUT_DTS_8_1_B             = (181 << 16) | 9,
 };
 
+struct MovChannelLabel {
+    uint32_t code;
+    char name[128];
+};
+
+static const struct MovChannelLabel mov_ch_labels[] = {
+    { 0,            "Unused"              },
+    { 1,            "Left"                },
+    { 2,            "Right"               },
+    { 3,            "Center"              },
+    { 4,            "LFE Screen"          },
+    { 5,            "Left Surround"       },
+    { 6,            "Right Surround"      },
+    { 7,            "Left Center"         },
+    { 8,            "Right Center"        },
+    { 9,            "Center Surround"     },
+    { 33,           "Rear Surround Left"  },
+    { 34,           "Rear Surround Right" },
+    { 38,           "Left Total"          },
+    { 39,           "Right Total"         },
+    { 42,           "Mono"                },
+    { 65536,        "Discrete 0"          },
+    { (1<<16) | 1,  "Discrete 1"          },
+    { (1<<16) | 2,  "Discrete 2"          },
+    { (1<<16) | 3,  "Discrete 3"          },
+    { (1<<16) | 4,  "Discrete 4"          },
+    { (1<<16) | 5,  "Discrete 5"          },
+    { (1<<16) | 6,  "Discrete 6"          },
+    { (1<<16) | 7,  "Discrete 7"          },
+    { (1<<16) | 8,  "Discrete 8"          },
+    { (1<<16) | 9,  "Discrete 9"          },
+    { (1<<16) | 10, "Discrete 10"         },
+    { (1<<16) | 11, "Discrete 11"         },
+    { (1<<16) | 12, "Discrete 12"         },
+    { (1<<16) | 13, "Discrete 13"         },
+    { (1<<16) | 14, "Discrete 14"         },
+    { (1<<16) | 15, "Discrete 15"         },
+    { 0xFFFFFFFF,   "Unknown"             }
+};
+
+struct MovChannelBitmap {
+    uint32_t code;
+    char name[128];
+};
+
+static const struct MovChannelBitmap mov_ch_bitmap[] = {
+    { (1 << 0),   "Left"                 },
+    { (1 << 1),   "Right"                },
+    { (1 << 2),   "Center"               },
+    { (1 << 3),   "LFE Screen"           },
+    { (1 << 4),   "Left Surround"        },
+    { (1 << 5),   "Right Surround"       },
+    { (1 << 6),   "Left Center"          },
+    { (1 << 7),   "Right Center"         },
+    { (1 << 8),   "Center Surround"      },
+    { (1 << 9),   "Left Surround Direct" },
+    { (1 << 10),  "Rear Surround Direct" },
+    { 0xFFFFFFFF, "Unknown"              }
+};
+
 struct MovChannelLayoutMap {
     uint32_t tag;
     uint64_t layout;
@@ -548,7 +608,8 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st,
                      int64_t size)
 {
     uint32_t layout_tag, bitmap, num_descr, label_mask;
-    int i;
+    int i, j;
+    char label_tag[16];
 
     if (size < 12)
         return AVERROR_INVALIDDATA;
@@ -572,6 +633,13 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st,
         avio_rl32(pb);                      // mCoordinates[1]
         avio_rl32(pb);                      // mCoordinates[2]
         size -= 20;
+        for (j = 0; mov_ch_labels[j].code != 0xFFFFFFFF; j++) {
+            if (mov_ch_labels[j].code == label){
+                snprintf(label_tag, sizeof(label_tag), "channel_label_%d", i);
+                av_dict_set(&st->metadata, label_tag, mov_ch_labels[j].name, 0);
+                break;
+            }
+        }
         if (layout_tag == 0) {
             uint32_t mask_incr = mov_get_channel_label(label);
             if (mask_incr == 0) {
@@ -585,6 +653,12 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st,
         if (label_mask)
             st->codec->channel_layout = label_mask;
     } else
+        for (i = 0; mov_ch_bitmap[i].code != 0xFFFFFFFF; i++) {
+            if (mov_ch_bitmap[i].code == bitmap){
+                av_dict_set(&st->metadata, "channel_bitmap", mov_ch_bitmap[i].name, 0);
+                break;
+            }
+        }
         st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap);
     avio_skip(pb, size - 12);
 
-- 
1.9.3 (Apple Git-50)



More information about the ffmpeg-devel mailing list