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 Change Video Resolution & Compress to Smaller Size in Command Line

Posted on January 24, 2023

 

 

 

Welcome folks today in this blog post we will be using the fluent-ffmpeg library to change the video resolution and compress to smaller size in node.js . All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to make a new node.js project using the below command as shown below

 

 

npm init -y

 

 

npm i fluent-ffmpeg

 

 

And 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
16
17
18
19
const ffmpeg = require('fluent-ffmpeg');
 
const inputPath = 'video.mp4';
const outputPath = 'output.mp4';
 
const width = 640;
const height = 480;
const bitrate = '800k';
 
ffmpeg(inputPath)
  .size(`${width}x${height}`)
  .videoBitrate(bitrate)
  .save(outputPath)
  .on('end', () => {
    console.log('Video resolution and file size have been changed successfully!');
  })
  .on('error', (err) => {
    console.log('Error: ' + err.message);
  });

 

 

As you can see we are importing the fluent-ffmpeg library and then we are providing the path of the input video file and then we are changing the bitrate using the videoBitrate() method and then we are compressing the size using the size() method. And then we are saving the video using the save() method.

 

Recent Posts

  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • 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
  • 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