Welcome folks today in this blog post we will be converting mp4 video to images
at custom time
using takeScreenshots()
method 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
After that you need to install the below dependencies
using the below command as shown below
npm i fluent-ffmpeg
After that you need to make the 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"); ffmpeg({ source: "./video.mp4" }) .on("filenames", (filenames) => { console.log("Created file names", filenames); }) .on("end", () => { console.log("Job done"); }) .on("error", (err) => { console.log("Error", err); }) .takeScreenshots( { filename: "example.jpg", timemarks: [2, 4], }, "images" ); |
As you can see we are importing the fluent-ffmpeg
library and then we are loading the video.mp4
file and then we are taking the screenshot
or thumbnail
of the video file at certain seconds using the takeScreenshots()
method. And then we are passing the object in which we are passing the filename
as well. And we have various events we are listening on for starting and end
and also for error events as well.
And now if you execute the node.js
script this will create the images
folder where the screenshots are taken as shown below
node index.js