[FFmpeg-devel] [PATCH] Fix ID3v1 tags in mp3 files
James Darnley
james.darnley
Mon Jul 5 21:37:44 CEST 2010
On 3 July 2010 00:44, James Darnley <james.darnley at gmail.com> wrote:
> This patch changes what keys are searched for.
This wasn't very good, it broke tags on mp2 files. As I see it, there
are two other ways to do this. Use the id3v2 conversion table for mp2
files. Otherwise change the strings looked for based on the output
format. See the two attached files.
-------------- next part --------------
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 5291fe3..aa93af5 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -118,7 +118,7 @@ OBJS-$(CONFIG_MMF_DEMUXER) += mmf.o raw.o
OBJS-$(CONFIG_MMF_MUXER) += mmf.o riff.o
OBJS-$(CONFIG_MOV_DEMUXER) += mov.o riff.o isom.o
OBJS-$(CONFIG_MOV_MUXER) += movenc.o riff.o isom.o avc.o movenchint.o
-OBJS-$(CONFIG_MP2_MUXER) += mp3.o id3v1.o
+OBJS-$(CONFIG_MP2_MUXER) += mp3.o id3v1.o id3v2.o
OBJS-$(CONFIG_MP3_DEMUXER) += mp3.o id3v1.o id3v2.o
OBJS-$(CONFIG_MP3_MUXER) += mp3.o id3v1.o id3v2.o
OBJS-$(CONFIG_MPC_DEMUXER) += mpc.o id3v1.o id3v2.o apetag.o
diff --git a/libavformat/mp3.c b/libavformat/mp3.c
index bdb2e4e..11ce59c 100644
--- a/libavformat/mp3.c
+++ b/libavformat/mp3.c
@@ -214,18 +214,18 @@ static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
buf[0] = 'T';
buf[1] = 'A';
buf[2] = 'G';
- count += id3v1_set_string(s, "title", buf + 3, 30);
- count += id3v1_set_string(s, "author", buf + 33, 30);
- count += id3v1_set_string(s, "album", buf + 63, 30);
- count += id3v1_set_string(s, "date", buf + 93, 4);
+ count += id3v1_set_string(s, "TIT2", buf + 3, 30); //title
+ count += id3v1_set_string(s, "TPE1", buf + 33, 30); //author|artist
+ count += id3v1_set_string(s, "TALB", buf + 63, 30); //album
+ count += id3v1_set_string(s, "TDRL", buf + 93, 4); //date
count += id3v1_set_string(s, "comment", buf + 97, 30);
- if ((tag = av_metadata_get(s->metadata, "track", NULL, 0))) {
+ if ((tag = av_metadata_get(s->metadata, "TRCK", NULL, 0))) { //track
buf[125] = 0;
buf[126] = atoi(tag->value);
count++;
}
buf[127] = 0xFF; /* default to unknown genre */
- if ((tag = av_metadata_get(s->metadata, "genre", NULL, 0))) {
+ if ((tag = av_metadata_get(s->metadata, "TCON", NULL, 0))) { //genre
for(i = 0; i <= ID3v1_GENRE_MAX; i++) {
if (!strcasecmp(tag->value, ff_id3v1_genre_str[i])) {
buf[127] = i;
@@ -290,6 +290,7 @@ AVOutputFormat mp2_muxer = {
NULL,
mp3_write_packet,
mp3_write_trailer,
+ .metadata_conv = ff_id3v2_metadata_conv,
};
#endif
-------------- next part --------------
diff --git a/libavformat/mp3.c b/libavformat/mp3.c
index bdb2e4e..589574d 100644
--- a/libavformat/mp3.c
+++ b/libavformat/mp3.c
@@ -209,23 +209,40 @@ static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
{
AVMetadataTag *tag;
int i, count = 0;
+ const char *title, *artist, *album, *date, *track, *genre;
+
+ if (!strcmp("mp3", s->oformat->name)) {
+ title = "TIT2";
+ artist = "TPE1";
+ album = "TALB";
+ date = "TDRL";
+ track = "TRCK";
+ genre = "TCON";
+ } else {
+ title = "title";
+ artist = "artist";
+ album = "album";
+ date = "date";
+ track = "track";
+ genre = "genre";
+ }
memset(buf, 0, ID3v1_TAG_SIZE); /* fail safe */
buf[0] = 'T';
buf[1] = 'A';
buf[2] = 'G';
- count += id3v1_set_string(s, "title", buf + 3, 30);
- count += id3v1_set_string(s, "author", buf + 33, 30);
- count += id3v1_set_string(s, "album", buf + 63, 30);
- count += id3v1_set_string(s, "date", buf + 93, 4);
+ count += id3v1_set_string(s, title, buf + 3, 30);
+ count += id3v1_set_string(s, artist, buf + 33, 30);
+ count += id3v1_set_string(s, album, buf + 63, 30);
+ count += id3v1_set_string(s, date, buf + 93, 4);
count += id3v1_set_string(s, "comment", buf + 97, 30);
- if ((tag = av_metadata_get(s->metadata, "track", NULL, 0))) {
+ if ((tag = av_metadata_get(s->metadata, track, NULL, 0))) {
buf[125] = 0;
buf[126] = atoi(tag->value);
count++;
}
buf[127] = 0xFF; /* default to unknown genre */
- if ((tag = av_metadata_get(s->metadata, "genre", NULL, 0))) {
+ if ((tag = av_metadata_get(s->metadata, genre, NULL, 0))) {
for(i = 0; i <= ID3v1_GENRE_MAX; i++) {
if (!strcasecmp(tag->value, ff_id3v1_genre_str[i])) {
buf[127] = i;
More information about the ffmpeg-devel
mailing list