I am trying to fluent-ffmpeg synchronously and await
its finishing. I wrapped it in a promise
and wait for it to resolve.
The problem is that it stops doing anything after the second chunk has been processed. I get an output of:
Processing: NaN% done
Processing: 12.710198594559962% done
Processing: 25.846254358525282% done
And then it just hangs and does nothing. I am using NodeJS’s PassThrough
to pipe the data from ffpmeg to. If I remove the promise
and just it normally, then it works fine. But I need the promise because there is other code after this that must wait for ffmpeg to finish first.
import {PassThrough} from 'node:stream';
import FFMpeg from 'fluent-ffmpeg';
let PassThroughStream = new PassThrough();
function ffmpegPromise() {
return new Promise((resolve, reject) => {
FFMpeg('/testvid.mp4')
.videoCodec('libx264')
.audioCodec('libmp3lame')
.size('640x480')
// Stream output requires manually specifying output formats
.format('mp4')
.outputOptions('-movflags dash')
.on('progress', function (progress) {
console.log('Processing: ' + progress.percent + '% done');
})
.on('error', function (err) {
console.log('An error occurred: ' + err.message);
reject(err);
})
.on('end', function () {
console.log('FFMpeg Processing finished!');
resolve()
})
.output(PassThroughStream, {end: false}).run();
})
}
await ffmpegPromise();