mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Extract a poster image from videos (not efficient yet)
This commit is contained in:
parent
813026e734
commit
43ec58085a
1 changed files with 19 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { transcodeVideo } from '@ditto/transcode';
|
||||
import { extractVideoFrame, transcodeVideo } from '@ditto/transcode';
|
||||
import { HTTPException } from '@hono/hono/http-exception';
|
||||
import { logi } from '@soapbox/logi';
|
||||
import { crypto } from '@std/crypto';
|
||||
|
|
@ -62,6 +62,8 @@ export async function uploadFile(
|
|||
const m = tags.find(([key]) => key === 'm')?.[1];
|
||||
const dim = tags.find(([key]) => key === 'dim')?.[1];
|
||||
const size = tags.find(([key]) => key === 'size')?.[1];
|
||||
const image = tags.find(([key]) => key === 'image')?.[1];
|
||||
const thumb = tags.find(([key]) => key === 'thumb')?.[1];
|
||||
const blurhash = tags.find(([key]) => key === 'blurhash')?.[1];
|
||||
|
||||
if (!x) {
|
||||
|
|
@ -77,6 +79,22 @@ export async function uploadFile(
|
|||
tags.push(['size', file.size.toString()]);
|
||||
}
|
||||
|
||||
if (baseType === 'video' && (!image || !thumb)) {
|
||||
const tmp = new URL('file://' + await Deno.makeTempFile());
|
||||
await Deno.writeFile(tmp, file.stream());
|
||||
const bytes = await extractVideoFrame(tmp);
|
||||
const [[, url]] = await uploader.upload(new File([bytes], 'thumb.jpg', { type: 'image/jpeg' }), { signal });
|
||||
await Deno.remove(tmp);
|
||||
|
||||
if (!image) {
|
||||
tags.push(['image', url]);
|
||||
}
|
||||
|
||||
if (!thumb) {
|
||||
tags.push(['thumb', url]);
|
||||
}
|
||||
}
|
||||
|
||||
// If the uploader didn't already, try to get a blurhash and media dimensions.
|
||||
// This requires `MEDIA_ANALYZE=true` to be configured because it comes with security tradeoffs.
|
||||
if (conf.mediaAnalyze && (!blurhash || !dim)) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue