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

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.

解决方案

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?

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐