[PATCH] ignore additional id3v2 tags at the beginning of mp3 =
David Byron none
dbyron
Thu Sep 2 17:06:09 CEST 2010
files=0A=
=0A=
---=0A=
Changelog | 1 +=0A=
libavformat/id3v2.c | 26 ++++++++++++++++++++++++++=0A=
libavformat/id3v2.h | 10 ++++++++++=0A=
libavformat/mp3.c | 7 +++++++=0A=
4 files changed, 44 insertions(+), 0 deletions(-)=0A=
=0A=
diff --git a/Changelog b/Changelog=0A=
index 59d4339..7f3e1ca 100644=0A=
--- a/Changelog=0A=
+++ b/Changelog=0A=
@@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.=0A=
=0A=
version <next>:=0A=
=0A=
+- skip additional id3v2 tags at the beginning of mp3 files=0A=
- WebM support in Matroska de/muxer=0A=
- low overhead Ogg muxing=0A=
- MMS-TCP support=0A=
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c=0A=
index f2515d5..c9c586b 100644=0A=
--- a/libavformat/id3v2.c=0A=
+++ b/libavformat/id3v2.c=0A=
@@ -69,6 +69,32 @@ void ff_id3v2_read(AVFormatContext *s, const char =
*magic)=0A=
}=0A=
}=0A=
=0A=
+int ff_id3v2_skip(AVFormatContext *s, const char *magic)=0A=
+{=0A=
+ int len, ret;=0A=
+ uint8_t buf[ID3v2_HEADER_SIZE];=0A=
+ int64_t off;=0A=
+=0A=
+ /* save the current offset in case there's nothing to skip */=0A=
+ off =3D url_ftell(s->pb);=0A=
+=0A=
+ ret =3D get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);=0A=
+ if ((ret =3D=3D ID3v2_HEADER_SIZE) && ff_id3v2_match(buf, magic)) {=0A=
+ len =3D ((buf[6] & 0x7f) << 21) |=0A=
+ ((buf[7] & 0x7f) << 14) |=0A=
+ ((buf[8] & 0x7f) << 7) |=0A=
+ (buf[9] & 0x7f);=0A=
+ url_fskip(s->pb,len);=0A=
+ return 1;=0A=
+ }=0A=
+=0A=
+ /* Either we didn't get enough bytes for an ID3v2=0A=
+ header, or what we got wasn't a valid ID3v2 header */=0A=
+ url_fseek(s->pb, off, SEEK_SET);=0A=
+=0A=
+ return 0;=0A=
+}=0A=
+=0A=
static unsigned int get_size(ByteIOContext *s, int len)=0A=
{=0A=
int v =3D 0;=0A=
diff --git a/libavformat/id3v2.h b/libavformat/id3v2.h=0A=
index 48373bb..f4f8c18 100644=0A=
--- a/libavformat/id3v2.h=0A=
+++ b/libavformat/id3v2.h=0A=
@@ -59,6 +59,16 @@ void ff_id3v2_parse(AVFormatContext *s, int len, =
uint8_t version, uint8_t flags)=0A=
*/=0A=
void ff_id3v2_read(AVFormatContext *s, const char *magic);=0A=
=0A=
+/**=0A=
+ * Skip an ID3v2 tag without reading it. Useful for=0A=
+ * skipping additional id3v2 frames if there's more than=0A=
+ * one.=0A=
+ *=0A=
+ * @retval 0 no id3v2 frame to skip=0A=
+ * @retval 1 skipped id3v2 frame=0A=
+ */=0A=
+int ff_id3v2_skip(AVFormatContext *s, const char *magic);=0A=
+=0A=
extern const AVMetadataConv ff_id3v2_metadata_conv[];=0A=
=0A=
/**=0A=
diff --git a/libavformat/mp3.c b/libavformat/mp3.c=0A=
index c1622a3..1f462fc 100644=0A=
--- a/libavformat/mp3.c=0A=
+++ b/libavformat/mp3.c=0A=
@@ -157,6 +157,13 @@ static int mp3_read_header(AVFormatContext *s,=0A=
av_set_pts_info(st, 64, 1, 14112000);=0A=
=0A=
ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);=0A=
+=0A=
+ /* skip any extra id3v2 frames that may be present since=0A=
+ they may contain data that looks like an mpeg frame */=0A=
+ while (ff_id3v2_skip(s, ID3v2_DEFAULT_MAGIC))=0A=
+ av_log(s,AV_LOG_VERBOSE,"skipping additional id3v2 tag in =
\"%s\"\n",=0A=
+ s->filename);=0A=
+=0A=
off =3D url_ftell(s->pb);=0A=
=0A=
if (!av_metadata_get(s->metadata, "", NULL, =
AV_METADATA_IGNORE_SUFFIX))=0A=
-- =0A=
1.6.0.4=0A=
=0A=
------=_NextPart_000_0117_01CB4E83.D0B95400--
More information about the ffmpeg-devel
mailing list