Fluent-ffmpeg:带有标签 'screen0' 的输出不存在于任何不同的过滤器图中,或者已在其他地方使用

Fluent-ffmpeg : Output with label 'screen0' doesnot exist in any diferent filter graph, or was already used elsewhere

我正在尝试使用 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 中提到的 here 确实有效。

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.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();
});