mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-24 04:59:06 +01:00
0a8cff4f3c
* Refactor * settings * Media Proxy * Replace API response
34 lines
782 B
TypeScript
34 lines
782 B
TypeScript
import * as fs from 'fs';
|
|
import * as tmp from 'tmp';
|
|
import { IImage, ConvertToJpeg } from './image-processor';
|
|
const ThumbnailGenerator = require('video-thumbnail-generator').default;
|
|
|
|
export async function GenerateVideoThumbnail(path: string): Promise<IImage> {
|
|
const [outDir, cleanup] = await new Promise<[string, any]>((res, rej) => {
|
|
tmp.dir((e, path, cleanup) => {
|
|
if (e) return rej(e);
|
|
res([path, cleanup]);
|
|
});
|
|
});
|
|
|
|
const tg = new ThumbnailGenerator({
|
|
sourcePath: path,
|
|
thumbnailPath: outDir,
|
|
});
|
|
|
|
await tg.generateOneByPercent(5, {
|
|
size: '100%',
|
|
filename: 'output.png',
|
|
});
|
|
|
|
const outPath = `${outDir}/output.png`;
|
|
|
|
const thumbnail = await ConvertToJpeg(outPath, 498, 280);
|
|
|
|
// cleanup
|
|
fs.unlinkSync(outPath);
|
|
cleanup();
|
|
|
|
return thumbnail;
|
|
}
|