node js fluent-ffmpeg 创建缩略图

问题描述

目前我正在处理一些视频上传,所以我想在上传视频的过程中创建一个缩略图..我安装了 fluent-ffmpeg 包,但在第一次运行时出现错误 Error: cannnot find ffprobe 然后我将 ffmpeg 改为 ffmpeg.ffprobe 然后我得到了 undefined .on .. 这是我用于视频上传的完整代码

const multer = require('multer');
const uuid = require('uuid/v1');
const ffmpeg = require('fluent-ffmpeg');


const MIME_TYPE_MAP = {
  'video/MPEG-4': 'MPEG-4','video/mpeg-4': 'mpeg-4','video/mp4': 'mp4','video/MP4': 'MP4'
};

const videoUpload = multer({
  limits: 10000000,storage: multer.diskStorage({
    destination: (req,file,cb) => {
      cb(null,'uploads/videos');
    },filename: (req,cb) => {
      const ext = MIME_TYPE_MAP[file.mimetype];
      const currentfilename = uuid() + '.' + ext;
      cb(null,currentfilename);

      
      ffmpeg.ffprobe(`uploads/videos/${currentfilename}`)
      .on('end',function() {
        console.log('Screenshots taken');
      })
      .on('error',function(err) {
        console.error(err);
      })
      .screenshots({
        count: 1,folder: 'uploads/videos/thumb',filename: uuid() + '_screenshot.' + ext
      });
    }
  }),fileFilter: (req,cb) => {
    const isValid = !!MIME_TYPE_MAP[file.mimetype];
    let error = isValid ? null : new Error('Invalid mime type!');
    cb(error,isValid);
  }

});

module.exports = videoUpload;

解决方法

问题是 pipeline { agent any stages { stage("ARCHIVE DIST ARTIFACTS") { steps{ archiveArtifacts artifacts: 'dist',followSymlinks: false } } stage("COPY DIST") { steps{ copyArtifacts fingerprintArtifacts: true,projectName: 'ev-frontend',target: '/opt/front-end' } } } } 为您提供了与 fluent-ffmpeg 一起使用的功能,但它没有为您提供(因此您必须手动安装它们)。其他方法是再安装 2 个库 ffprobe and ffmpeg@ffmpeg-installer/ffmpeg 并将 thr 路径传递到 @ffprobe-installer/ffprobeHere

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...