(a: z.infer<typeof ProbeArgs>)
| 25 | isReadOnly = true; isDestructive = false; argsSchema = ProbeArgs; |
| 26 | |
| 27 | async execute(a: z.infer<typeof ProbeArgs>): Promise<ToolResult> { |
| 28 | const r = await runProcess('ffprobe', ['-v', 'quiet', '-print_format', 'json', '-show_format', '-show_streams', a.file], { timeoutMs: 30_000 }); |
| 29 | if (r.notFound) return { content: notInstalledMessage('ffprobe', FFMPEG_HINT), isError: true }; |
| 30 | if (!r.ok) return { content: (r.stderr || r.stdout).trim() || 'ffprobe failed', isError: true }; |
| 31 | try { |
| 32 | const data = JSON.parse(r.stdout); |
| 33 | const fmt = data.format ?? {}; |
| 34 | const lines: string[] = []; |
| 35 | lines.push(`File: ${fmt.filename ?? a.file}`); |
| 36 | lines.push(`Format: ${fmt.format_long_name ?? fmt.format_name}`); |
| 37 | if (fmt.duration) lines.push(`Duration: ${Number(fmt.duration).toFixed(2)}s`); |
| 38 | if (fmt.bit_rate) lines.push(`Bitrate: ${Math.round(Number(fmt.bit_rate) / 1000)} kbps`); |
| 39 | if (fmt.size) lines.push(`Size: ${(Number(fmt.size) / 1048576).toFixed(2)} MB`); |
| 40 | for (const s of data.streams ?? []) { |
| 41 | if (s.codec_type === 'video') { |
| 42 | const fps = s.r_frame_rate && s.r_frame_rate !== '0/0' |
| 43 | ? (() => { const [n, d] = s.r_frame_rate.split('/').map(Number); return d ? (n / d).toFixed(2) : s.r_frame_rate; })() |
| 44 | : '?'; |
| 45 | lines.push(` video: ${s.codec_name} ${s.width}x${s.height} @ ${fps}fps${s.pix_fmt ? ` (${s.pix_fmt})` : ''}`); |
| 46 | } else if (s.codec_type === 'audio') { |
| 47 | lines.push(` audio: ${s.codec_name} ${s.sample_rate ? s.sample_rate + 'Hz' : ''} ${s.channels ? s.channels + 'ch' : ''}`); |
| 48 | } else { |
| 49 | lines.push(` ${s.codec_type}: ${s.codec_name}`); |
| 50 | } |
| 51 | } |
| 52 | return { content: lines.join('\n') }; |
| 53 | } catch { |
| 54 | return { content: r.stdout.slice(0, 4000) }; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // ---- media_transform ---- |
nothing calls this directly
no test coverage detected