Commit b182eeb0 authored by Aurelien Jacobs's avatar Aurelien Jacobs

use new metadata API in the mp3 muxer

Originally committed as revision 16954 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 9d98535c
...@@ -526,35 +526,44 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -526,35 +526,44 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
} }
#if CONFIG_MP2_MUXER || CONFIG_MP3_MUXER #if CONFIG_MP2_MUXER || CONFIG_MP3_MUXER
static void id3v1_create_tag(AVFormatContext *s, uint8_t *buf) static int id3v1_set_string(AVFormatContext *s, const char *key,
uint8_t *buf, int buf_size)
{ {
int v, i; AVMetadataTag *tag;
if ((tag = av_metadata_get(s->metadata, key, NULL, 0)))
strncpy(buf, tag->value, buf_size);
return !!tag;
}
static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf)
{
AVMetadataTag *tag;
int i, count = 0;
memset(buf, 0, ID3v1_TAG_SIZE); /* fail safe */ memset(buf, 0, ID3v1_TAG_SIZE); /* fail safe */
buf[0] = 'T'; buf[0] = 'T';
buf[1] = 'A'; buf[1] = 'A';
buf[2] = 'G'; buf[2] = 'G';
strncpy(buf + 3, s->title, 30); count += id3v1_set_string(s, "title", buf + 3, 30);
strncpy(buf + 33, s->author, 30); count += id3v1_set_string(s, "author", buf + 33, 30);
strncpy(buf + 63, s->album, 30); count += id3v1_set_string(s, "album", buf + 63, 30);
v = s->year; count += id3v1_set_string(s, "year", buf + 93, 4);
if (v > 0) { count += id3v1_set_string(s, "comment", buf + 97, 30);
for(i = 0;i < 4; i++) { if ((tag = av_metadata_get(s->metadata, "track", NULL, 0))) {
buf[96 - i] = '0' + (v % 10);
v = v / 10;
}
}
strncpy(buf + 97, s->comment, 30);
if (s->track != 0) {
buf[125] = 0; buf[125] = 0;
buf[126] = s->track; buf[126] = atoi(tag->value);
count++;
} }
if ((tag = av_metadata_get(s->metadata, "genre", NULL, 0))) {
for(i = 0; i <= ID3v1_GENRE_MAX; i++) { for(i = 0; i <= ID3v1_GENRE_MAX; i++) {
if (!strcasecmp(s->genre, id3v1_genre_str[i])) { if (!strcasecmp(tag->value, id3v1_genre_str[i])) {
buf[127] = i; buf[127] = i;
count++;
break; break;
} }
} }
}
return count;
} }
/* simple formats */ /* simple formats */
...@@ -584,22 +593,24 @@ static void id3v2_put_ttag(AVFormatContext *s, const char *string, uint32_t tag) ...@@ -584,22 +593,24 @@ static void id3v2_put_ttag(AVFormatContext *s, const char *string, uint32_t tag)
static int mp3_write_header(struct AVFormatContext *s) static int mp3_write_header(struct AVFormatContext *s)
{ {
AVMetadataTag *title, *author, *album, *genre, *copyright, *track, *year;
int totlen = 0; int totlen = 0;
char tracktxt[10];
char yeartxt[10]; title = av_metadata_get(s->metadata, "title", NULL, 0);
author = av_metadata_get(s->metadata, "author", NULL, 0);
if(s->track) album = av_metadata_get(s->metadata, "album", NULL, 0);
snprintf(tracktxt, sizeof(tracktxt), "%d", s->track); genre = av_metadata_get(s->metadata, "genre", NULL, 0);
if(s->year) copyright = av_metadata_get(s->metadata, "copyright", NULL, 0);
snprintf( yeartxt, sizeof(yeartxt) , "%d", s->year ); track = av_metadata_get(s->metadata, "track", NULL, 0);
year = av_metadata_get(s->metadata, "year", NULL, 0);
if(s->title[0]) totlen += 11 + strlen(s->title);
if(s->author[0]) totlen += 11 + strlen(s->author); if(title) totlen += 11 + strlen(title->value);
if(s->album[0]) totlen += 11 + strlen(s->album); if(author) totlen += 11 + strlen(author->value);
if(s->genre[0]) totlen += 11 + strlen(s->genre); if(album) totlen += 11 + strlen(album->value);
if(s->copyright[0]) totlen += 11 + strlen(s->copyright); if(genre) totlen += 11 + strlen(genre->value);
if(s->track) totlen += 11 + strlen(tracktxt); if(copyright) totlen += 11 + strlen(copyright->value);
if(s->year) totlen += 11 + strlen(yeartxt); if(track) totlen += 11 + strlen(track->value);
if(year) totlen += 11 + strlen(year->value);
if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
totlen += strlen(LIBAVFORMAT_IDENT) + 11; totlen += strlen(LIBAVFORMAT_IDENT) + 11;
...@@ -612,13 +623,13 @@ static int mp3_write_header(struct AVFormatContext *s) ...@@ -612,13 +623,13 @@ static int mp3_write_header(struct AVFormatContext *s)
id3v2_put_size(s, totlen); id3v2_put_size(s, totlen);
if(s->title[0]) id3v2_put_ttag(s, s->title, MKBETAG('T', 'I', 'T', '2')); if(title) id3v2_put_ttag(s, title->value, MKBETAG('T', 'I', 'T', '2'));
if(s->author[0]) id3v2_put_ttag(s, s->author, MKBETAG('T', 'P', 'E', '1')); if(author) id3v2_put_ttag(s, author->value, MKBETAG('T', 'P', 'E', '1'));
if(s->album[0]) id3v2_put_ttag(s, s->album, MKBETAG('T', 'A', 'L', 'B')); if(album) id3v2_put_ttag(s, album->value, MKBETAG('T', 'A', 'L', 'B'));
if(s->genre[0]) id3v2_put_ttag(s, s->genre, MKBETAG('T', 'C', 'O', 'N')); if(genre) id3v2_put_ttag(s, genre->value, MKBETAG('T', 'C', 'O', 'N'));
if(s->copyright[0]) id3v2_put_ttag(s, s->copyright, MKBETAG('T', 'C', 'O', 'P')); if(copyright) id3v2_put_ttag(s, copyright->value, MKBETAG('T', 'C', 'O', 'P'));
if(s->track) id3v2_put_ttag(s, tracktxt, MKBETAG('T', 'R', 'C', 'K')); if(track) id3v2_put_ttag(s, track->value, MKBETAG('T', 'R', 'C', 'K'));
if(s->year) id3v2_put_ttag(s, yeartxt, MKBETAG('T', 'Y', 'E', 'R')); if(year) id3v2_put_ttag(s, year->value, MKBETAG('T', 'Y', 'E', 'R'));
if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT))
id3v2_put_ttag(s, LIBAVFORMAT_IDENT, MKBETAG('T', 'E', 'N', 'C')); id3v2_put_ttag(s, LIBAVFORMAT_IDENT, MKBETAG('T', 'E', 'N', 'C'));
return 0; return 0;
...@@ -636,8 +647,7 @@ static int mp3_write_trailer(struct AVFormatContext *s) ...@@ -636,8 +647,7 @@ static int mp3_write_trailer(struct AVFormatContext *s)
uint8_t buf[ID3v1_TAG_SIZE]; uint8_t buf[ID3v1_TAG_SIZE];
/* write the id3v1 tag */ /* write the id3v1 tag */
if (s->title[0] != '\0') { if (id3v1_create_tag(s, buf) > 0) {
id3v1_create_tag(s, buf);
put_buffer(s->pb, buf, ID3v1_TAG_SIZE); put_buffer(s->pb, buf, ID3v1_TAG_SIZE);
put_flush_packet(s->pb); put_flush_packet(s->pb);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment