Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Node.js Fluent-FFMPEG Example to Trim or Cut Videos Based on Start & End Time in Command Line

Posted on January 17, 2023

 

 

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

 

 

JavaScript
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.

 

Recent Posts

  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Android Java Project to Download Youtube Video Thumbnail From URL & Save it inside SD Card
  • Android Java Project to Embed Google Maps & Add Markers Using Maps SDK
  • Android Java Project to Download Random Image From Unsplash Using OkHttp & Picasso Library & Display it
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme