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"
24 #include "libavutil/avstring.h"
26 const char * const ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1] = {
60 [33] = "Instrumental",
73 [46] = "Instrumental Pop",
74 [47] = "Instrumental Rock",
78 [51] = "Techno-Industrial",
83 [56] = "Southern Rock",
88 [61] = "Christian Rap",
91 [64] = "Native American",
105 [78] = "Rock & Roll",
109 [82] = "National Folk",
111 [84] = "Fast Fusion",
118 [91] = "Gothic Rock",
119 [92] = "Progressive Rock",
120 [93] = "Psychedelic Rock",
121 [94] = "Symphonic Rock",
125 [98] = "Easy Listening",
131 [104] = "Chamber Music",
134 [107] = "Booty Bass",
136 [109] = "Porn Groove",
144 [117] = "Power Ballad",
145 [118] = "Rhythmic Soul",
151 [124] = "Euro-House",
152 [125] = "Dance Hall",
154 [127] = "Drum & Bass",
155 [128] = "Club-House",
161 [134] = "Polsk Punk",
163 [136] = "Christian Gangsta",
164 [137] = "Heavy Metal",
165 [138] = "Black Metal",
167 [140] = "Contemporary Christian",
168 [141] = "Christian Rock",
171 [144] = "Thrash Metal",
177 static void get_string(AVFormatContext *s, const char *key,
178 const uint8_t *buf, int buf_size)
184 for(i = 0; i < buf_size; i++) {
188 if ((q - str) >= sizeof(str) - 1)
195 av_metadata_set2(&s->metadata, key, str, 0);
201 * @param buf ID3v1_TAG_SIZE long buffer containing the tag
203 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 av_metadata_set2(&s->metadata, "track", av_d2str(buf[126]), AV_METADATA_DONT_STRDUP_VAL);
219 if (genre <= ID3v1_GENRE_MAX)
220 av_metadata_set2(&s->metadata, "genre", ff_id3v1_genre_str[genre], 0);
224 void ff_id3v1_read(AVFormatContext *s)
227 uint8_t buf[ID3v1_TAG_SIZE];
229 if (!url_is_streamed(s->pb)) {
230 /* XXX: change that */
231 filesize = url_fsize(s->pb);
232 if (filesize > 128) {
233 url_fseek(s->pb, filesize - 128, SEEK_SET);
234 ret = get_buffer(s->pb, buf, ID3v1_TAG_SIZE);
235 if (ret == ID3v1_TAG_SIZE) {
238 url_fseek(s->pb, 0, SEEK_SET);