提问者:小点点

如何使用NodeJS在微软Azure功能中生成视频缩略图?


这个图像缩略图生成器功能是触发时,上传一个图像到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);

                }

            });

    });


};

共1个答案

匿名用户

有多个节点模块可以帮助您从视频生成缩略图。 您可以使用以下任一项:

  1. 视频缩略图生成器(https://www.npmjs.com/package/video-thumbnail-generator)
  2. Fluent-FFMPEG https://www.npmjs.com/package/fluent-FFMPEG/v/1.7.0#生成-缩略图

在您的示例中,由于您计划为图像和视频生成缩略图,我建议使用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');