花太长时间才能在ffmpeg中生成ScreenShot [英] Taking too long to generate a ScreenShot in ffmpeg
问题描述
我正在使用ffmpeg生成屏幕截图.它会生成缩略图,但耗时太长(超过2分钟).
I am generating a Screenshot by using ffmpeg. Its generating the thumbnail but its taking too long (more than 2 minutes).
我已引用此链接
但是我必须在我的nodejs代码中设置
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'
});
我使用了时间戳记,尽管花费了超过2分钟的时间.如何解决此问题.
I used timestamp But even though its taking more than 2 minutes. How do I fix this Issue.
推荐答案
我不喜欢fluent-ffmpeg"screenshot"命令. ffmpeg具有内置的屏幕截图功能,并且更加灵活.最值得注意的是,它使您可以利用ffmpeg的功能来快速查找输入"而不是输出". (寻求输出"基本上意味着它将处理视频开始到您要截屏的那一帧之间的每一帧.)
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.)
幸运的是,fluent-ffmpeg允许您通过outputOptions
使用任何命令行参数.以下命令将在15分钟后截取屏幕截图.在我的机器上大约需要1秒钟.
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()
没有命令"-frames 1",它将为视频的每一帧拍摄屏幕截图.
Without the command '-frames 1', it would take a screenshot for every frame of the video.
为说明此功能的强大之处,以下命令将整个视频连续生成5x5图像(每个文件25张图像).非常适合制作缩略图.
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?
这篇关于花太长时间才能在ffmpeg中生成ScreenShot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!