[FFmpeg-devel] Wave header

Daniel Verkamp daniel at drv.nu
Sat Apr 20 02:15:50 CEST 2013


On Fri, Apr 19, 2013 at 8:15 AM, Виталий <vitalik1231 at yandex.ru> wrote:
>>The short answer: add '-flags +bitexact' to the FFmpeg command line.
>>
>>This inhibits the "encoder" metadata (see libavformat/mux.c:336), so
>>no extra chunks will be written.
>>
>>It would still be interesting to know what (broken) programs do not
>>accept WAV files with arbitrary chunks in the header; this is also a
>>worry for -rf64 auto mode (which is currently not enabled by default).
>>
>>Thanks,
>>-- Daniel Verkamp
>
> It doesn't work
> Source code of wavcrc32.cpp you can find from:
> http://rutracker.org/forum/viewtopic.php?t=357895
> http://pastebin.com/M3DxtHqX

The next problem is that the optional "cbSize" in the fmt chunk is
always being written even when it is zero.  This is due to:

commit 2c4e08d89327595f7f4be57dda4b3775e1198d5e
Author: John Brooks <john.brooks at bluecherry.net>
Date:   Thu Oct 13 08:34:20 2011 +0000

    riff: always generate a proper WAVEFORMATEX structure in ff_put_wav_header

    The cbSize field should be included in all cases, even with PCM where
    its value is ignored.

    Fixes encoding PCM audio in Matroska for some players which insist on
    a full WAVEFORMATEX structure for A_MS/ACM audio.

The change looks correct to me based on the docs; according to a MS
developer blog [1], the WAVEFORMATEX structure (used from Windows 95
on) has the cbSize parameter, which should exist and be set to zero
for PCM according to MSDN [2].

As a counter-argument, the PCM WAV files shipped with recent versions
of Windows (e.g. %WINDIR%\Media\ding.wav) still have a 0x10-byte fmt
chunk, so no cbSize... (do as I say, not as I do?)


Anyway, the problem could be solved by relaxing the check on the fmt
chunk size in wavcrc32:

  if (!CheckDWORD(f, 0x10, 0x00000010, "*** invalid format chunk
size!")) return 0;

This could be changed to allow for any size >= 0x10 (size of the
original PCMWAVEFORMAT from Windows 3.1) and skip any further contents
of fmt. Additionally, it would need to be changed to skip any unknown
chunks to work with the files that ffmpeg creates by default.

Thanks,
-- Daniel Verkamp


[1]: http://blogs.msdn.com/b/larryosterman/archive/2007/10/18/the-evolution-of-a-data-structure-the-waveformat.aspx
[2]: http://msdn.microsoft.com/en-us/library/windows/desktop/dd390970(v=vs.85).aspx


More information about the ffmpeg-devel mailing list