Get video dimensions from frame

This commit is contained in:
Alex Gleason 2025-03-01 22:15:32 -06:00
parent 5168ccd748
commit 7e8ff1f329
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -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) });