ndugger
ndugger

Reputation: 7531

fluent-ffmpeg module: "end" event does not fire

I'm using the fluent-ffmpeg npm module

I've POSTed a video from my client, and am using new stream.Readable to "read" the video Buffer.

ffmpeg is converting and saving the file, and everything seems beautiful, but the "end" event never fires.

My code is as follows:

const videoStream = new stream.Readable({
    read: function (n) {
        this.push(myVideoBuffer);
    }
});

ffmpeg(videoStream)
.on('progress', e => console.log(e))
.on('end', () => {
    console.log('ended')
    videoStream.destroy();
})
.on('error', e => console.error(e))
.save(`${process.cwd()}/media/videos/${Date.now()}.mp4`);

I get a log on every progress event, and it does save the video, but the "end" event's callback never gets called.

I assume this is a bug, since everything else works just fine.

Upvotes: 4

Views: 2524

Answers (1)

ndugger
ndugger

Reputation: 7531

Apparently, I had to push null to my Readable stream after I pushed my Buffer in order to end the stream, which ended the ffmpeg process in turn.

const videoStream = new stream.Readable({
    read: function (n) {
        this.push(myVideoBuffer);
        this.push(null);
    }
});

That's it; now my "end" event is firing, and all is well.

Upvotes: 2

Related Questions