我正在使用 fluent-ffmpeg
npm 模块
我已经从我的客户端发布了一个视频,并且正在使用 new stream.Readable
来“读取”视频缓冲区。
ffmpeg 正在转换和保存文件,一切看起来都很美好,但“结束”事件从未触发。
我的代码如下:
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`);
我得到了每个进度事件的日志,它确实保存了视频,但是“结束”事件的回调永远不会被调用。
我认为这是一个错误,因为其他一切正常。
最佳答案
显然,在我推送 Buffer 以结束流后,我必须将 null
推送到我的 Readable 流,这反过来结束了 ffmpeg 进程。
const videoStream = new stream.Readable({
read: function (n) {
this.push(myVideoBuffer);
this.push(null);
}
});
就是这样;现在我的“结束”事件正在触发,一切都很好。
关于node.js - 流利的 ffmpeg 模块 : "end" event does not fire,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34123519/