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