node-wav icon indicating copy to clipboard operation
node-wav copied to clipboard

Unsupported format in WAV file: ff

Open Ron-SSG opened this issue 5 years ago • 1 comments

Hi !

I'm extracting audio for a video using ffmpeg with the command: ffmpeg -i input_video.mp4 -c copy -map a -f segment -segment_time 0.50 audio_frame-%d.wav

And when I try to decode one of the wav files like so:

let buffer = fs.readFileSync('audio_frame-%d.wav');
let result = wav.decode(buffer);

return JSON.stringify({ data: result.channelData });

I get a decoder error on the second line(the decode function) saying:

TypeError: Unsupported format in WAV file: ff
 at Object.decode (/root/myProject/node_modules/node-wav/index.js:204:15)

Any idea why and how to fix it?

Ron-SSG avatar Oct 11 '20 08:10 Ron-SSG

I have similar issues.

I'm split audio ussing ffmpeg with the command: ffmpeg -i .\audio.wav -f segment -segment_time 0.05 -c copy out%04d.wav

And I try to decode part of wav file like this:

let buffer = fs.readFileSync('out0148.wav');
let result = wav.decode(buffer);

and I get error on decode line:

TypeError: Unsupported format in WAV file: fffe
    at Object.decode (C:\Users\bass9030\Documents\REAPER Media\split test\node_modules\node-wav\index.js:204:15)
    at Object.<anonymous> (C:\Users\bass9030\Documents\REAPER Media\split test\index.js:2:18)

I think this issue occurs when try to load too short a wav file.

The temporary solution is to modify some of the phrases in node-wav/index.js:204

...
 while (pos < end) {
    let type = string(4);
    let size = u32();
    let next = pos + size;
    switch (type) {
    case 'fmt ':
      let formatId = u16();
      // comment the conditional statements
      /*if (formatId !== 0x0001 && formatId !== 0x0003)
        throw new TypeError('Unsupported format in WAV file: ' + formatId.toString(16));*/
      fmt = {
        format: 'lpcm',
        floatingPoint: formatId === 0x0003,
        channels: u16(),
        sampleRate: u32(),
        byteRate: u32(),
        blockSize: u16(),
        bitDepth: u16(),
      };
...

bass9030 avatar Jul 28 '22 08:07 bass9030

#4 should fix this issue

achrafash avatar Mar 15 '24 18:03 achrafash