[FFmpeg-devel] [PATCHv5 2/3] vorbis: append data from tags together

Ben Boeckel mathstuf at gmail.com
Mon Jan 13 04:19:27 CET 2014


Currently, if there are multiple 'performer' tags, the last one is the
only one which appears. Instead, join them with a semicolon.

Signed-off-by: Ben Boeckel <mathstuf at gmail.com>
---
 libavformat/oggparsevorbis.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index 36ad738..79d7ec0 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -52,7 +52,6 @@ static int ogm_chapter(AVFormatContext *as, uint8_t *key, uint8_t *val)
         avpriv_new_chapter(as, cnum, (AVRational) { 1, 1000 },
                            ms + 1000 * (s + 60 * (m + 60 * h)),
                            AV_NOPTS_VALUE, NULL);
-        av_free(val);
     } else if (!strcmp(key + keylen - 4, "NAME")) {
         for (i = 0; i < as->nb_chapters; i++)
             if (as->chapters[i]->id == cnum) {
@@ -62,7 +61,7 @@ static int ogm_chapter(AVFormatContext *as, uint8_t *key, uint8_t *val)
         if (!chapter)
             return 0;
 
-        av_dict_set(&chapter->metadata, "title", val, AV_DICT_DONT_STRDUP_VAL);
+        av_dict_set(&chapter->metadata, "title", val, 0);
     } else
         return 0;
 
@@ -113,22 +112,24 @@ int ff_vorbis_comment(AVFormatContext *as, AVDictionary **m,
         v++;
 
         if (tl && vl) {
-            char *tt, *ct;
+            char *tt, *ct, *vt;
 
             tt = av_malloc(tl + 1);
-            ct = av_malloc(vl + 1);
+            ct = av_malloc(vl + 2);
             if (!tt || !ct) {
                 av_freep(&tt);
                 av_freep(&ct);
                 return AVERROR(ENOMEM);
             }
+            ct[0] = ';';
+            vt = ct + 1;
 
             for (j = 0; j < tl; j++)
                 tt[j] = av_toupper(t[j]);
             tt[tl] = 0;
 
-            memcpy(ct, v, vl);
-            ct[vl] = 0;
+            memcpy(vt, v, vl);
+            vt[vl] = 0;
 
             /* The format in which the pictures are stored is the FLAC format.
              * Xiph says: "The binary FLAC picture structure is base64 encoded
@@ -146,7 +147,7 @@ int ff_vorbis_comment(AVFormatContext *as, AVDictionary **m,
                     av_freep(&ct);
                     continue;
                 }
-                if ((ret = av_base64_decode(pict, ct, vl)) > 0)
+                if ((ret = av_base64_decode(pict, vt, vl)) > 0)
                     ret = ff_flac_parse_picture(as, pict, ret);
                 av_freep(&tt);
                 av_freep(&ct);
@@ -155,10 +156,17 @@ int ff_vorbis_comment(AVFormatContext *as, AVDictionary **m,
                     av_log(as, AV_LOG_WARNING, "Failed to parse cover art block.\n");
                     continue;
                 }
-            } else if (!ogm_chapter(as, tt, ct))
-                av_dict_set(m, tt, ct,
+            } else if (!ogm_chapter(as, tt, vt)) {
+                int extra_flags = 0;
+                if (m && av_dict_get(*m, tt, NULL, 0)) {
+                    extra_flags = AV_DICT_APPEND;
+                    --vt;
+                }
+                av_dict_set(m, tt, vt,
                             AV_DICT_DONT_STRDUP_KEY |
-                            AV_DICT_DONT_STRDUP_VAL);
+                            extra_flags);
+            }
+            av_freep(&ct);
         }
     }
 
-- 
1.8.5.2



More information about the ffmpeg-devel mailing list