这个图像缩略图生成器功能是触发时,上传一个图像到blob容器和工作良好,但我不知道如何做同样的过程为视频!
var Jimp = require("jimp");
module.exports = (context, myBlob) => {
// Read image with Jimp
Jimp.read(myBlob).then((image) => {
// Manipulate image
image
.resize(200, Jimp.AUTO)
.greyscale()
.getBuffer(Jimp.MIME_JPEG, (error, stream) => {
// Check for errors
if (error) {
context.log(`There was an error processing the image.`);
context.done(error);
}
else {
context.log(`Successfully processed the image`);
// Bind the stream to the output binding to create a new blob
context.done(null, stream);
}
});
});
};
有多个节点模块
可以帮助您从视频生成缩略图。 您可以使用以下任一项:
在您的示例中,由于您计划为图像和视频生成缩略图,我建议使用fluent-FFMPEG
,因为它具有使用withSize()
方法处理图像和视频的功能。
但是,在缺点方面,为了能够使用这个模块,请确保您的系统上安装了ffmpeg(包括所有必要的编码库,如libmp3lame或libx264)。
fluent-FFMPEG
如何允许您生成缩略图的一个示例是:
const FFmpeg = require('fluent-ffmpeg');
new FFmpeg({ source: '/path/to/video.avi' })
.withSize('320x240')
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
})
.on('end', function(filenames) {
console.log('Successfully generated ' + filenames.join(', '));
})
.takeScreenshots(5, '/path/to/directory');