[FFmpeg-devel] [PATCH] id3v2: parse TIT3 in chapters

Paul B Mahol onemda at gmail.com
Sat Apr 27 20:58:18 CEST 2013


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

Need sample.

---
 libavformat/id3v2.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 3567bbc..7bcb599 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -511,7 +511,9 @@ fail:
 static void read_chapter(AVFormatContext *s, AVIOContext *pb, int taglen, char *tag, ID3v2ExtraMeta **extra_meta)
 {
     AVRational time_base = {1, 1000};
+    AVChapter *chapter;
     char title[1024];
+    char descr[1024] = {0};
     uint32_t start, end;
 
     taglen -= avio_get_str(pb, taglen, title, sizeof(title));
@@ -531,11 +533,25 @@ static void read_chapter(AVFormatContext *s, AVIOContext *pb, int taglen, char *
             if (taglen < 0)
                 return;
             avio_skip(pb, 3);
-            avio_get_str(pb, taglen, title, sizeof(title));
+            taglen -= avio_get_str(pb, taglen, title, sizeof(title));
+            if (taglen < 0) {
+                avio_read(pb, tag, 4);
+                if (!memcmp(tag, "TIT3", 4)) {
+                    taglen = FFMIN(taglen, avio_rb32(pb));
+                    if (taglen > 0) {
+                        avio_skip(pb, 3);
+                        avio_get_str(pb, taglen, descr, sizeof(descr));
+                    }
+                }
+            }
         }
     }
 
-    avpriv_new_chapter(s, s->nb_chapters + 1, time_base, start, end, title);
+    chapter = avpriv_new_chapter(s, s->nb_chapters + 1, time_base, start, end, title);
+    if (!chapter)
+        return;
+    if (descr[0])
+        av_dict_set(&chapter->metadata, "description", descr, 0);
 }
 
 typedef struct ID3v2EMFunc {
-- 
1.7.11.2



More information about the ffmpeg-devel mailing list