哪个ffmpeg命令序列可以生成视频的第一帧[需要Node.js应用程序的缩略图]

Which ffmpeg command sequence can generate the first frame of the video [Need thumbnails for Node.js app]

我正在尝试为视频制作缩略图,但问题是我无法编写一些正确的 ffmpeg 命令来获取第一帧。这是用于 Node.js AWS Lambda 函数。

我试过了,但对我不起作用。

-vf "select=eq(n\,0)"

从这里尝试了所有 How to extract the 1st frame and restore as an image with ffmpeg?

这是我的命令行,我复制了它,老实说我不知道​​这个命令。

function createImage(type) {
    return new Promise((resolve, reject) => {
      let tmpFile = fs.createWriteStream(`/tmp/screenshot.${type}`);
      const ffmpeg = spawn(ffmpegPath, [
      '-ss',
      '00:00:00.01',
      '-i',
      target,
      '-vf',
      `thumbnail`,
      '-qscale:v',
      '2',
      '-frames:v',
      '1',
      '-f',
      'image2',
      '-c:v',
      'mjpeg',
      'pipe:1',
    ]);


  ffmpeg.stdout.pipe(tmpFile);

  ffmpeg.on('close', function(code) {
    tmpFile.end();
    resolve();
  });

  ffmpeg.on('error', function(err) {
    console.log(err);
    reject();
  });
});
}

(我在 Node 子进程上使用这个 https://johnvansickle.com/ffmpeg/ 版本 4.2.3。)

这应该会让您得到想要的结果。

您的命令中有一些额外的参数。您应该阅读ffmpeg文档。

function createImage(type) {
    return new Promise((resolve, reject) => {
        let tmpFile = fs.createWriteStream(`./screenshot.${type}`);
        const ffmpeg = spawn(ffmpegPath, [
            '-i', target,
            '-r', '1',
            '-vframes', '1',
            '-f', 'image2',
            '-qscale:v', '2',
            '-c:v', 'mjpeg',
            'pipe:1'
        ]);


        ffmpeg.stdout.pipe(tmpFile);

        ffmpeg.on('close', code => {
            tmpFile.end();
            resolve();
        });

        ffmpeg.on('error', err => {
            console.log(err);
            reject();
        });
    });
}


createImage("jpg");