How to generate thumbnails from video ?

In this tutorial, you will learn how to generate thumbnails from a video file.

Warning!!! Please use small video files only, if your machine is low-end.

We will primarily use the fluent-ffmpeg library to perform the action.

For this, downl…


This content originally appeared on DEV Community and was authored by Lakshyaraj Dash

In this tutorial, you will learn how to generate thumbnails from a video file.

Warning!!! Please use small video files only, if your machine is low-end.

We will primarily use the fluent-ffmpeg library to perform the action.

For this, download the ffmpeg library from the official site of ffmpeg https://ffmpeg.org/.

Extract the zip and add the bin folder to your environment variables path.

Steps:

  1. Create a folder for the conversion, name it as video-thumbnail-generator .
  1. Initialize it as a nodejs package.
$ npm init -y
  1. Install the fluent ffmpeg library
$ npm install fluent-ffmpeg
  1. Import the library
const ffmpeg = require('fluent-ffmpeg')
  1. The first argument of the ffmpeg will be the path to the video file
ffmpeg('path_to_videofile')
  1. Take screenshot and save to the folder (Note: Multiple screenshots can be taken at a time, but we will take only 1)
ffmpeg('path_to_videofile')
  .screenshots({
     count: 1,
     filename: 'thumbnail-%s.png',
     folder: 'output_path/'
  })

Entire code

const ffmpeg = require('fluent-ffmpeg')
ffmpeg('path_to_videofile')
  .on('filenames', (filenames) => {
     console.log(filenames.join(', ') // Display the filenames to be generated
  })
  .on('end', () => {
     console.log('Screenshots taken!');
  })
  .screenshots({
     count: 1,
     filename: 'thumbnail-%s.png',
     folder: 'output_path/'
  })


This content originally appeared on DEV Community and was authored by Lakshyaraj Dash


Print Share Comment Cite Upload Translate Updates
APA

Lakshyaraj Dash | Sciencx (2024-06-23T07:55:41+00:00) How to generate thumbnails from video ?. Retrieved from https://www.scien.cx/2024/06/23/how-to-generate-thumbnails-from-video/

MLA
" » How to generate thumbnails from video ?." Lakshyaraj Dash | Sciencx - Sunday June 23, 2024, https://www.scien.cx/2024/06/23/how-to-generate-thumbnails-from-video/
HARVARD
Lakshyaraj Dash | Sciencx Sunday June 23, 2024 » How to generate thumbnails from video ?., viewed ,<https://www.scien.cx/2024/06/23/how-to-generate-thumbnails-from-video/>
VANCOUVER
Lakshyaraj Dash | Sciencx - » How to generate thumbnails from video ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/23/how-to-generate-thumbnails-from-video/
CHICAGO
" » How to generate thumbnails from video ?." Lakshyaraj Dash | Sciencx - Accessed . https://www.scien.cx/2024/06/23/how-to-generate-thumbnails-from-video/
IEEE
" » How to generate thumbnails from video ?." Lakshyaraj Dash | Sciencx [Online]. Available: https://www.scien.cx/2024/06/23/how-to-generate-thumbnails-from-video/. [Accessed: ]
rf:citation
» How to generate thumbnails from video ? | Lakshyaraj Dash | Sciencx | https://www.scien.cx/2024/06/23/how-to-generate-thumbnails-from-video/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.