[FFmpeg-devel] [PATCH] Handle ID3v1 tag while decoding mp[123] frames

Clément Bœsch ubitux
Fri Jan 7 02:40:14 CET 2011


Hi,

I have a lot of mp3 with id3v1 tag at the end of the file; here is a
random one:
http://ccmixter.org/content/Ghost_k/Ghost_k_-_Stop_(blue_mix).mp3

While reading this last frame, the header is not recognized as a mpeg
one so the frame read basically fails. If I'm not wrong, it also tries
byte per byte to find a new mpeg header (since id3v1 header is 128 bytes
it should be around 124 times).

So I attached a patch to just ignore this frame. I'm not sure this is the
correct place to do so (maybe there is some stream end offset mark to
explicit the end of the file before the tag?), and I'm also not sure about
the way I made av_read_frame ignoring this packet. Do I also need to
update the data_size (function argument) value?

Regards,

-- 
Cl?ment B.
-------------- next part --------------
>From 6b291325a850f098568afcac915aeed11a2cc219 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Fri, 7 Jan 2011 02:27:25 +0100
Subject: [PATCH] Handle ID3v1 tag while decoding mp[123] frames

---
 libavcodec/mpegaudiodec.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c
index 769be89..fe84214 100644
--- a/libavcodec/mpegaudiodec.c
+++ b/libavcodec/mpegaudiodec.c
@@ -27,6 +27,7 @@
 #include "avcodec.h"
 #include "get_bits.h"
 #include "dsputil.h"
+#include "libavformat/id3v1.h"
 
 /*
  * TODO:
@@ -2043,6 +2044,14 @@ static int decode_frame(AVCodecContext * avctx,
 
     header = AV_RB32(buf);
     if(ff_mpa_check_header(header) < 0){
+
+        if (buf_size == ID3v1_TAG_SIZE
+            && buf[0] == 'T' && buf[1] == 'A' && buf[2] == 'G') {
+            avpkt->data += ID3v1_TAG_SIZE;
+            avpkt->size = 0;
+            return 0;
+        }
+
         av_log(avctx, AV_LOG_ERROR, "Header missing\n");
         return -1;
     }
-- 
1.7.3.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20110107/be2d9ef7/attachment.pgp>



More information about the ffmpeg-devel mailing list