【问题标题】:How to generate video thumbnail in Microsoft Azure function using Nodejs?如何使用 Nodejs 在 Microsoft Azure 功能中生成视频缩略图?
【发布时间】:2020-07-28 14:11:58
【问题描述】:

此图像缩略图生成器功能在将图像上传到 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);

                }

            });

    });


};

【问题讨论】:

标签: node.js azure containers azure-functions devops


【解决方案1】:

有多个node modules 可以帮助您从视频中生成缩略图。 您可以使用以下任何一种:

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

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

【讨论】:

    猜你喜欢
    • 2019-07-26
    • 2018-09-04
    • 1970-01-01
    • 2012-10-16
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-15
    相关资源
    最近更新 更多