[FFmpeg-devel] [PATCH] WAVEFORMATEXTENSIBLE support in the wav muxer

Michael Niedermayer michaelni
Mon Dec 29 14:15:27 CET 2008


On Mon, Dec 29, 2008 at 02:02:08PM +0100, Benjamin Larsson wrote:
> $topic, based on this:
> http://msdn.microsoft.com/en-us/library/ms713496.aspx
> 
> MvH
> Benjamin Larsson

> Index: libavformat/riff.c
> ===================================================================
> --- libavformat/riff.c	(revision 16278)
> +++ libavformat/riff.c	(working copy)
> @@ -267,12 +267,18 @@
>  int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
>  {
>      int bps, blkalign, bytespersec;
> +    int waveformatextensible = 0;
>      int hdrsize = 18;
>  
>      if(!enc->codec_tag || enc->codec_tag > 0xffff)
>          return -1;
>  
> -    put_le16(pb, enc->codec_tag);
> +    if (enc->channels > 2 && enc->channel_layout) {
> +        put_le16(pb, 0xfffe);
> +        waveformatextensible = 1;
> +    } else
> +        put_le16(pb, enc->codec_tag);
> +
>      put_le16(pb, enc->channels);
>      put_le32(pb, enc->sample_rate);
>      if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) {
> @@ -336,10 +342,21 @@
>          put_le16(pb, 2); /* wav_extra_size */
>          hdrsize += 2;
>          put_le16(pb, enc->frame_size); /* wSamplesPerBlock */
> -    } else if(enc->extradata_size){
> -        put_le16(pb, enc->extradata_size);
> +    } else if(enc->extradata_size || waveformatextensible){
> +        if (waveformatextensible) {                     /* write WAVEFORMATEXTENSIBLE extensions */
> +            put_le16(pb, enc->extradata_size+22);       /* 22 is the size of WAVEFORMATEXTENSIBLE-WAVEFORMATEX */
> +            put_le16(pb, enc->bits_per_coded_sample);   /* ValidBitsPerSample || SamplesPerBlock || Reserved */
> +            put_le32(pb, enc->channel_layout);          /* dwChannelMask */

> +            put_le32(pb, enc->codec_tag);               /* GUID + next 3 */
> +            put_le32(pb, 0);
> +            put_le32(pb, 0);
> +            put_le32(pb, 0);

This does not look correct, we should use the official GUIDs where such exist
and only fall back to tag+000 when none exists.

also, waveformatextensible does not belong under one branch of the if/else
chain used to set extradata, instead it should be written independant of
the branch, just depening on "waveformatextensible"

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

There will always be a question for which you do not know the correct awnser.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20081229/4446c41a/attachment.pgp>



More information about the ffmpeg-devel mailing list