Welcome folks today in this blog post we will be using the fluent-ffmpeg
library to trim or cut
videos based on start and end
time in command line using javascript. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the below library using the npm
command as shown below
npm i fluent-ffmpeg
After that you need to make an index.js
file and copy paste the following code
index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
const ffmpeg = require('fluent-ffmpeg') ffmpeg({source:'video.mp4'}) .setStartTime('00:01:10') .duration(50) .on('start',(commandLine) => { console.log("Processing Started") }) .on('error',(err) => { console.log("error takes place") }) .on('end',() => { console.log("processing done") }) .saveToFile("cut.mp4") |
As you can see we are importing the fluent-ffmpeg
library and then we are calling it and passing the source
property where we provide the path of the input
video file and then we are calling the setStartTime()
to trim or cut the video at the specified time
duration and then we are using the duration()
method to trim the video for x
seconds. And then we are listening on various events such as start
,error and end
. And lastly we are saving the video
file with custom filename.