Something went wrong. Try again.
An entry for the streamplace vod showcase
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374/** * 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<CommandResult> { 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<CommandResult> { 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<ProbeResult> { 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)}