Meteor.JS CollectionFS视频转换为图像缩略图(Graphics Magick)

7
我正在开发一款Meteor应用程序,其中使用CollectionFS上传文件。
我已经能够上传并生成图像的缩略图。
但我的问题是:如何为视频创建缩略图?
我可以通过命令行看到它是可能的:https://superuser.com/questions/599348/can-imagemagick-make-thumbnails-from-video 但我该如何将其应用到我的Meteor代码中。
以下是我的做法:
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);

    }
  })
]
});

视频被上传到"videos"文件夹中,同时在"videosthumbs"下创建一个0字节的PNG文件,但无法生成缩略图。我还阅读了这篇文章:https://github.com/aheckmann/gm#custom-arguments,其中提到可以使用gm().command()自定义命令,比如identify或者convert。请问有什么建议来解决这个问题吗?谢谢。
1个回答

1

我已经检查了您添加的链接,这里提供一个初步的解决方案可能会对您有所帮助。

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

这是我写的一个函数。
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;
});

谢谢,我已经尝试过了,但仍无法解决这个问题。 - Manu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接