[FFmpeg-cvslog] parse ID3v2 chapters

Paul B Mahol git at videolan.org
Sun Oct 28 16:10:36 CET 2012


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sat Oct 27 22:00:09 2012 +0000| [07ed191b15fbf2ad396b6a7c1024410553d63a58] | committer: Paul B Mahol

parse ID3v2 chapters

Signed-off-by: Paul B Mahol <onemda at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=07ed191b15fbf2ad396b6a7c1024410553d63a58
---

 libavformat/id3v2.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 9c20287..14aa9e0 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -508,6 +508,36 @@ fail:
     avio_seek(pb, end, SEEK_SET);
 }
 
+static void read_chapter(AVFormatContext *s, AVIOContext *pb, int taglen, char *tag, ID3v2ExtraMeta **extra_meta)
+{
+    AVRational time_base = {1, 1000};
+    char title[1024];
+    uint32_t start, end;
+
+    taglen -= avio_get_str(pb, taglen, title, sizeof(title));
+    if (taglen < 16)
+        return;
+
+    start = avio_rb32(pb);
+    end   = avio_rb32(pb);
+    taglen -= 27;
+    if (taglen > 0) {
+        char tag[4];
+
+        avio_skip(pb, 8);
+        avio_read(pb, tag, 4);
+        if (!memcmp(tag, "TIT2", 4)) {
+            taglen = FFMIN(taglen, avio_rb32(pb));
+            if (taglen < 0)
+                return;
+            avio_skip(pb, 3);
+            avio_get_str(pb, taglen, title, sizeof(title));
+        }
+    }
+
+    avpriv_new_chapter(s, s->nb_chapters + 1, time_base, start, end, title);
+}
+
 typedef struct ID3v2EMFunc {
     const char *tag3;
     const char *tag4;
@@ -518,6 +548,7 @@ typedef struct ID3v2EMFunc {
 static const ID3v2EMFunc id3v2_extra_meta_funcs[] = {
     { "GEO", "GEOB", read_geobtag, free_geobtag },
     { "PIC", "APIC", read_apic,    free_apic },
+    { "CHAP","CHAP", read_chapter, NULL },
     { NULL }
 };
 



More information about the ffmpeg-cvslog mailing list