-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrabThumbs.js
50 lines (43 loc) · 1.41 KB
/
grabThumbs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const fs = require("fs");
const ffmpeg = require("fluent-ffmpeg");
const videosDir = "./public/videos";
const thumbnailsDir = "./public/images/thumbnails";
fs.readdir(videosDir, (err, files) => {
if (err) {
console.error("Error reading the videos directory", err);
return;
}
files.forEach((file) => {
const videoPath = `${videosDir}/${file}`;
const thumbnailPath = `${thumbnailsDir}/${file.split(".")[0]}.jpg`;
ffmpeg.ffprobe(videoPath, (err, metadata) => {
if (!metadata) {
console.error(`Error getting metadata for file: ${file}`);
return;
}
console.log(metadata);
let meta = metadata.streams[0];
let ratio = meta.display_aspect_ratio.split(":");
ratio = ratio[0] / ratio[1];
let width = Math.round(meta.height * ratio);
let height = meta.height;
ffmpeg(videoPath).screenshots({
timestamps: ["0.10"],
filename: file.split(".")[0] + ".jpg",
folder: thumbnailsDir,
size: width + "x" + height,
});
// ffmpeg(videoPath)
// // Ensure video has an aspect ratio of 1.5
// .size(`${width}x${height}`)
// .frames(1)
// .on("end", () => {
// console.log(`Thumbnail created for ${file}`);
// })
// .on("error", (err) => {
// console.error(`Error processing ${file}:`, err);
// })
// .save(thumbnailPath);
});
});
});