/** * FFmpeg/FFprobe wrapper using Deno.Command * Works in the Deno sandbox with run: ["ffmpeg", "ffprobe"] permission */ interface CommandResult { success: boolean stdout: string stderr: string } export async function ffmpeg(args: string[]): Promise { const cmd = new Deno.Command("ffmpeg", { args, stdout: "piped", stderr: "piped", }) const { success, stdout, stderr } = await cmd.output() return { success, stdout: new TextDecoder().decode(stdout), stderr: new TextDecoder().decode(stderr), } } export async function ffprobe(args: string[]): Promise { const cmd = new Deno.Command("ffprobe", { args, stdout: "piped", stderr: "piped", }) const { success, stdout, stderr } = await cmd.output() return { success, stdout: new TextDecoder().decode(stdout), stderr: new TextDecoder().decode(stderr), } } export interface ProbeResult { format: { duration: number size: number bit_rate: number } streams: Array<{ codec_type: string codec_name: string width?: number height?: number }> } export async function probe(input: string): Promise { const result = await ffprobe([ "-protocol_whitelist", "file,http,https,tcp,tls,crypto", "-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", input, ]) if (!result.success) { throw new Error(`ffprobe failed: ${result.stderr}`) } return JSON.parse(result.stdout) }