![](/img/trans.png)
[英]Creating Thumbnail of Video from screenshot using Fluent FFMPEG in Node JS
[英]node js fluent-ffmpeg creating thumbnail
currently im working on some video uploads, so i wanted to create a thumbnail during upload of videos.. I installated fluent-ffmpeg package but on first run i got error Error: cannnot find ffprobe then i changed ffmpeg to ffmpeg.ffprobe then i got 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, file, 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, file, cb) => {
const isValid = !!MIME_TYPE_MAP[file.mimetype];
let error = isValid ? null : new Error('Invalid mime type!');
cb(error, isValid);
}
});
module.exports = videoUpload;
看到的事情是fluent-ffmpeg
為您提供了與ffprobe and ffmpeg
一起使用的功能,它沒有為您提供它們(因此您必須手動安裝它們)。 其他方法是再安裝 2 個庫@ffmpeg-installer/ffmpeg
和@ffprobe-installer/ffprobe
並將路徑傳遞到fluent.ffmpeg
。 這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.