Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cut a video in specific start & end time in ffmpeg by Node JS?

I want to cut a video in specific start & end time & save it. I am able to copy a full video but cant understand to how to cut specific time of that video by Node JS.

Video copy code :

  ffmpeg('public/'+req.body.video)
    .on('end', function(err) {   
        if(!err)
        {
          console.log('Done');

        }                 

    })
    .on('error', function(err){
        console.log('error: '+err);
        callback(err);
    }).run();
like image 750
Bilash Avatar asked Jun 25 '15 09:06

Bilash


1 Answers

I have found a solution. Here it is :

const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path
const ffmpeg = require('fluent-ffmpeg')
ffmpeg.setFfmpegPath(ffmpegPath)

ffmpeg('video.mp4')
  .setStartTime('00:00:03')
  .setDuration('10')
  .output('video_out.mp4')
  .on('end', function(err) {
    if(!err) { console.log('conversion Done') }
  })
  .on('error', err => console.log('error: ', err))
  .run()

Note that you should install these two:

npm install @ffmpeg-installer/ffmpeg
npm install fluent-ffmpeg
like image 150
Bilash Avatar answered Oct 22 '22 10:10

Bilash