[FFmpeg-devel] look for valid mpeg frame (was skip multiple id3v2 headers)

Michael Niedermayer michaelni
Thu Sep 23 23:10:26 CEST 2010


On Thu, Sep 23, 2010 at 11:26:25AM -0700, David Byron wrote:
> > > Is there a way to find out what subset of each packet is
> > > audio?  avcodec_decode_audio3 doesn't seem to help in
> > > this case as it returns -1 on
> > 
> > a patch for the mpeg audio decode frame code is welcome so
> > it searches for a valid frame header
> 
> Like this?  This gets avcodec_decode_audio3 to decode the mpeg frame in
> bad_id3v2_with_one_frame.mp3 posted earlier (with no change to the id3v2
> parsing code).
> 
> -DB

>  Changelog                 |    1 +
>  libavcodec/mpegaudiodec.c |   15 +++++++++------
>  2 files changed, 10 insertions(+), 6 deletions(-)
> 1d249b571ef18408e4ca3a663244641bb63ed9e8  0001-look-for-valid-mpeg-frames-when-decoding-instead-of.patch
> From fd284e2b1207cbd38be106871065b1a0b68b526a Mon Sep 17 00:00:00 2001
> From: David Byron <dbyron at UbuntuVM.(none)>
> Date: Thu, 23 Sep 2010 11:05:38 -0700
> Subject: [PATCH] look for valid mpeg frames when decoding instead of giving up if a packet doesn't begin with an mpeg frame
> 
> ---
>  Changelog                 |    1 +
>  libavcodec/mpegaudiodec.c |   15 +++++++++------
>  2 files changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/Changelog b/Changelog
> index 263fb74..e6b7ba6 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.
>  
>  version <next>:
>  
> +- look for valid mpeg frames when decoding
>  - read all id3v2 tags at the beginning of mp3 files
>  - WebM support in Matroska de/muxer
>  - low overhead Ogg muxing
> diff --git a/libavcodec/mpegaudiodec.c b/libavcodec/mpegaudiodec.c
> index 769be89..03a4f9e 100644
> --- a/libavcodec/mpegaudiodec.c
> +++ b/libavcodec/mpegaudiodec.c
> @@ -2038,14 +2038,17 @@ static int decode_frame(AVCodecContext * avctx,
>      int out_size;
>      OUT_INT *out_samples = data;
>  
> -    if(buf_size < HEADER_SIZE)
> -        return -1;
> -
> +    while (buf_size >= HEADER_SIZE) {
>      header = AV_RB32(buf);
> -    if(ff_mpa_check_header(header) < 0){
> -        av_log(avctx, AV_LOG_ERROR, "Header missing\n");
> -        return -1;
> +    if(ff_mpa_check_header(header) >= 0){
> +        break;
>      }

> +    buf++;
> +    buf_size--;
> +    }

buf_size is used later and this value does not look correct

newly added lines should be indented correctly

if the header is not where it should be an warning should be printed


> +
> +    if(buf_size < HEADER_SIZE)
> +        return -1;

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100923/abfa3d45/attachment.pgp>



More information about the ffmpeg-devel mailing list