简体   繁体   English

nodejs快速获取mp4文件缩略图

[英]nodejs get mp4 file thumbnail quickly

I want to have a thumbnail of 0.0 sec of a video. 我想要一个视频的0.0秒的缩略图。 Currently I am using node-fluent-ffmpeg to generate thumbnail. 目前,我正在使用node-fluent-ffmpeg生成缩略图。 Following is the code: 以下是代码:

ffmpeg(tempLocalFile)
          .screenshots({
            timestamps: [0.0],
            filename: 'xx.png',
            folder: tempFilePath
          }).on('end', function() {
            console.log('done');
          });

But the problem is, it is taking too much of time to do the process. 但是问题是,花费太多时间来完成该过程。 It is normally taking 30sec to generate the thumbnail. 生成缩略图通常需要30秒。 Which keeps increasing if the mp4 file size increases. 如果mp4文件大小增加,该数字将不断增加。

So my question is, Is there any fast way to generate the thumbnail. 所以我的问题是,是否有任何快速的方法来生成缩略图。 Can we improve above code to improve the performance. 我们可以改进上面的代码来提高性能。

ps: The machine this code is running is 512MB RAM 800MHz ps:正在运行此代码的机器是512MB RAM 800MHz

There is a trick to make ffmpeg only decode a single frame. 有一个使ffmpeg仅解码单个帧的技巧。 You simply define the -ss flag before the input. 您只需在输入之前定义-ss标志。 That will force it to only decode the specified frame, as opposed to the whole video. 这将迫使它仅解码指定的帧,而不是整个视频。

ffmpeg -ss 0 -i input.mp4 -vframes 1 output.jpg

I'm not sure how this could be done in fluent-ffmpeg, or if it's even possible. 我不确定如何在fluent-ffmpeg中完成此操作,甚至不确定是否可行。 You could file an issue 您可以提出问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM