build video support

This commit is contained in:
2026-03-28 09:30:26 -05:00
parent 32bcdc94fc
commit f235987b3a
7 changed files with 141 additions and 47 deletions

View File

@@ -1,7 +1,11 @@
import sharp from 'sharp';
import fs from 'fs';
import { execFile } from 'child_process';
import { promisify } from 'util';
import { absolutePath, ensureDir } from './storage.js';
const execFileAsync = promisify(execFile);
export interface ImageMeta {
width: number;
height: number;
@@ -29,6 +33,30 @@ export async function extractMeta(filePath: string): Promise<ImageMeta> {
};
}
export async function extractVideoMeta(filePath: string, mimeType: string): Promise<ImageMeta> {
const abs = absolutePath(filePath);
const stat = fs.statSync(abs);
try {
const { stdout } = await execFileAsync('ffprobe', [
'-v', 'quiet',
'-print_format', 'json',
'-show_streams',
abs,
]);
const data = JSON.parse(stdout);
const video = (data.streams as any[])?.find((s) => s.codec_type === 'video');
return {
width: video?.width ?? 1280,
height: video?.height ?? 720,
mimeType,
size: stat.size,
};
} catch {
// ffprobe unavailable or failed — use safe defaults
return { width: 1280, height: 720, mimeType, size: stat.size };
}
}
export async function saveBuffer(buffer: Buffer, destRelPath: string): Promise<void> {
ensureDir(destRelPath);
const abs = absolutePath(destRelPath);