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 Convert Video to Images at Custom Time Using takeScreenshots() in Command Line

Posted on January 23, 2023

 

 

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

 

 

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");
 
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

 

 

 

 

Recent Posts

  • Node.js Express Passwordless Login Example to Send Magic Auth Link Using Nodemailer
  • Python 3 Tkinter Script to Encrypt PDF Documents With Password Using PyPDF2 Library GUI Desktop App
  • Node.js Express Project to Upload Image Buffer & BLOB Data to MongoDB Database & Display it in Browser Using Javascript
  • Node.js Tutorial to Export Images to PDF Document With Effects Using FilePix Library in Javascript
  • Node.js Tutorial to Export All Pages of PDF Document to Images and Save it in Javascript
  • 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