[FFmpeg-devel] [PATCHv4] flac: ignore duplicated ID3 tags if vorbis tags exist

Ben Boeckel mathstuf at gmail.com
Fri Feb 6 04:57:07 CET 2015


FLAC doesn't really support ID3 tags, so warn if they are found at all.
If vorbis tags are found, toss out duplicate ID3 tags.

Fixes #3799.

Signed-off-by: Ben Boeckel <mathstuf at gmail.com>
---
 libavformat/flacdec.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 1a8dc19..fdb8e46 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -33,6 +33,7 @@ static int flac_read_header(AVFormatContext *s)
     int ret, metadata_last=0, metadata_type, metadata_size, found_streaminfo=0;
     uint8_t header[4];
     uint8_t *buffer=NULL;
+    int has_idv3 = 0;
     AVStream *st = avformat_new_stream(s, NULL);
     if (!st)
         return AVERROR(ENOMEM);
@@ -47,6 +48,19 @@ static int flac_read_header(AVFormatContext *s)
         return 0;
     }
 
+    if (av_dict_count(s->metadata)) {
+        /* XXX: Is there a better way to parse this out? ID3 parsing is done
+         * all the way out in avformat_open_input. */
+        has_idv3 = 1;
+    }
+
+    if (has_idv3) {
+        int level = AV_LOG_WARNING;
+        if (s->error_recognition & AV_EF_COMPLIANT)
+            level = AV_LOG_ERROR;
+        av_log(s, level, "Spec-compliant FLAC do not support ID3 tags.\n");
+    }
+
     /* process metadata blocks */
     while (!avio_feof(s->pb) && !metadata_last) {
         avio_read(s->pb, header, 4);
@@ -139,8 +153,16 @@ static int flac_read_header(AVFormatContext *s)
             }
             /* process supported blocks other than STREAMINFO */
             if (metadata_type == FLAC_METADATA_TYPE_VORBIS_COMMENT) {
+                AVDictionary *other_meta = NULL;
                 AVDictionaryEntry *chmask;
 
+                if (has_idv3) {
+                    av_log(s, AV_LOG_VERBOSE, "FLAC found with ID3 and vorbis tags; ignoring ID3 tags also provided by vorbis.\n");
+
+                    av_dict_copy(&other_meta, s->metadata, 0);
+                    av_dict_free(&s->metadata);
+                }
+
                 ret = ff_vorbis_comment(s, &s->metadata, buffer, metadata_size, 1);
                 if (ret < 0) {
                     av_log(s, AV_LOG_WARNING, "error parsing VorbisComment metadata\n");
@@ -148,6 +170,11 @@ static int flac_read_header(AVFormatContext *s)
                     s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
                 }
 
+                if (other_meta) {
+                    av_dict_copy(&s->metadata, other_meta, AV_DICT_DONT_OVERWRITE);
+                    av_dict_free(&other_meta);
+                }
+
                 /* parse the channels mask if present */
                 chmask = av_dict_get(s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", NULL, 0);
                 if (chmask) {
-- 
2.2.2



More information about the ffmpeg-devel mailing list