Search code examples
node.jsffmpegfluent-ffmpeg

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


I'm trying to take video frame by frame using fluent-ffmpeg, to create video masking and some kin of like experiment video editor. But when I do that by screenshots it says ffmpeg exited with code 1: Output with label 'screen0' does not exist in any defined filter graph, or was already used elsewhere.

Here example array that I use for producing timestamps. ["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();
});

My expected result are, I can genereta all the 600 screenshot. on one video. but the actual result is this error ffmpeg exited with code 1: Output with label 'screen0' does not exist in any defined filter graph, or was already used elsewhere and only 100 screen generated.

[UPDATE]

using -filter_complex as mentioned in here doenst work.

ffmpeg exited with code 1: Error initializing complex filters.
Invalid argument

[UPDATE]

command line arg :

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

Solution

  • Turns out that using

    ffmpeg().input(path) and ffmpeg(path) behave differently. Thats make duplicate on input frames. first command keeping old input frames and add it, and second command doesnt. so the second command works perfectly.

    Thanks.

    Working code :

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