user15324999
user15324999

Reputation: 81

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.. 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;

Upvotes: 2

Views: 1234

Answers (1)

albo
albo

Reputation: 51

See the thing is that fluent-ffmpeg provides you with functions to work with ffprobe and ffmpeg it does not provide you with them(so you have to install them manually in short). Other way would be to install 2 more libararies @ffmpeg-installer/ffmpeg and @ffprobe-installer/ffprobe and pass thr path into fluent.ffmpeg.Here

Upvotes: 1

Related Questions