[FFmpeg-trac] #10229(undetermined:new): Wrong data size for WAV (RIFF) format

FFmpeg trac at avcodec.org
Thu Mar 2 20:43:36 EET 2023


#10229: Wrong data size for WAV (RIFF) format
-------------------------------------+-------------------------------------
             Reporter:  polochon     |                     Type:  defect
               Status:  new          |                 Priority:  normal
            Component:               |                  Version:
  undetermined                       |  unspecified
             Keywords:  pcm_u8 RIFF  |               Blocked By:
  WAV                                |
             Blocking:               |  Reproduced by developer:  0
Analyzed by developer:  0            |
-------------------------------------+-------------------------------------
 Hello,

 I think there is sometimes an issue when converting wav files to another
 wave file with specific format.

 A problematic input file is freely available on this free sound bank:
 https://lasonotheque.org/detail-0254-klaxon-de-vielle-voiture-1.html
 (click on "télécharger" red button to download). The issue is not
 systematic but happend quite often with different files tried.

 What I do: I need to convert sounds for the thymio robot project which
 accept only:
 - 8000Hz sampling
 - mono channel
 - PCM u8 unsigned
 - absolutely no metadatas in file.

 The command line used:
 ffmpeg -i originalWav/VEHHorn_Klaxon_de_vielle_voiture_1.wav -f wav
 -bitexact -map_metadata -1 -c:a pcm_u8 -ac 1 -ar 8000 Pwork.wav

 Observed behavior: Thymio robot don't play sounds

 Hypothesis:
 There is an issue in the datasize field, at adress 0x28 just near the "64
 46 74 61" data block.
 I understand (by reading some docs on RIFF files) that the next 4 bytes
 are caclculated like this: size of the file - size of the header, which is
 44 bytes in my case.
 For my file:
 hexdump -C -n 60 Pwork.wav
 00000000  52 49 46 46 78 07 00 00  57 41 56 45 66 6d 74 20
 |RIFFx...WAVEfmt |
 00000010  10 00 00 00 01 00 01 00  40 1f 00 00 40 1f 00 00
 |........ at ...@...|
 00000020  01 00 08 00 64 61 74 61  53 07 00 00 7f 7f 7f 7f
 |....dataS.......|
 00000030  7f 7f 7f 7f 7f 7f 7f 7f  7f 7f 7f 7f              |............|
 0000003c

 In this case, the file is 1920bytes so the data size should be
 1920-44=1876bytes.
 The size is 0x753 which is 1875 bytes, so there is an 1 byte error.

 In this case, I'm not able to play the sound with the thymio robot. But if
 I put the right size (I edit the file manually), this work wells. I
 suppose that the robot firmware do some verifications before playing a
 sound.

 Thanks
 Polochon


 Additional infos with complete log:
 ffmpeg -v 9 -loglevel 99 -i
 originalWav/VEHHorn_Klaxon_de_vielle_voiture_1.wav -f wav -bitexact
 -map_metadata -1 -c:a pcm_u8 -ac 1 -ar 8000 Pwork.wav
 ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg
 developers
   built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
   configuration: --prefix=/usr --extra-version=0ubuntu0.1
 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu
 --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl
 --disable-stripping --enable-avresample --disable-filter=resample
 --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom
 --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca
 --enable-libcdio --enable-libcodec2 --enable-libflite --enable-
 libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme
 --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa
 --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-
 libpulse --enable-librsvg --enable-librubberband --enable-libshine
 --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh
 --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-
 libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-
 libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi
 --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl
 --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883
 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264
 --enable-shared
   libavutil      56. 31.100 / 56. 31.100
   libavcodec     58. 54.100 / 58. 54.100
   libavformat    58. 29.100 / 58. 29.100
   libavdevice    58.  8.100 / 58.  8.100
   libavfilter     7. 57.100 /  7. 57.100
   libavresample   4.  0.  0 /  4.  0.  0
   libswscale      5.  5.100 /  5.  5.100
   libswresample   3.  5.100 /  3.  5.100
   libpostproc    55.  5.100 / 55.  5.100
 Splitting the commandline.
 Reading option '-v' ... matched as option 'v' (set logging level) with
 argument '9'.
 Reading option '-loglevel' ... matched as option 'loglevel' (set logging
 level) with argument '99'.
 Reading option '-i' ... matched as input url with argument
 'originalWav/VEHHorn_Klaxon_de_vielle_voiture_1.wav'.
 Reading option '-f' ... matched as option 'f' (force format) with argument
 'wav'.
 Reading option '-bitexact' ... matched as option 'bitexact' (bitexact
 mode) with argument '1'.
 Reading option '-map_metadata' ... matched as option 'map_metadata' (set
 metadata information of outfile from infile) with argument '-1'.
 Reading option '-c:a' ... matched as option 'c' (codec name) with argument
 'pcm_u8'.
 Reading option '-ac' ... matched as option 'ac' (set number of audio
 channels) with argument '1'.
 Reading option '-ar' ... matched as option 'ar' (set audio sampling rate
 (in Hz)) with argument '8000'.
 Reading option 'Pwork.wav' ... matched as output url.
 Finished splitting the commandline.
 Parsing a group of options: global .
 Applying option v (set logging level) with argument 9.
 Successfully parsed a group of options.
 Parsing a group of options: input url
 originalWav/VEHHorn_Klaxon_de_vielle_voiture_1.wav.
 Successfully parsed a group of options.
 Opening an input file: originalWav/VEHHorn_Klaxon_de_vielle_voiture_1.wav.
 [NULL @ 0x562bce2d47c0] Opening
 'originalWav/VEHHorn_Klaxon_de_vielle_voiture_1.wav' for reading
 [file @ 0x562bce2d5240] Setting default whitelist 'file,crypto'
 Probing wav score:99 size:2048
 [wav @ 0x562bce2d47c0] Format wav probed with size=2048 and score=99
 [wav @ 0x562bce2d47c0] Before avformat_find_stream_info() pos: 44 bytes
 read:76136 seeks:3 nb_streams:1
 [wav @ 0x562bce2d47c0] probing stream 0 pp:32
 Probing mp3 score:1 size:4096
 [wav @ 0x562bce2d47c0] Probe with size=4096, packets=2469 detected mp3
 with score=1
 [wav @ 0x562bce2d47c0] probing stream 0 pp:31
 [wav @ 0x562bce2d47c0] probing stream 0 pp:30
 [wav @ 0x562bce2d47c0] probing stream 0 pp:29
 [wav @ 0x562bce2d47c0] probing stream 0 pp:28
 [wav @ 0x562bce2d47c0] probing stream 0 pp:27
 [wav @ 0x562bce2d47c0] probing stream 0 pp:26
 [wav @ 0x562bce2d47c0] probing stream 0 pp:25
 [wav @ 0x562bce2d47c0] probing stream 0 pp:24
 [wav @ 0x562bce2d47c0] probing stream 0 pp:23
 [wav @ 0x562bce2d47c0] probing stream 0 pp:22
 [wav @ 0x562bce2d47c0] probing stream 0 pp:21
 [wav @ 0x562bce2d47c0] probed stream 0
 [wav @ 0x562bce2d47c0] parser not found for codec pcm_s16le, packets or
 times may be invalid.
 [wav @ 0x562bce2d47c0] stream 0: start_time: -209146758205323.719
 duration: 0.234
 [wav @ 0x562bce2d47c0] format: start_time: -9223372036854.775 duration:
 0.234 bitrate=1447 kb/s
 [wav @ 0x562bce2d47c0] After avformat_find_stream_info() pos: 42394 bytes
 read:118486 seeks:3 frames:11
 Guessed Channel Layout for Input Stream #0.0 : stereo
 Input #0, wav, from 'originalWav/VEHHorn_Klaxon_de_vielle_voiture_1.wav':
   Metadata:
     comment         : Klaxon de vielle voiture 1
     encoded_by      : LaSonotheque.org
     originator_reference: 0254
     date            : 2007-03-30
     time_reference  : 0
     coding_history  : A=PCM,F=44100,W=16,M=stereo
     copyright       : CC0 / WTFPL / Domaine public
     IKEY            :
 voiture,klaxon,alerte,signal,sonore,vehicule,auto,automobile,pouet,car,horn,vehicle,klaxonner
   Duration: 00:00:00.23, bitrate: 1447 kb/s
     Stream #0:0, 11, 1/44100: Audio: pcm_s16le ([1][0][0][0] / 0x0001),
 44100 Hz, stereo, s16, 1411 kb/s
 Successfully opened the file.
 Parsing a group of options: output url Pwork.wav.
 Applying option f (force format) with argument wav.
 Applying option bitexact (bitexact mode) with argument 1.
 Applying option map_metadata (set metadata information of outfile from
 infile) with argument -1.
 Applying option c:a (codec name) with argument pcm_u8.
 Applying option ac (set number of audio channels) with argument 1.
 Applying option ar (set audio sampling rate (in Hz)) with argument 8000.
 Successfully parsed a group of options.
 Opening an output file: Pwork.wav.
 File 'Pwork.wav' already exists. Overwrite ? [y/N] y
 [file @ 0x562bce2e8d80] Setting default whitelist 'file,crypto'
 Successfully opened the file.
 Stream mapping:
   Stream #0:0 -> #0:0 (pcm_s16le (native) -> pcm_u8 (native))
 Press [q] to stop, [?] for help
 cur_dts is invalid st:0 (0) [init:0 i_done:0 finish:0] (this is harmless
 if it occurs once at the start per stream)
 detected 8 logical cores
 [graph_0_in_0_0 @ 0x562bce2f5000] Setting 'time_base' to value '1/44100'
 [graph_0_in_0_0 @ 0x562bce2f5000] Setting 'sample_rate' to value '44100'
 [graph_0_in_0_0 @ 0x562bce2f5000] Setting 'sample_fmt' to value 's16'
 [graph_0_in_0_0 @ 0x562bce2f5000] Setting 'channel_layout' to value '0x3'
 [graph_0_in_0_0 @ 0x562bce2f5000] tb:1/44100 samplefmt:s16
 samplerate:44100 chlayout:0x3
 [format_out_0_0 @ 0x562bce2f5740] Setting 'sample_fmts' to value 'u8'
 [format_out_0_0 @ 0x562bce2f5740] Setting 'sample_rates' to value '8000'
 [format_out_0_0 @ 0x562bce2f5740] Setting 'channel_layouts' to value '0x4'
 [format_out_0_0 @ 0x562bce2f5740] auto-inserting filter 'auto_resampler_0'
 between the filter 'Parsed_anull_0' and the filter 'format_out_0_0'
 [AVFilterGraph @ 0x562bce2e8880] query_formats: 4 queried, 6 merged, 3
 already done, 0 delayed
 [auto_resampler_0 @ 0x562bce2f86c0] [SWR @ 0x562bce2f8bc0] Using s16p
 internally between filters
 [auto_resampler_0 @ 0x562bce2f86c0] [SWR @ 0x562bce2f8bc0] Matrix
 coefficients:
 [auto_resampler_0 @ 0x562bce2f86c0] [SWR @ 0x562bce2f8bc0] FC: FL:0.500000
 FR:0.500000
 [auto_resampler_0 @ 0x562bce2f86c0] ch:2 chl:stereo fmt:s16 r:44100Hz ->
 ch:1 chl:mono fmt:u8 r:8000Hz
 Output #0, wav, to 'Pwork.wav':
     Stream #0:0, 0, 1/8000: Audio: pcm_u8 ([1][0][0][0] / 0x0001), 8000
 Hz, mono, u8, 64 kb/s
     Metadata:
       encoder         : Lavc pcm_u8
 [out_0_0 @ 0x562bce2f5f80] EOF on sink link out_0_0:default.
 No more output streams to write to, finishing.
 size=       2kB time=00:00:00.23 bitrate=  65.5kbits/s speed=57.3x
 video:0kB audio:2kB subtitle:0kB other streams:0kB global headers:0kB
 muxing overhead: 2.400000%
 Input file #0 (originalWav/VEHHorn_Klaxon_de_vielle_voiture_1.wav):
   Input stream #0:0 (audio): 11 packets read (41332 bytes); 11 frames
 decoded (10333 samples);
   Total: 11 packets (41332 bytes) demuxed
 Output file #0 (Pwork.wav):
   Output stream #0:0 (audio): 12 frames encoded (1875 samples); 12 packets
 muxed (1875 bytes);
   Total: 12 packets (1875 bytes) muxed
 11 frames successfully decoded, 0 decoding errors
 [AVIOContext @ 0x562bce2d7f80] Statistics: 4 seeks, 5 writeouts
 [AVIOContext @ 0x562bce2dd5c0] Statistics: 118486 bytes read, 3 seeks
-- 
Ticket URL: <https://trac.ffmpeg.org/ticket/10229>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list