mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Get video dimensions from frame
This commit is contained in:
parent
5168ccd748
commit
7e8ff1f329
1 changed files with 5 additions and 7 deletions
|
|
@ -108,25 +108,23 @@ export async function uploadFile(
|
||||||
perf.mark('analyze-start');
|
perf.mark('analyze-start');
|
||||||
|
|
||||||
if (baseType === 'video' && mediaAnalyze && mediaTranscode && video && (!image || !thumb)) {
|
if (baseType === 'video' && mediaAnalyze && mediaTranscode && video && (!image || !thumb)) {
|
||||||
const { width, height } = video;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const tmp = new URL('file://' + await Deno.makeTempFile());
|
const tmp = new URL('file://' + await Deno.makeTempFile());
|
||||||
await Deno.writeFile(tmp, file.stream());
|
await Deno.writeFile(tmp, file.stream());
|
||||||
const bytes = await extractVideoFrame(tmp, '00:00:01', { ffmpegPath });
|
const frame = await extractVideoFrame(tmp, '00:00:01', { ffmpegPath });
|
||||||
await Deno.remove(tmp);
|
await Deno.remove(tmp);
|
||||||
const [[, url]] = await uploader.upload(new File([bytes], 'thumb.jpg', { type: 'image/jpeg' }), { signal });
|
const [[, url]] = await uploader.upload(new File([frame], 'thumb.jpg', { type: 'image/jpeg' }), { signal });
|
||||||
|
|
||||||
if (!image) {
|
if (!image) {
|
||||||
tags.push(['image', url]);
|
tags.push(['image', url]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dim && width && height) {
|
if (!dim) {
|
||||||
tags.push(['dim', `${width}x${height}`]);
|
tags.push(['dim', await getImageDim(frame)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!blurhash) {
|
if (!blurhash) {
|
||||||
tags.push(['blurhash', await getBlurhash(bytes)]);
|
tags.push(['blurhash', await getBlurhash(frame)]);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logi({ level: 'error', ns: 'ditto.upload.analyze', error: errorJson(e) });
|
logi({ level: 'error', ns: 'ditto.upload.analyze', error: errorJson(e) });
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue