2

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;
  • verify just the file upload part - no ffmpeg - to be sure where in the code the asnych #1 ( upld ) completes. that is where your callback w ffmpeg piece should go - just follow the fluent docs as u have normal use case for the ffmpeg part. make sure ffmpeg is NOT being called PRIOR to the 'onComplete' event on the upload part. – Robert Rowntree Mar 06 '21 at 16:37
  • can u provide me some example on this code i post? – user15324999 Mar 06 '21 at 16:47

1 Answers1

1

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

albo
  • 41
  • 7
  • i did install everything and used your code but now im getting: Error: ffmpeg exited with code 1: uploads/videos/cd302570-7ebf-11eb-98c1-a19b59997719.mp4: Invalid data found when processing input @ this is my currently code : https://pastebin.com/nxyvFf3X – user15324999 Mar 06 '21 at 21:10
  • Are you sure that the video you are trying to upload has 10 seconds, since you are taking a screenshot at 10th second. Also there seems to be issue with `[mov,mp4,m4a,3gp,3g2,mj2 @ 00000000001345c0] moov atom not found` this not ffmpeg problem i guess.... got that from your stack trance. – albo Mar 07 '21 at 08:55
  • Thanks, idk how i fixed i didnt change nothing but my code working now without errors :) – user15324999 Mar 07 '21 at 13:27
  • It seems like it was a problem with online convertor i used :) – user15324999 Mar 07 '21 at 13:49
  • If the code worked kindly mark the answer as right. Thanks – albo Mar 08 '21 at 12:45