mirror of
https://github.com/misskey-dev/misskey.git
synced 2025-01-26 03:20:54 +09:00
fix: GenerateVideoThumbnail
This commit is contained in:
parent
90827ce4a8
commit
267d9a0906
@ -1,12 +1,10 @@
|
|||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import * as path from 'node:path';
|
import { createTempDir } from '@/misc/create-temp.js';
|
||||||
import { createTemp } from '@/misc/create-temp.js';
|
|
||||||
import { IImage, convertToJpeg } from './image-processor.js';
|
import { IImage, convertToJpeg } from './image-processor.js';
|
||||||
import FFmpeg from 'fluent-ffmpeg';
|
import FFmpeg from 'fluent-ffmpeg';
|
||||||
|
|
||||||
export async function GenerateVideoThumbnail(source: string): Promise<IImage> {
|
export async function GenerateVideoThumbnail(source: string): Promise<IImage> {
|
||||||
const [file, cleanup] = await createTemp();
|
const [dir, cleanup] = await createTempDir();
|
||||||
const parsed = path.parse(file);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await new Promise((res, rej) => {
|
await new Promise((res, rej) => {
|
||||||
@ -16,15 +14,15 @@ export async function GenerateVideoThumbnail(source: string): Promise<IImage> {
|
|||||||
.on('end', res)
|
.on('end', res)
|
||||||
.on('error', rej)
|
.on('error', rej)
|
||||||
.screenshot({
|
.screenshot({
|
||||||
folder: parsed.dir,
|
folder: dir,
|
||||||
filename: parsed.base,
|
filename: 'out.png', // must have .png extension
|
||||||
count: 1,
|
count: 1,
|
||||||
timestamps: ['5%'],
|
timestamps: ['5%'],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// JPEGに変換 (Webpでもいいが、MastodonはWebpをサポートせず表示できなくなる)
|
// JPEGに変換 (Webpでもいいが、MastodonはWebpをサポートせず表示できなくなる)
|
||||||
return await convertToJpeg(file, 498, 280);
|
return await convertToJpeg(`${dir}/out.png`, 498, 280);
|
||||||
} finally {
|
} finally {
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user