在 ffmpeg 中生成屏幕截图花费太长时间

Vis*_*hnu 5 ffmpeg node.js

我正在使用 ffmpeg 生成屏幕截图。它生成缩略图,但花费的时间太长(超过 2 分钟)。

我已经提到了这个链接

使用 FFmpeg 从大电影创建缩略图需要太长时间

但我必须在我的nodejs代码中设置

ffmpeg(main_folder_path)
  .on('filenames', function(filenames) {
    console.log('Will generate ' + filenames.join(', '))
  })
  .on('end', function() {
    console.log('Screenshots taken');
  })
  .screenshots({
pro_root_path+'public/uploads/inspection/'+req.body.clientID+'/images/'
timestamps: [30.5, '20%', '01:10.123'],
filename: 'thumbnail-at-%s-seconds.png',
folder: pro_root_path+'public/uploads/inspection/'+req.body.clientID+'/images/',
size: '320x240'
  });
Run Code Online (Sandbox Code Playgroud)

我使用了时间戳,但即使它花费了超过 2 分钟。我该如何解决这个问题。

jam*_*lol 10

我不喜欢 fluence-ffmpeg“屏幕截图”命令。ffmpeg 具有内置的屏幕截图功能,而且更加灵活。最值得注意的是,它允许您利用 ffmpeg 快速查找“输入”而不是“输出”的能力。(“寻找输出”基本上意味着它将处理视频开始和您想要屏幕截图之间的每一帧。)

幸运的是,Fluent-ffmpeg 允许您通过outputOptions. 以下命令将在 15 分钟标记处截取屏幕截图。在我的机器上大约需要 1 秒。

ffmpeg('video.mp4')
    .seekInput('15:00.000')
    .output('output/screenshot.jpg')
    .outputOptions(
        '-frames', '1'  // Capture just one frame of the video
    )
    .on('end', function() {
      console.log('Screenshot taken');
    })
    .run()
Run Code Online (Sandbox Code Playgroud)

如果没有命令“-frames 1”,它将截取视频的每一帧的屏幕截图。

为了说明它的强大功能,以下命令可以制作整个视频的连续精灵 5x5 图像(每个文件 25 个图像)。非常适合制作缩略图。

ffmpeg('video.mp4')
    .on('end', function() {
      console.log('Screenshots taken');
    })
    .output('output/screenshot-%04d.jpg')
    .outputOptions(
        '-q:v', '8',
        '-vf', 'fps=1/10,scale=-1:120,tile=5x5',
    )
    .run()

// fps=1/10: 1 frame every 10 seconds
// scale=-1:120: resolution of 120p
// tile=5x5: 25 screenshots per jpg file
// -q:v 8: quality set to 8. 0=best, 69=worst?
Run Code Online (Sandbox Code Playgroud)