[FFmpeg-devel] [PATCH 7/8] id3v2: merge TYER/TDAT/TIME frames to "date" tag on conversion.

Anton Khirnov wyskas
Wed Jun 2 15:16:04 CEST 2010


---
 libavformat/id3v2.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 4831501..781ae8a 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -232,6 +232,33 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
     url_fskip(s->pb, len);
 }
 
+static void conv2generic(AVMetadata **src, AVMetadata **dst)
+{
+    AVMetadataTag *t;
+    char date[17] = {0};      // YYYY-MM-DD hh:mm
+
+    if (!(t = av_metadata_get(*src, "TYER", NULL, AV_METADATA_MATCH_CASE)) ||
+        strlen(t->value) != 4)
+        return;
+    snprintf(date, 5, "%04d", atoi(t->value));
+    av_metadata_remove(src, &t);
+
+    if (!(t = av_metadata_get(*src, "TDAT", NULL, AV_METADATA_MATCH_CASE)) ||
+        strlen(t->value) != 4)
+        goto finish;
+    snprintf(date + 4, sizeof(date) - 4, "-%.2s-%.2s", t->value + 2, t->value);
+    av_metadata_remove(src, &t);
+
+    if (!(t = av_metadata_get(*src, "TIME", NULL, AV_METADATA_MATCH_CASE)) ||
+        strlen(t->value) != 4)
+        goto finish;
+    snprintf(date + 10, sizeof(date) - 10, " %.2s:%.2s", t->value, t->value + 2);
+
+finish:
+    if (date[0])
+        av_metadata_set2(dst, "date", date, 0);
+}
+
 static const AVMetadataConvTable id3v2_conv_table[] = {
     { "TALB", "album"},
     { "TAL",  "album"},
@@ -265,6 +292,7 @@ static const AVMetadataConvTable id3v2_conv_table[] = {
 
 const AVMetadataConv ff_id3v2_metadata_conv = {
     id3v2_conv_table,
+    .conv2generic = conv2generic
 };
 
 const char ff_id3v2_tags[][4] = {
-- 
1.7.1




More information about the ffmpeg-devel mailing list