mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-28 12:43:08 +02:00
parent
2b0cb6d728
commit
84931003ea
2 changed files with 14 additions and 6 deletions
|
@ -122,8 +122,6 @@ async function save(path: string, name: string, type: string, hash: string, size
|
|||
} else if (type.startsWith('video/')) {
|
||||
try {
|
||||
thumbnail = await GenerateVideoThumbnail(path);
|
||||
thumbnailExt = 'png';
|
||||
thumbnailType = 'image/png';
|
||||
} catch (e) {
|
||||
console.log(`GenerateVideoThumbnail failed: ${e}`);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as fs from 'fs';
|
||||
import * as tmp from 'tmp';
|
||||
import * as sharp from 'sharp';
|
||||
const ThumbnailGenerator = require('video-thumbnail-generator').default;
|
||||
|
||||
export async function GenerateVideoThumbnail(path: string): Promise<Buffer> {
|
||||
|
@ -15,18 +16,27 @@ export async function GenerateVideoThumbnail(path: string): Promise<Buffer> {
|
|||
thumbnailPath: outDir,
|
||||
});
|
||||
|
||||
await tg.generateOneByPercent(10, {
|
||||
size: '498x280',
|
||||
await tg.generateOneByPercent(5, {
|
||||
size: '100%',
|
||||
filename: 'output.png',
|
||||
});
|
||||
|
||||
const outPath = `${outDir}/output.png`;
|
||||
|
||||
const buffer = fs.readFileSync(outPath);
|
||||
const thumbnail = await sharp(outPath)
|
||||
.resize(498, 280, {
|
||||
fit: 'inside',
|
||||
withoutEnlargement: true
|
||||
})
|
||||
.jpeg({
|
||||
quality: 85,
|
||||
progressive: true
|
||||
})
|
||||
.toBuffer();
|
||||
|
||||
// cleanup
|
||||
fs.unlinkSync(outPath);
|
||||
cleanup();
|
||||
|
||||
return buffer;
|
||||
return thumbnail;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue