* [FFmpeg-devel] [PATCH 1/3] lavu/dict: add AV_DICT_DEDUP @ 2022-08-25 0:27 rcombs 2022-08-25 0:27 ` [FFmpeg-devel] [PATCH 2/3] lavf/metadata: support duplicate keys in ff_metadata_conv rcombs 2022-08-25 0:27 ` [FFmpeg-devel] [PATCH 3/3] lavf/id3v2dec: support multiple values and TIPL frames rcombs 0 siblings, 2 replies; 4+ messages in thread From: rcombs @ 2022-08-25 0:27 UTC (permalink / raw) To: ffmpeg-devel This is useful when multiple metadata inputs may set the same value (e.g. both a container-specific header and an ID3 tag). --- libavutil/dict.c | 11 +++++++++++ libavutil/dict.h | 1 + 2 files changed, 12 insertions(+) diff --git a/libavutil/dict.c b/libavutil/dict.c index 9d3d96c58b..aa98f753a3 100644 --- a/libavutil/dict.c +++ b/libavutil/dict.c @@ -76,6 +76,17 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, if (!(flags & AV_DICT_MULTIKEY)) { tag = av_dict_get(m, key, NULL, flags); + } else if (flags & AV_DICT_DEDUP) { + while ((tag = av_dict_get(m, key, tag, flags))) { + if ((!value && !tag->value) || + (value && tag->value && !strcmp(value, tag->value))) { + if (flags & AV_DICT_DONT_STRDUP_KEY) + av_free((void*)key); + if (flags & AV_DICT_DONT_STRDUP_VAL) + av_free((void*)value); + return 0; + } + } } if (flags & AV_DICT_DONT_STRDUP_KEY) copy_key = (void *)key; diff --git a/libavutil/dict.h b/libavutil/dict.h index 0d1afc6c64..a957b48bf3 100644 --- a/libavutil/dict.h +++ b/libavutil/dict.h @@ -75,6 +75,7 @@ #define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no delimiter is added, the strings are simply concatenated. */ #define AV_DICT_MULTIKEY 64 /**< Allow to store several equal keys in the dictionary */ +#define AV_DICT_DEDUP 128 /**< If inserting a value that already exists for a key, do nothing. Only relevant with AV_DICT_MULTIKEY. */ typedef struct AVDictionaryEntry { char *key; -- 2.37.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH 2/3] lavf/metadata: support duplicate keys in ff_metadata_conv 2022-08-25 0:27 [FFmpeg-devel] [PATCH 1/3] lavu/dict: add AV_DICT_DEDUP rcombs @ 2022-08-25 0:27 ` rcombs 2022-08-25 0:27 ` [FFmpeg-devel] [PATCH 3/3] lavf/id3v2dec: support multiple values and TIPL frames rcombs 1 sibling, 0 replies; 4+ messages in thread From: rcombs @ 2022-08-25 0:27 UTC (permalink / raw) To: ffmpeg-devel --- libavformat/metadata.c | 2 +- tests/ref/fate/cover-art-aiff-id3v2-remux | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavformat/metadata.c b/libavformat/metadata.c index b9b6de7972..2a1ffc69e7 100644 --- a/libavformat/metadata.c +++ b/libavformat/metadata.c @@ -50,7 +50,7 @@ void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, key = dc->native; break; } - av_dict_set(&dst, key, mtag->value, 0); + av_dict_set(&dst, key, mtag->value, AV_DICT_MULTIKEY | AV_DICT_DEDUP); } av_dict_free(pm); *pm = dst; diff --git a/tests/ref/fate/cover-art-aiff-id3v2-remux b/tests/ref/fate/cover-art-aiff-id3v2-remux index 3ca2855eb8..2eac5f8d9c 100644 --- a/tests/ref/fate/cover-art-aiff-id3v2-remux +++ b/tests/ref/fate/cover-art-aiff-id3v2-remux @@ -67,10 +67,10 @@ TAG:title=third TAG:comment=Conductor [/STREAM] [FORMAT] -TAG:artist=Мельница +TAG:title=Дороги TAG:RATING=0 TAG:album=Ангелофрения -TAG:title=Дороги +TAG:artist=Мельница TAG:tracktotal=11 TAG:totaltracks=11 TAG:genre=Folk -- 2.37.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH 3/3] lavf/id3v2dec: support multiple values and TIPL frames 2022-08-25 0:27 [FFmpeg-devel] [PATCH 1/3] lavu/dict: add AV_DICT_DEDUP rcombs 2022-08-25 0:27 ` [FFmpeg-devel] [PATCH 2/3] lavf/metadata: support duplicate keys in ff_metadata_conv rcombs @ 2022-08-25 0:27 ` rcombs 1 sibling, 0 replies; 4+ messages in thread From: rcombs @ 2022-08-25 0:27 UTC (permalink / raw) To: ffmpeg-devel Fixes https://trac.ffmpeg.org/ticket/6949 Ordinary text frames in ID3v2 are allowed to have multiple (null-separated) values. This technically isn't allowed in TXXX, but it's used in practice by Picard, and supporting it is harmless. TIPL/IPL (Involved People List) and TMCL (Musician Credits List) work similarly to TXXX, but alternate key-value-key-value. --- libavformat/id3v2.c | 49 ++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index 191a305ffb..335a1436b2 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -321,8 +321,12 @@ static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen, AVDictionary **metadata, const char *key) { uint8_t *dst; - int encoding, dict_flags = AV_DICT_DONT_OVERWRITE | AV_DICT_DONT_STRDUP_VAL; + uint8_t *dst_key = NULL; + int encoding, dict_flags = AV_DICT_MULTIKEY | AV_DICT_DONT_STRDUP_VAL | AV_DICT_DEDUP; unsigned genre; + int count = 0; + int is_tipl = !(strcmp(key, "TIPL") && strcmp(key, "TMCL") && + strcmp(key, "IPL")); if (taglen < 1) return; @@ -330,30 +334,33 @@ static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen, encoding = avio_r8(pb); taglen--; /* account for encoding type byte */ - if (decode_str(s, pb, encoding, &dst, &taglen) < 0) { - av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", key); - return; - } - - if (!(strcmp(key, "TCON") && strcmp(key, "TCO")) && - (sscanf(dst, "(%d)", &genre) == 1 || sscanf(dst, "%d", &genre) == 1) && - genre <= ID3v1_GENRE_MAX) { - av_freep(&dst); - dst = av_strdup(ff_id3v1_genre_str[genre]); - } else if (!(strcmp(key, "TXXX") && strcmp(key, "TXX"))) { - /* dst now contains the key, need to get value */ - key = dst; + while (taglen > 1) { if (decode_str(s, pb, encoding, &dst, &taglen) < 0) { av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", key); - av_freep(&key); return; } - dict_flags |= AV_DICT_DONT_STRDUP_KEY; - } else if (!*dst) - av_freep(&dst); - if (dst) - av_dict_set(metadata, key, dst, dict_flags); + count++; + + if (!(strcmp(key, "TCON") && strcmp(key, "TCO")) && + (sscanf(dst, "(%d)", &genre) == 1 || sscanf(dst, "%d", &genre) == 1) && + genre <= ID3v1_GENRE_MAX) { + av_freep(&dst); + dst = av_strdup(ff_id3v1_genre_str[genre]); + } else if (!(strcmp(key, "TXXX") && strcmp(key, "TXX")) || + (is_tipl && (count & 1))) { + /* dst now contains the key, need to get value */ + av_free(dst_key); + key = dst_key = dst; + continue; + } else if (!*dst) + av_freep(&dst); + + if (dst) + av_dict_set(metadata, key, dst, dict_flags); + } + + av_free(dst_key); } static void read_uslt(AVFormatContext *s, AVIOContext *pb, int taglen, @@ -1039,7 +1046,7 @@ static void id3v2_parse(AVIOContext *pb, AVDictionary **metadata, pbx = &pb_local.pub; // read from sync buffer } #endif - if (tag[0] == 'T') + if (tag[0] == 'T' || !strcmp(tag, "IPL")) /* parse text tag */ read_ttag(s, pbx, tlen, metadata, tag); else if (!memcmp(tag, "USLT", 4)) -- 2.37.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH 1/3] lavu/dict: add AV_DICT_DEDUP @ 2022-08-24 23:51 rcombs 2022-08-24 23:51 ` [FFmpeg-devel] [PATCH 2/3] lavf/metadata: support duplicate keys in ff_metadata_conv rcombs 0 siblings, 1 reply; 4+ messages in thread From: rcombs @ 2022-08-24 23:51 UTC (permalink / raw) To: ffmpeg-devel This is useful when multiple metadata inputs may set the same value (e.g. both a container-specific header and an ID3 tag). --- libavutil/dict.c | 11 +++++++++++ libavutil/dict.h | 1 + 2 files changed, 12 insertions(+) diff --git a/libavutil/dict.c b/libavutil/dict.c index 9d3d96c58b..d8b38cc71f 100644 --- a/libavutil/dict.c +++ b/libavutil/dict.c @@ -76,6 +76,17 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, if (!(flags & AV_DICT_MULTIKEY)) { tag = av_dict_get(m, key, NULL, flags); + } else if (flags & AV_DICT_DEDUP) { + while ((tag = av_dict_get(m, key, NULL, flags))) { + if ((!value && !tag->value) || + (value && tag->value && !strcmp(value, tag->value))) { + if (flags & AV_DICT_DONT_STRDUP_KEY) + av_free(key); + if (flags & AV_DICT_DONT_STRDUP_VAL) + av_free(value); + return 0; + } + } } if (flags & AV_DICT_DONT_STRDUP_KEY) copy_key = (void *)key; diff --git a/libavutil/dict.h b/libavutil/dict.h index 0d1afc6c64..a957b48bf3 100644 --- a/libavutil/dict.h +++ b/libavutil/dict.h @@ -75,6 +75,7 @@ #define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no delimiter is added, the strings are simply concatenated. */ #define AV_DICT_MULTIKEY 64 /**< Allow to store several equal keys in the dictionary */ +#define AV_DICT_DEDUP 128 /**< If inserting a value that already exists for a key, do nothing. Only relevant with AV_DICT_MULTIKEY. */ typedef struct AVDictionaryEntry { char *key; -- 2.37.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH 2/3] lavf/metadata: support duplicate keys in ff_metadata_conv 2022-08-24 23:51 [FFmpeg-devel] [PATCH 1/3] lavu/dict: add AV_DICT_DEDUP rcombs @ 2022-08-24 23:51 ` rcombs 0 siblings, 0 replies; 4+ messages in thread From: rcombs @ 2022-08-24 23:51 UTC (permalink / raw) To: ffmpeg-devel --- libavformat/metadata.c | 2 +- tests/ref/fate/cover-art-aiff-id3v2-remux | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavformat/metadata.c b/libavformat/metadata.c index b9b6de7972..2a1ffc69e7 100644 --- a/libavformat/metadata.c +++ b/libavformat/metadata.c @@ -50,7 +50,7 @@ void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, key = dc->native; break; } - av_dict_set(&dst, key, mtag->value, 0); + av_dict_set(&dst, key, mtag->value, AV_DICT_MULTIKEY | AV_DICT_DEDUP); } av_dict_free(pm); *pm = dst; diff --git a/tests/ref/fate/cover-art-aiff-id3v2-remux b/tests/ref/fate/cover-art-aiff-id3v2-remux index 3ca2855eb8..2eac5f8d9c 100644 --- a/tests/ref/fate/cover-art-aiff-id3v2-remux +++ b/tests/ref/fate/cover-art-aiff-id3v2-remux @@ -67,10 +67,10 @@ TAG:title=third TAG:comment=Conductor [/STREAM] [FORMAT] -TAG:artist=Мельница +TAG:title=Дороги TAG:RATING=0 TAG:album=Ангелофрения -TAG:title=Дороги +TAG:artist=Мельница TAG:tracktotal=11 TAG:totaltracks=11 TAG:genre=Folk -- 2.37.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-25 0:27 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-08-25 0:27 [FFmpeg-devel] [PATCH 1/3] lavu/dict: add AV_DICT_DEDUP rcombs 2022-08-25 0:27 ` [FFmpeg-devel] [PATCH 2/3] lavf/metadata: support duplicate keys in ff_metadata_conv rcombs 2022-08-25 0:27 ` [FFmpeg-devel] [PATCH 3/3] lavf/id3v2dec: support multiple values and TIPL frames rcombs -- strict thread matches above, loose matches on Subject: below -- 2022-08-24 23:51 [FFmpeg-devel] [PATCH 1/3] lavu/dict: add AV_DICT_DEDUP rcombs 2022-08-24 23:51 ` [FFmpeg-devel] [PATCH 2/3] lavf/metadata: support duplicate keys in ff_metadata_conv rcombs
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git