I tried to convert a file from pcm into mp3 with ffmpeg and the npm package fluent-ffmpeg. This is my code:
const ffmpeg = require('fluent-ffmpeg');
function convert(input, output, callback) {
ffmpeg(input)
.output(output)
.on('end', function() {
console.log('conversion ended');
callback(null);
}).on('error', function(err){
console.log('error: ' + err);
callback(err);
}).run();
}
convert('./test.pcm', './converted.mp3', function(err){
if(!err) {
console.log('conversion complete');
}
});
But every time I execute the script, I get this error:
error: Error: ffmpeg exited with code 1: ./test.pcm: Invalid data found when processing input
When I tired running:
ffmpeg -f s16le -ar 48k -ac 2 -i test.pcm converted.mp3
Everything worked though. Is there something wrong with the npm package? Is there something I missed out or something I did wrong on my code?
Edit:
My code works when I try to convert an mp3 to a wav file (for example). So it's only struggling with pcm files.