From 7e8ff1f329aca7ca6f999a6674a98d53aaadf330 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 1 Mar 2025 22:15:32 -0600 Subject: [PATCH] Get video dimensions from frame --- packages/ditto/utils/upload.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/ditto/utils/upload.ts b/packages/ditto/utils/upload.ts index 94d627e3..fc0316e8 100644 --- a/packages/ditto/utils/upload.ts +++ b/packages/ditto/utils/upload.ts @@ -108,25 +108,23 @@ export async function uploadFile( perf.mark('analyze-start'); if (baseType === 'video' && mediaAnalyze && mediaTranscode && video && (!image || !thumb)) { - const { width, height } = video; - try { const tmp = new URL('file://' + await Deno.makeTempFile()); 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); - 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) { tags.push(['image', url]); } - if (!dim && width && height) { - tags.push(['dim', `${width}x${height}`]); + if (!dim) { + tags.push(['dim', await getImageDim(frame)]); } if (!blurhash) { - tags.push(['blurhash', await getBlurhash(bytes)]); + tags.push(['blurhash', await getBlurhash(frame)]); } } catch (e) { logi({ level: 'error', ns: 'ditto.upload.analyze', error: errorJson(e) });