Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor.JS CollectionFS Video to Image Thumbnails (Graphics Magick)

I am working on one Meteor App where I am using CollectionFS to upload Files.

I am able to upload and generate thumbnails for Images.

But my Issue is : How should I create thumbnails for Videos?

I can see that it is possible via command line: https://superuser.com/questions/599348/can-imagemagick-make-thumbnails-from-video

But how can I apply this to my Meteor code.

Here is what I am doing:

VideoFileCollection = new FS.Collection("VideoFileCollection", {
stores: [
  new FS.Store.FileSystem("videos", {path: "/uploads/videos"}),
  new FS.Store.FileSystem("videosthumbs", {path: "/uploads/videosthumbs",
    beforeWrite: function(fileObj) {
      // We return an object, which will change the
      // filename extension and type for this store only.
      return {
        extension: 'png',
        type: 'image/png'
      };
    },
    transformWrite: function(fileObj, readStream, writeStream) {
      gm(readStream, fileObj.name()).stream('PNG').pipe(writeStream);

    }
  })
]
});

What is happening here that video is getting Uploaded to "videos" folder and one PNG is created under "videosthumbs" with 0 Bytes and thumbnail is not getting generated.

I have also read at : https://github.com/aheckmann/gm#custom-arguments

that we can use : gm().command() - Custom command such as identify or convert

Can Anybody advise me on what can be done to handle this situation?

Thanks and Regards

like image 828
Manu Avatar asked Aug 27 '15 09:08

Manu


1 Answers

Checked the link that you have added and here is a rough solution that might help you

ffmpeg -ss 600 -i input.mp4 -vframes 1 -s 420x270 -filter:v 'yadif' output.png

Here is a function that i have made.

var im = require('imagemagick');

var args = [
    "ffmpeg", "-ss", "600", "-i", "input.mp4", "-vframes", " 1", "-s", "420x270", "-filter:v", "'yadif'", "output.png"
    ];

// Function to convert and 
im.convert(args, function(err) 
if (err) throw err;
});
like image 183
Profstyle Avatar answered Oct 20 '22 21:10

Profstyle