Add video thumbnail support.

This commit is contained in:
Patrick Fic
2022-05-13 10:16:42 -07:00
parent fc37f09e6b
commit fa0213ce99
4 changed files with 121 additions and 2 deletions

View File

@@ -8,6 +8,9 @@ import core from "file-type/core";
import GenerateUrl from "./MediaUrlGen";
import { FolderPaths } from "./serverInit";
import { logger } from "../server";
const simpleThumb = require("simple-thumbnail");
const ffmpeg = require("ffmpeg-static");
var Bluebird = require("bluebird");
Bluebird.promisifyAll(gm.prototype);
@@ -39,6 +42,10 @@ export default async function GenerateThumbnail(
if (type?.mime === "application/pdf") {
const fileOnDisk: Buffer = await fs.readFile(file);
await GeneratePdfThumbnail(file, thumbPath);
} else if (type?.mime.startsWith("video")) {
await simpleThumb(file, thumbPath, "250x?", {
path: ffmpeg,
});
} else {
logger.debug("Thumbnail being created for : " + thumbPath);
const thumbnail = await imageThumbnail(file, {
@@ -51,7 +58,11 @@ export default async function GenerateThumbnail(
}
return path.relative(path.dirname(file), thumbPath);
} catch (err) {
logger.error("Error when genenerating thumbnail:", { thumbPath, err });
logger.error("Error when genenerating thumbnail:", {
thumbPath,
err,
message: (err as Error).message,
});
return path.relative(path.dirname(file), thumbPath);
}
}