
* wip * Update packages/client/src/os.ts Co-authored-by: tamaina <tamaina@hotmail.co.jp> * メニューをComposition API化、switchアイテム追加 クライアントサイド画像圧縮の準備 * メニュー型定義を分離 (TypeScriptの型支援が効かないので) * disabled * make keepOriginal to follow setting value * ✌️ * fix * fix * ✌️ * WEBP * aaa * ✌️ * webp * lazy load browser-image-resizer * rename * rename 2 * Fix * clean up * add comment * clean up * jpeg, pngにもどす * fix * fix name * webpでなくする ただしサムネやプレビューはwebpのまま (テスト) * 動画サムネイルはjpegに * エラーハンドリング * ✌️ * v2.2.1-misskey-beta.2 * browser-image-resizer#v2.2.1-misskey.1 * ✌️ * fix alert * update browser-image-resizer to v2.2.1-misskey.2 * lockfile Co-authored-by: mei23 <m@m544.net> Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com>
39 lines
916 B
TypeScript
39 lines
916 B
TypeScript
import * as fs from 'node:fs';
|
|
import * as tmp from 'tmp';
|
|
import { IImage, convertToJpeg } from './image-processor.js';
|
|
import * as FFmpeg from 'fluent-ffmpeg';
|
|
|
|
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]);
|
|
});
|
|
});
|
|
|
|
await new Promise((res, rej) => {
|
|
FFmpeg({
|
|
source: path,
|
|
})
|
|
.on('end', res)
|
|
.on('error', rej)
|
|
.screenshot({
|
|
folder: outDir,
|
|
filename: 'output.png',
|
|
count: 1,
|
|
timestamps: ['5%'],
|
|
});
|
|
});
|
|
|
|
const outPath = `${outDir}/output.png`;
|
|
|
|
// JPEGに変換 (Webpでもいいが、MastodonはWebpをサポートせず表示できなくなる)
|
|
const thumbnail = await convertToJpeg(outPath, 498, 280);
|
|
|
|
// cleanup
|
|
await fs.promises.unlink(outPath);
|
|
cleanup();
|
|
|
|
return thumbnail;
|
|
}
|