1

On my node.js server I want to convert a wav file to apple lossless .m4a

Using fluent-ffmpeg, I got this so far:

const transcoder = ffmpeg(fs.createReadStream(`${__dirname}/convertTest.wav`));

transcoder
  .withAudioCodec('alac')
  .addOutput(fs.createWriteStream(`${__dirname}/test2.m4a`))
  .run()
;

But it throws me the following error:

Error: ffmpeg exited with code 1: Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 -- 
Conversion failed!

I read that mp4 container needs a seekable file an therefore doesn't work with streams. So this actually works:

const transcoder = ffmpeg(`${__dirname}/convertTest.wav`);

transcoder
  .withAudioCodec('alac')
  .save(`${__dirname}/test2.m4a`)
  .run()
;

Since I have all files as streams and not physical files, I am looking for way to somehow abstract this away to make it work with streams. Is this possible with fluent-ffmpeg?

The alac codec and .m4a format is non optional, so I need it to work with those formats.

Johannes Klauß
  • 10,676
  • 16
  • 68
  • 122

1 Answers1

0

Turns out that the ALAC codec does not support streams because the file head has to be read at different times. So I had to use it without streams.

Johannes Klauß
  • 10,676
  • 16
  • 68
  • 122