[FFmpeg-devel] [PATCH] MOV muxer : Add SoundDescriptionV2 support

Baptiste Coudurier baptiste.coudurier
Sat Nov 28 09:03:47 CET 2009


Hi,

On 11/27/09 11:41 PM, Jai Menon wrote:
> Hi,
>
> This is the current situation :
>
> [jai at outrax ffbuild]$ ./ffmpeg -i "Nine Inch Nails - Lights In The Sky.wav"
> FFmpeg version git-svn-r20620, Copyright (c) 2000-2009 Fabrice Bellard, et al.
> [...]
> Input #0, wav, from 'Nine Inch Nails - Lights In The Sky.wav':
>    Duration: 00:03:29.97, bitrate: 4608 kb/s
>      Stream #0.0: Audio: pcm_s24le, 96000 Hz, 2 channels, s32, 4608 kb/s
>
>
> [jai at outrax ffbuild]$ ./ffmpeg -i "Nine Inch Nails - Lights In The Sky.wav" -acodec copy remuxed.mov
> FFmpeg version git-svn-r20620, Copyright (c) 2000-2009 Fabrice Bellard, et al.
> [...]
> Input #0, wav, from 'Nine Inch Nails - Lights In The Sky.wav':
>    Duration: 00:03:29.97, bitrate: 4608 kb/s
>      Stream #0.0: Audio: pcm_s24le, 96000 Hz, 2 channels, s32, 4608 kb/s
> Output #0, mov, to 'remuxed.mov':
>      Stream #0.0: Audio: pcm_s24le, 96000 Hz, 2 channels, 4608 kb/s
> Stream mapping:
>    Stream #0.0 ->  #0.0
> Press [q] to stop encoding
> size=  118215kB time=209.95 bitrate=4612.5kbits/s
> video:0kB audio:118099kB global headers:0kB muxing overhead 0.098321%
>
>
> [jai at outrax ffbuild]$ ./ffmpeg -i remuxed.mov
> FFmpeg version git-svn-r20620, Copyright (c) 2000-2009 Fabrice Bellard, et al.
> [...]
> Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'remuxed.mov':
>    Duration: 00:03:29.95, start: 0.000000, bitrate: 4612 kb/s
>      Stream #0.0(eng): Audio: pcm_s24le, 30464 Hz, 2 channels, s32, 1462 kb/s
>                                          ^^^^^
>
> Needless to say, the output is broken and there isn't any warning too.
> Attached patch adds support for writing an extended sound desc which
> allows for higher samplerates. The output has been tested against
> Quicktime for all samples I have.  Ideally, I'd hope for the patch to
> be applied but if nothing comes of that, I'd suggest that we atleast
> error out if samplerate>  UINT16_MAX.

Yes, and a warning for all other formats than mov is welcome too.

> sounddescv2.patch
>
>
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index ac6378c..36b156e 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -405,13 +405,21 @@ static int mov_write_glbl_tag(ByteIOContext *pb, MOVTrack *track)
>   static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack *track)
>   {
>       int64_t pos = url_ftell(pb);
> -    int version = track->mode == MODE_MOV&&
> +    int version;
> +
> +    if (track->mode == MODE_MOV&&
>           (track->audio_vbr ||
>            track->enc->codec_id == CODEC_ID_PCM_S32LE ||
> -         track->enc->codec_id == CODEC_ID_PCM_S24LE);
> +         track->enc->codec_id == CODEC_ID_PCM_S24LE)) {
> +        if (track->timescale>  UINT16_MAX)
> +            version = 2;

The stsd v2 must always be used when timescale > UINT16_MAX regardless 
of codec.

> +        else version = 1;
> +    }
>
>       put_be32(pb, 0); /* size */
> -    put_le32(pb, track->tag); // store it byteswapped
> +    if (version == 2)
> +        put_le32(pb, AV_RL32("lpcm"));

Technically all codecs can use stsd v2, I have an ALAC sample using stsd 
v2 since sample rate is 192000. It was just for test :)

> +    else put_le32(pb, track->tag); // store it byteswapped
>       put_be32(pb, 0); /* Reserved */
>       put_be16(pb, 0); /* Reserved */
>       put_be16(pb, 1); /* Data-reference index, XXX  == 1 */
> @@ -444,6 +452,15 @@ static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack *track)
>           put_be32(pb, track->sampleSize / track->enc->channels); /* Bytes per packet */
>           put_be32(pb, track->sampleSize); /* Bytes per frame */
>           put_be32(pb, 2); /* Bytes per sample */
> +    } else if (version == 2) {
> +        put_be32(pb, 72);

Please split it according to specs:

    SInt16     always3;
    SInt16     always16;
    SInt16     alwaysMinus2;
    SInt16     always0;
    UInt32     always65536;
    UInt32     sizeOfStructOnly;

[...]

-- 
Baptiste COUDURIER
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
FFmpeg maintainer                                  http://www.ffmpeg.org



More information about the ffmpeg-devel mailing list