node.js - Fluent-ffmpeg:标签为“screen0”的输出不存在于任何不同的过滤器图中,或者已在其他地方使用
问题描述
我正在尝试使用 fluent-ffmpeg 逐帧拍摄视频,以创建视频遮罩和类似的实验视频编辑器。但是当我这样做时,screenshots
它说ffmpeg exited with code 1: Output with label 'screen0' does not exist in any defined filter graph, or was already used elsewhere.
这是我用于生成时间戳的示例数组。["0.019528","0.05226","0.102188","0.13635","0.152138","0.186013","0.236149" ...]
// read json file that contains timestaps, array
fs.readFile(`${config.videoProc}/timestamp/1.json`, 'utf8', async (err, data) => {
if (err) throw new Error(err.message);
const timestamp = JSON.parse(data);
// screenshot happens here
// loop till there is nothing on array...
function takeFrame() {
command.input(`${config.publicPath}/static/video/1.mp4`)
.on('error', error => console.log(error.message))
.on('end', () => {
if (timestamp.length > 0) {
// screenshot again ...
takeFrame();
} else {
console.log('Process ended');
}
})
.noAudio()
.screenshots({
timestamps: timestamp.splice(0, 100),
filename: '%i.png',
folder: '../video/img',
size: '320x240',
});
}
// call the function
takeFrame();
});
我的预期结果是,我可以生成所有 600 个屏幕截图。在一个视频上。但实际结果是这个错误ffmpeg exited with code 1: Output with label 'screen0' does not exist in any defined filter graph, or was already used elsewhere
,只生成了 100 个屏幕。
[更新]
使用这里-filter_complex
提到的确实有效。
ffmpeg exited with code 1: Error initializing complex filters.
Invalid argument
[更新]
命令行参数:
ffmpeg -ss 0.019528 -i D:\Latihan\video-cms-core\public/static/video/1.mp4 -y -filter_complex scale=w=320:h=240[size0];[size0]split=1[screen0] -an -vframes 1 -map [screen0] ..\video\img\1.png
解决方案
原来,使用
ffmpeg().input(path)
并且ffmpeg(path)
表现不同。那就是在输入帧上重复。第一个命令保留旧输入帧并添加它,第二个命令没有。所以第二个命令完美运行。
谢谢。
工作代码:
function takeFrame() {
// notice that I inisitae this new ffmpeg, not using const command = new ffmpeg()
const screenshots = new ffmpeg(`${config.publicPath}/static/video/1.mp4`)
.on('error', error => console.log(error.message))
.on('end', () => {
if (timestamp.length > 0) {
// screenshot again ...
takeFrame();
} else {
console.log('Process ended');
}
})
.noAudio()
.screenshots({
timestamps: timestamp.splice(0, 100),
filename: '%i.png',
folder: '../video/img',
size: '320x240',
});
}
// call the function
takeFrame();
});
推荐阅读
- dmn - 通过 DMN 中的业务知识模型返回时处理 null
- tomcat - 在 catalina.sh 和 setenv.sh 更改时区后,tomcat 时区没有改变
- mongodb - 左加入 group by 并在 mongoose 中有子句
- dasha - 如何将动态数据添加到短语表中?
- python - pygame 中缺少位置参数
- python - 使用 OpenCV 将 RGB 注册到具有不同分辨率和视场的热图像
- c++ - 一个函数只返回一个索引而不是两个或更多 | C++
- json - 如何使用特定数据附加 JSON 数组
- ios - 升级到 Uno.UI 3.9.7 后出现异常:FrameNavigationController 多次推送同一个视图控制器实例 PageViewController
- edmx - Business Central API 列表扩展/发布者