首页 > 解决方案 > 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

标签: node.jsffmpegfluent-ffmpeg

解决方案


原来,使用

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

推荐阅读