Sych Octo
Sych Octo

Reputation: 11

Trim Video before uploading using multer and gridfs

Good day! I am currently working on uploading video however I would like to trim it to 3 mins before uploading to my mongodb. I am using Multer and GridFS, upon checking on Multer, It was directly uploaded to my mongodb, Is there a way to trim it before uploading or any package to trim video before uploading to my mongodb?

here is my code


const multer = require('multer')
const upload = multer({ dest: 'uploads/'}).single('demo_file')


app.get('/', (req, res) => {
  res.send('hello world');
})

app.post("/upload-file", (req, res) => {

  console.log('req', req)

  upload(req, res, (err) => {
    const options = [
      '-crf 23',
      '-preset',
      'veryslow',
      '-vtag',
      'DIVX',
      '-t 180',
      '-c:a aac',
      '-b:a 480k',
      '-b:v 480k'
  ]
  
    ffmpeg(req.file.filename)
    .addOptions(options)
    .output(req.file.originalname + '-1280x720.mp4')
    .aspect('16:9')
    .size('50%')
    .fps(30)
    .audioCodec('libmp3lame')
    .audioChannels(2)
    .format('avi')
    .on('error', (e) => {
      console.error('Err' + e.message)
    })
    .on('end', () => {
      console.log('End')
    })
    .save(`./uploads/${req.filename}.mp4`)
   if(err) {
     res.status(400).send("Something went wrong!");
   }
   res.send(req.file);
 });
});

Upvotes: 1

Views: 62

Answers (0)

Related Questions