import json import subprocess from pathlib import Path def ffprobe_json(path: Path) -> dict: cmd = [ "ffprobe", "-v", "error", "-print_format", "json", "-show_format", "-show_streams", str(path) ] p = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) if p.returncode != 0: return {"error": p.stderr[-1600:]} try: return json.loads(p.stdout) except Exception: return {"error": "Failed to parse ffprobe output."}