Node Js

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.

 

Avinash

Share
Published by
Avinash

Recent Posts

JavaScript filter() Function | Array.prototype.filter()

If you don't know about JavaScript filter() function then this tutorial is for you. In…

1 year ago

How to Install and Set Up Bower On Windows 10

In this tutorial, we will learn how to install bower on windows 10. But, before…

1 year ago

JavaScript reduce() Method | Array.prototype.reduce()

JavaScript reduce() method tutorial is the topic, we are going to understand today. So what…

1 year ago

Angular HttpClient get & post Request (GET & Post)

In this post, we will understand Angular HttpClient with example. When Angular version 4.3 launched,…

1 year ago

How to Redirect domain according to country IP using PHP| .htaccess

In this tutorial, we will know how to redirect domain according to a country IP…

1 year ago

How to Install MongoDB on Ubuntu & macOS

Introduction to MongoDB MongoDB is an open-source, NoSQL document database designed for development. This guide…

1 year ago

This website uses cookies.