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/dict.h"
26 /* See Genre List at http://id3.org/id3v2.3.0 */
27 const char * const ff_id3v1_genre_str
[ID3v1_GENRE_MAX
+ 1] = {
61 [33] = "Instrumental",
74 [46] = "Instrumental Pop",
75 [47] = "Instrumental Rock",
79 [51] = "Techno-Industrial",
84 [56] = "Southern Rock",
89 [61] = "Christian Rap",
92 [64] = "Native American",
95 [67] = "Psychadelic", /* sic, the misspelling is used in the specification */
106 [78] = "Rock & Roll",
110 [82] = "National Folk",
112 [84] = "Fast Fusion",
119 [91] = "Gothic Rock",
120 [92] = "Progressive Rock",
121 [93] = "Psychedelic Rock",
122 [94] = "Symphonic Rock",
126 [98] = "Easy Listening",
132 [104] = "Chamber Music",
135 [107] = "Booty Bass",
137 [109] = "Porn Groove",
145 [117] = "Power Ballad",
146 [118] = "Rhythmic Soul",
152 [124] = "Euro-House",
153 [125] = "Dance Hall",
155 [127] = "Drum & Bass",
156 [128] = "Club-House",
162 [134] = "Polsk Punk",
164 [136] = "Christian Gangsta",
165 [137] = "Heavy Metal",
166 [138] = "Black Metal",
168 [140] = "Contemporary Christian",
169 [141] = "Christian Rock",
172 [144] = "Thrash Metal",
178 static void get_string(AVFormatContext
*s
, const char *key
,
179 const uint8_t *buf
, int buf_size
)
185 for(i
= 0; i
< buf_size
; i
++) {
189 if ((q
- str
) >= sizeof(str
) - 1)
196 av_dict_set(&s
->metadata
, key
, str
, 0);
202 * @param buf ID3v1_TAG_SIZE long buffer containing the tag
204 static int parse_tag(AVFormatContext
*s
, const uint8_t *buf
)
208 if (!(buf
[0] == 'T' &&
212 get_string(s
, "title", buf
+ 3, 30);
213 get_string(s
, "artist", buf
+ 33, 30);
214 get_string(s
, "album", buf
+ 63, 30);
215 get_string(s
, "date", buf
+ 93, 4);
216 get_string(s
, "comment", buf
+ 97, 30);
217 if (buf
[125] == 0 && buf
[126] != 0) {
218 av_dict_set_int(&s
->metadata
, "track", buf
[126], 0);
221 if (genre
<= ID3v1_GENRE_MAX
)
222 av_dict_set(&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
);