Cut a Video in Specific Start & End Time Using Node Js

Some times in our work, we need to cut a video in specific start & end time. After searching a lot on google I found some way to get this done.

Here, we will use node js and ffmpeg to get our result. So let’s get started.

So, we are assuming that you have a running node on your machine.

I have written a detailed explanation to install node js. So, If you do not have node js on your machine. then make sure to install node js here.

var ffmpeg = require('fluent-ffmpeg');

ffmpeg('public/' + req.body.video)
.setStartTime('00:00:05')
.setDuration(10)
.output('public/videos/techyhunger/videofile.mp4')

.on('end', function(err) {   
  if(!err)
  {
    console.log('successfully converted');
  }                 

})
.on('error', function(err){
  console.log('conversion error: ', +err);

}).run();

Cut the Video in Specific Start & End using Command

you can cut part of a video from start position to end position using command.

Issue the command given below:

ffmpeg -ss [start] -i mainvideo.mp4 -t [duration] -c copy outputvideo.mp4

Now let’s understand all the options used in the above command:

  • -ss specifies the start time of the video, e.g. 00:00:15.000  (15 seconds)
  • -t indicates the duration of the video clip after cut.
  • -c copy copies the first video, audio, and subtitle from the input to the output file.

Using the above command you can cut the video in a specific start and end time.

Cut a Video From Start to End Position Example

let’s say if you have a video and you want to cut it 10 minutes long from the start time 1 hour 20 minutes.

So your syntax would be like:

ffmpeg -ss 01:20:00 -i inputvideo.avi -t 00:10:00 -c copy outputvideo.avi
or
ffmpeg -ss 01:20:00 -i inputvideo.avi -t 00:10:00 outputvideo.avi

Conclusion

There are a lot of tutorials you can find on the web for this task. You can also find a lot of methods to cut a part of the video. I have tested the above method and it is working fine for me.

You can get the best method by visiting the FFmpeg website yourself and read the latest documentation provided by them.

Let me know if you have any question regarding this topic. I will be really glad to answer your questions.

 

Leave a Reply