import { execFile } from 'node:child_process'; import { promisify } from 'node:util'; const execFileAsync = promisify(execFile); export async function analyzeWithFfprobe(path: string): Promise { const { stdout } = await execFileAsync('ffprobe', [ '-v', 'error', '-print_format', 'json', '-show_streams', '-show_format', path ]); const json = JSON.parse(stdout); const video = (json.streams || []).find((s: any) => s.codec_type === 'video'); const audio = (json.streams || []) .filter((s: any) => s.codec_type === 'audio') .map((s: any) => ({ codec_name: s.codec_name, channels: s.channels, language: s.tags?.language })); return { video: video ? { codec_name: video.codec_name, width: video.width, height: video.height, r_frame_rate: video.r_frame_rate } : null, audio, format: { duration: json.format?.duration, bit_rate: json.format?.bit_rate, format_name: json.format?.format_name } }; } export function fallbackMediaInfo(): any { return { video: { codec_name: 'unknown', width: 1920, height: 1080, r_frame_rate: '24/1' }, audio: [{ codec_name: 'unknown', channels: 2, language: 'und' }], format: { duration: '0', bit_rate: '0', format_name: 'matroska' } }; }