Taking too long to generate a ScreenShot in ffmpeg

2019-05-23 12:27发布

I am generating a Screenshot by using ffmpeg. Its generating the thumbnail but its taking too long (more than 2 minutes).

I have referred this link

create thumbnails from big movies with FFmpeg takes too long

But I have to set in my nodejs code

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

I used timestamp But even though its taking more than 2 minutes. How do I fix this Issue.

1条回答
Viruses.
2楼-- · 2019-05-23 12:45

I'm not a fan of the fluent-ffmpeg "screenshot" command. ffmpeg has a built-in screenshot capability, and it's much more flexible. Most notably, it allows you to take advantage of ffmpeg's ability to quickly seek on on the "input" rather than the "output". ("Seeking on output" basically means that it will process every single frame between the start of the video and the one that you want to screenshot.)

Fortunately, fluent-ffmpeg allows you to use any command line parameters, by way of outputOptions. The following command would take a screenshot at the 15-minute mark. It takes about 1 second on my machine.

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

Without the command '-frames 1', it would take a screenshot for every frame of the video.

As an illustration of just how powerful this can be, the following command makes consecutive sprited 5x5 images (25 images per file) of an entire video. Great for making thumbnails.

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?
查看更多
登录 后发表回答