how to generate video thumbnail in node.js?

前端 未结 6 970
不知归路
不知归路 2020-12-15 10:31

I am building an 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 execute a system command

相关标签:
6条回答
  • 2020-12-15 10:50

    Reference to GitHub fluent-ffmpeg project.

    Repeating example from original StackOverflow 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')
      });
    
    0 讨论(0)
  • 2020-12-15 10:50

    There is a node module for this: video-thumb

    It basically just wraps a call to exec ffmpeg

    0 讨论(0)
  • 2020-12-15 10:54

    Using media-thumbnail, you can easily generate thumbnails from your videos. The module basically wraps the ffmpeg thumbnail functionality.

    const mt = require('media-thumbnail')
    
    mt.forVideo(
      './path/to/video.mp4',
      './path/to/thumbnail.png', {
        width: 200
      })
      .then(() => console.log('Success'), err => console.error(err)) 
    

    You can also create thumbnails from your images using this package.

    0 讨论(0)
  • 2020-12-15 10:56

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

    0 讨论(0)
  • 2020-12-15 10:58

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

    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
    })
    
    0 讨论(0)
  • 2020-12-15 11:12

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

    0 讨论(0)
提交回复
热议问题