[FFmpeg-devel] [PATCH 2/3] lavf/matroskadec: export SegmentUID to metadata.

Nicolas George george at nsup.org
Fri Feb 27 16:50:29 CET 2015


The metadata key is "segment_uid", and is formatted as
32 hex nibbles grouped in 32 bits words by dashes.

Signed-off-by: Nicolas George <george at nsup.org>
---
 libavformat/matroskadec.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 6c0d0d5..f8519b7 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -273,6 +273,7 @@ typedef struct MatroskaDemuxContext {
     char    *title;
     char    *muxingapp;
     EbmlBin date_utc;
+    EbmlBin segment_uid;
     EbmlList tracks;
     EbmlList attachments;
     EbmlList chapters;
@@ -342,7 +343,7 @@ static EbmlSyntax matroska_info[] = {
     { MATROSKA_ID_WRITINGAPP,    EBML_NONE },
     { MATROSKA_ID_MUXINGAPP,     EBML_UTF8, 0, offsetof(MatroskaDemuxContext, muxingapp) },
     { MATROSKA_ID_DATEUTC,       EBML_BIN,  0, offsetof(MatroskaDemuxContext, date_utc) },
-    { MATROSKA_ID_SEGMENTUID,    EBML_NONE },
+    { MATROSKA_ID_SEGMENTUID,    EBML_BIN,  0, offsetof(MatroskaDemuxContext, segment_uid) },
     { 0 }
 };
 
@@ -1575,6 +1576,27 @@ static void matroska_metadata_creation_time(AVDictionary **metadata, int64_t dat
         av_dict_set(metadata, "creation_time", buffer, 0);
 }
 
+static void matroska_metadata_uid(AVFormatContext *s, AVDictionary **metadata, EbmlBin *uid)
+{
+    char buffer[36], *p = buffer;
+    unsigned i;
+
+    if(uid->size != 16) {
+        if (uid->size)
+            av_log(s, AV_LOG_WARNING, "Invalid SegmentUID length %d\n", uid->size);
+        return;
+    }
+    for (i = 0; i < uid->size; i++) {
+        if (i > 0 && !(i & 3))
+            *(p++) = '-';
+        snprintf(p, 3, "%02x", uid->data[i]);
+        p += 2;
+    }
+    *(p++) = 0;
+    av_assert0(p == buffer + sizeof(buffer));
+    av_dict_set(metadata, "segment_uid", buffer, 0);
+}
+
 static int matroska_parse_flac(AVFormatContext *s,
                                MatroskaTrack *track,
                                int *offset)
@@ -2125,6 +2147,7 @@ static int matroska_read_header(AVFormatContext *s)
 
     if (matroska->date_utc.size == 8)
         matroska_metadata_creation_time(&s->metadata, AV_RB64(matroska->date_utc.data));
+    matroska_metadata_uid(s, &s->metadata, &matroska->segment_uid);
 
     res = matroska_parse_tracks(s);
     if (res < 0)
-- 
2.1.4



More information about the ffmpeg-devel mailing list