[FFmpeg-devel] [PATCH] WAVEFORMATEXTENSIBLE support in the wav muxer
Benjamin Larsson
banan
Mon Dec 29 21:23:23 CET 2008
Michael Niedermayer wrote:
> 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.
True, http://www.microsoft.com/whdc/device/audio/multichaud.mspx
mentions this that you can convert 2CC/4CC to GUID
(DEFINE_WAVEFORMATEX_GUID(x) ). Would that be acceptable? The main
objective is to be able to store multichannel pcm data.
>
> 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"
>
Ok, I'll cook something up.
MvH
Benjamin Larsson
More information about the ffmpeg-devel
mailing list