Taking video screenshot in NodeJs using FFMPEG
Please install fluent-ffmpeg library and import it in your file like below
var ffmpeg = require(‘fluent-ffmpeg’);
If you are window users please download ffmpeg.exe and ffprobe.exe from below location
After downloading please mention the path of the binaries in the same file
ffmpeg.setFfmpegPath(“D:\\ffmpeg.exe”);
ffmpeg.setFfprobePath(“D:\\ffprobe.exe”);
If you are linux users please install FFMPEG globally from below link and please don’t use above two line in this case
https://linuxize.com/post/how-to-install-ffmpeg-on-ubuntu-18-04/
Below is the code to take snapshot.
if (file.type.match(‘video.*’)) {
ffmpeg(file.path)
.on(‘end’, function () {
console.log(‘Screenshots taken’);
})
.on(‘error’, function (err) {
console.error(‘this error:’);
console.error(err);
}).screenshots({
count: 1,
timemarks: [‘0’],
filename: “screenhot.jpg”,
folder: __dirname + ‘/folderName/’
});
}
Note :- Please pass file object.
Please let me know in-case of any improvement or queries.