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.. Heres my full code for video-upload:
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;