[Ffmpeg-devel] [PATCH] mov stsd audio version 2

Corey Hickey bugfood-ml
Fri Mar 3 23:39:45 CET 2006


Baptiste COUDURIER wrote:
> Hi,
> 
> Here is a patch to support stsd audio version 2, found in apple h264
> trailers.
> 
> Sample rate is supposed to be a float64, according to the specs. Im not
> sure at all that reading it that way is correct.
> 
> Unfortunately, AAC is 5:1 in apple's trailers and it seems it is decoded
> right by faad in ffmpeg. Anybody knows why, or knows a fix ?
> 
> 
> 
> ------------------------------------------------------------------------
> 
> Index: libavformat/mov.c
> ===================================================================
> RCS file: /cvsroot/ffmpeg/ffmpeg/libavformat/mov.c,v
> retrieving revision 1.117
> diff -u -p -r1.117 mov.c
> --- libavformat/mov.c	22 Feb 2006 23:46:20 -0000	1.117
> +++ libavformat/mov.c	1 Mar 2006 11:56:07 -0000
> @@ -1063,6 +1083,15 @@ static int mov_read_stsd(MOVContext *c, 
>                  get_be32(pb); /* bytes per packet */
>                  get_be32(pb); /* bytes per frame */
>                  get_be32(pb); /* bytes per sample */
> +            } else if(version==2) {
> +                get_be32(pb); /* sizeof struct only */
> +                st->codec->sample_rate = get_be64(pb); /* float 64 ? */

No, I don't think this is correct. For example, 48000 Hz audio is
0x40E7700000000000. get_be64() uses so many left shifts the result is 0,
but if it were read completely that way it would be 4676829883349860352.

I'm not sure how, but if the chars were read into a double
(endian-switched if necessary) and then cast to int it should work
properly. Reading the value into a double is the hard part, though,
since you can't use bitwise operators (and, even so, is a double
universally 64-bit?). The conversion might have to be done manually.

So far, the only files with the v2 atom I've seen have AAC audio and the
samplerate stored in an esds atom. That's how mplayer gets by without
parsing the samplerate correctly -- the esds is passed to libfaad. I
don't know if that holds true for ffmpeg. It might be ok to not parse
the samplerate from the stsd and try to get it from the esds instead.

By the way, thanks a bunch for the v2 spec -- I found out that some of
my guesses were incorrect. I'll be sending a patch for mplayer after I
get the samplerate issue resolved (or give up).

-Corey





More information about the ffmpeg-devel mailing list