如何在node.js中生成视频缩略图?

时间:2022-11-25 13:35:58

am building a app with node.js, i successfully uploaded the video but i need to generate a video thumbnail for it, currently i use node exec to excute a system command of ffmpeg to make the thumbnail

我正在用node.js构建一个应用程序,我成功上传了视频,但我需要为它生成一个视频缩略图,目前我使用node exec来执行ffmpeg的系统命令来制作缩略图

   exec("C:/ffmpeg/bin/ffmpeg -i Video/" + Name  + " -ss 00:01:00.00 -r 1 -an -vframes 1 -f mjpeg Video/" + Name  + ".jpg")

this code is coming from a tutorial from http://net.tutsplus.com/tutorials/javascript-ajax/how-to-create-a-resumable-video-uploade-in-node-js/

此代码来自http://net.tutsplus.com/tutorials/javascript-ajax/how-to-create-a-resumable-video-uploade-in-node-js/上的教程

the code above did generate a jpg file but its not a thumbnail but a video screen shot, i wonder is there any other method to generate video thumbnail,or how to exec the ffmpeg command to make a real thumbanil (resized),and i prefer png file, please help!!!

上面的代码确实生成了一个jpg文件,但它不是缩略图而是视频屏幕截图,我想知道是否还有其他方法来生成视频缩略图,或者如何执行ffmpeg命令来制作真正的thumbanil(调整大小),我更喜欢png文件,请帮忙!!!

5 个解决方案

#1


1  

Resize by adding a -s widthxheight option to your command.

通过在命令中添加-s widthxheight选项来调整大小。

#2


9  

Reference to GitHub fluent-ffmpeg project.

参考GitHub fluent-ffmpeg项目。

Repeating example from original * answer:

从原始的*回答示例:

var proc = new ffmpeg('/path/to/your_movie.avi')
  .takeScreenshots({
      count: 1,
      timemarks: [ '600' ] // number of seconds
    }, '/path/to/thumbnail/folder', function(err) {
    console.log('screenshots were saved')
  });

#3


1  

There is a node module for this: video-thumb

有一个节点模块:video-thumb

It basically just wraps a call to exec ffmpeg

它基本上只是调用exec ffmpeg

#4


0  

I recommend using https://www.npmjs.com/package/fluent-ffmpeg to call ffmpeg from Node.js

我建议使用https://www.npmjs.com/package/fluent-ffmpeg从Node.js调用ffmpeg

#5


0  

Instead I would recommend using thumbsupply. In addition to provide you with thumbnails, it caches them to improve performance significantly.

相反,我会建议使用thumbsupply。除了为您提供缩略图之外,它还可以缓存它们以显着提高性能。

npm install --save thumbsuppply

After installing the module, you can use it in a following way.

安装模块后,您可以按以下方式使用它。

const thumbsupply = require('thumbsupply')("com.example.application");

thumbsupply.generateThumbnail('some-video.mp4')
.then(thumb => {
    // serve thumbnail
})

#1


1  

Resize by adding a -s widthxheight option to your command.

通过在命令中添加-s widthxheight选项来调整大小。

#2


9  

Reference to GitHub fluent-ffmpeg project.

参考GitHub fluent-ffmpeg项目。

Repeating example from original * answer:

从原始的*回答示例:

var proc = new ffmpeg('/path/to/your_movie.avi')
  .takeScreenshots({
      count: 1,
      timemarks: [ '600' ] // number of seconds
    }, '/path/to/thumbnail/folder', function(err) {
    console.log('screenshots were saved')
  });

#3


1  

There is a node module for this: video-thumb

有一个节点模块:video-thumb

It basically just wraps a call to exec ffmpeg

它基本上只是调用exec ffmpeg

#4


0  

I recommend using https://www.npmjs.com/package/fluent-ffmpeg to call ffmpeg from Node.js

我建议使用https://www.npmjs.com/package/fluent-ffmpeg从Node.js调用ffmpeg

#5


0  

Instead I would recommend using thumbsupply. In addition to provide you with thumbnails, it caches them to improve performance significantly.

相反,我会建议使用thumbsupply。除了为您提供缩略图之外,它还可以缓存它们以显着提高性能。

npm install --save thumbsuppply

After installing the module, you can use it in a following way.

安装模块后,您可以按以下方式使用它。

const thumbsupply = require('thumbsupply')("com.example.application");

thumbsupply.generateThumbnail('some-video.mp4')
.then(thumb => {
    // serve thumbnail
})