dev-resources.site
for different kinds of informations.
How to generate thumbnails from video ?
Published at
6/23/2024
Categories
ffmpeg
javascript
node
Author
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:
- Create a folder for the conversion, name it as
video-thumbnail-generator
.
- Initialize it as a nodejs package.
$ npm init -y
- Install the fluent ffmpeg library
$ npm install fluent-ffmpeg
- Import the library
const ffmpeg = require('fluent-ffmpeg')
- The first argument of the ffmpeg will be the path to the video file
ffmpeg('path_to_videofile')
- 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/'
})
Articles
12 articles in total
How to generate thumbnails from video ?
currently reading
CRUD App Using Binary files in python
read article
How to find mean, median & mode of the elements of a tuple or list (no statistics module used) ?
read article
Custom HTML video player
read article
How to record your screen on Windows ?
read article
How to code almost every programming language in your phone ?
read article
Is c++ getting old ? What to do now ?
read article
TicTacToe game using python
read article
How to convert decimal number to bin, octal and hex format using python ?
read article
Create a rest api using expressjs and postgresql
read article
How to send emails using python django ?
read article
How to find the odd and even numbers in python ?
read article
Featured ones: