16

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 of ffmpeg to make the thumbnail.

   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/

the code above did generate a jpg file but it's 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 thumbnail (resized), and I prefer png file.

Sinandro
  • 2,426
  • 3
  • 21
  • 36
paynestrike
  • 4,348
  • 14
  • 46
  • 70

7 Answers7

20

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')
  });
Community
  • 1
  • 1
Risadinha
  • 16,058
  • 2
  • 88
  • 91
  • 2
    what is `count:1` here ?? – vineet Mar 09 '16 at 12:54
  • 2
    quoting the documentation: "count: specifies how many thumbnails to generate. When using this option, thumbnails are generated at regular intervals in the video (for example, when requesting 3 thumbnails, at 25%, 50% and 75% of the video length). count is ignored when timemarks or timestamps is specified." – Risadinha Mar 09 '16 at 15:20
  • 2
    can that /path/to/your_movie.avi be a URL? – Andrey Solera Jul 15 '17 at 21:23
2

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

av501
  • 6,645
  • 2
  • 23
  • 34
  • well it works, but is this the only way to do this,i mean do i really have to use exec, is there a node module to handle this problem – paynestrike Oct 26 '12 at 04:28
2

There is a node module for this: video-thumb

It basically just wraps a call to exec ffmpeg

Matt Palmerlee
  • 2,668
  • 2
  • 27
  • 28
1

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

0

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

npm install --save thumbsupply

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
})
ryanafrish7
  • 3,222
  • 5
  • 20
  • 35
0

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.

Rajat Saxena
  • 3,834
  • 5
  • 45
  • 63
-1
app.post('/convert', upload.any(), (req, res) => {
    console.log("calling", req.files)
    let thumbNailName = req.files[0].filename.split('.')
    var gm = require('gm');

    gm('./src/Upload/'+req.files[0].filename)// get pdf file from storage folder
    .thumb(
        50, // Width
        50, // Height
        './src/thumbnail/'+thumbNailName[0]+'.png', // Output file name
        80, // Quality from 0 to 100
        function (error, stdout, stderr, command) {
            if (!error) {
                console.log("processing");
            } else {
                console.log("error")
            }
        }
    );
})