3 * Copyright (c) 2003 Fabrice Bellard
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavcodec/avcodec.h"
25 const char * const ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1] = {
59 [33] = "Instrumental",
72 [46] = "Instrumental Pop",
73 [47] = "Instrumental Rock",
77 [51] = "Techno-Industrial",
82 [56] = "Southern Rock",
87 [61] = "Christian Rap",
90 [64] = "Native American",
104 [78] = "Rock & Roll",
108 [82] = "National Folk",
110 [84] = "Fast Fusion",
117 [91] = "Gothic Rock",
118 [92] = "Progressive Rock",
119 [93] = "Psychedelic Rock",
120 [94] = "Symphonic Rock",
124 [98] = "Easy Listening",
130 [104] = "Chamber Music",
133 [107] = "Booty Bass",
135 [109] = "Porn Groove",
143 [117] = "Power Ballad",
144 [118] = "Rhythmic Soul",
150 [124] = "Euro-House",
151 [125] = "Dance Hall",
153 [127] = "Drum & Bass",
154 [128] = "Club-House",
160 [134] = "Polsk Punk",
162 [136] = "Christian Gangsta",
163 [137] = "Heavy Metal",
164 [138] = "Black Metal",
166 [140] = "Contemporary Christian",
167 [141] = "Christian Rock",
170 [144] = "Thrash Metal",
176 static void get_string(AVFormatContext *s, const char *key,
177 const uint8_t *buf, int buf_size)
183 for(i = 0; i < buf_size; i++) {
187 if ((q - str) >= sizeof(str) - 1)
194 av_metadata_set2(&s->metadata, key, str, 0);
200 * @param buf ID3v1_TAG_SIZE long buffer containing the tag
202 static int parse_tag(AVFormatContext *s, const uint8_t *buf)
207 if (!(buf[0] == 'T' &&
211 get_string(s, "title", buf + 3, 30);
212 get_string(s, "artist", buf + 33, 30);
213 get_string(s, "album", buf + 63, 30);
214 get_string(s, "date", buf + 93, 4);
215 get_string(s, "comment", buf + 97, 30);
216 if (buf[125] == 0 && buf[126] != 0) {
217 snprintf(str, sizeof(str), "%d", buf[126]);
218 av_metadata_set2(&s->metadata, "track", str, 0);
221 if (genre <= ID3v1_GENRE_MAX)
222 av_metadata_set2(&s->metadata, "genre", ff_id3v1_genre_str[genre], 0);
226 void ff_id3v1_read(AVFormatContext *s)
229 uint8_t buf[ID3v1_TAG_SIZE];
230 int64_t filesize, position = avio_tell(s->pb);
232 if (s->pb->seekable) {
233 /* XXX: change that */
234 filesize = avio_size(s->pb);
235 if (filesize > 128) {
236 avio_seek(s->pb, filesize - 128, SEEK_SET);
237 ret = avio_read(s->pb, buf, ID3v1_TAG_SIZE);
238 if (ret == ID3v1_TAG_SIZE) {
241 avio_seek(s->pb, position, SEEK_SET);