{"record":{"id":"35efaa00926413d4","repo":"harry0703/MoneyPrinterTurbo","slug":"failed-to-run-ffmpeg-for-sonilo-video-proxy","errorCode":null,"errorMessage":"failed to run FFmpeg for Sonilo video proxy","messagePattern":"failed to run FFmpeg for Sonilo video proxy","errorType":"exception","errorClass":"SoniloError","httpStatus":null,"severity":"critical","filePath":"app/services/sonilo.py","lineNumber":188,"sourceCode":"        \"yuv420p\",\n        \"-movflags\",\n        \"+faststart\",\n        proxy_path,\n    ]\n    try:\n        result = subprocess.run(\n            command,\n            capture_output=True,\n            text=True,\n            timeout=600,\n            check=False,\n        )\n    except subprocess.TimeoutExpired as exc:\n        _remove_file(proxy_path)\n        raise SoniloError(\"Sonilo video proxy generation timed out\") from exc\n    except OSError as exc:\n        _remove_file(proxy_path)\n        raise SoniloError(\"failed to run FFmpeg for Sonilo video proxy\") from exc\n    if result.returncode != 0:\n        _remove_file(proxy_path)\n        detail = (result.stderr or \"\").strip().replace(\"\\n\", \" \")[-500:]\n        raise SoniloError(f\"failed to generate Sonilo video proxy: {detail}\")\n    proxy_size = os.path.getsize(proxy_path) if os.path.isfile(proxy_path) else 0\n    if proxy_size <= 0 or proxy_size > MAX_PROXY_BYTES:\n        _remove_file(proxy_path)\n        raise SoniloError(\"Sonilo video proxy is empty or exceeds the 300 MB limit\")\n    logger.info(\n        f\"Sonilo video proxy prepared: source={video_path}, size={proxy_size} bytes\"\n    )\n    return proxy_path\n\n\ndef _parse_event(raw_line: bytes) -> dict[str, Any]:\n    \"\"\"严格解析单条 NDJSON，禁止静默忽略截断或非对象响应。\"\"\"\n    try:\n        event = json.loads(raw_line.decode(\"utf-8\"))","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/app/services/sonilo.py#L170-L206","documentation":"Raised when launching the FFmpeg subprocess itself raises OSError; the classic case is FileNotFoundError because the ffmpeg executable is not on PATH. It is distinct from a timeout (error 82) or a non-zero FFmpeg exit (error 84): the process never started, so there is no stderr detail to include.","triggerScenarios":"ffmpeg not installed on the host or not on the PATH of the process running the app; PATH stripped in a systemd or docker environment; ffmpeg installed as a snap or flatpak not visible to the service user; exec permission bits missing on the binary.","commonSituations":"Fresh deployment to a minimal Docker image (python slim variants) without the ffmpeg package; systemd service with a restricted PATH; running under a different user than the one that installed ffmpeg.","solutions":["Run 'which ffmpeg' as the same user and environment the app runs under; install it if missing (apt-get install -y ffmpeg or apk add ffmpeg).","For Docker images, add ffmpeg to the image build rather than relying on the host.","For systemd units, set an explicit Environment PATH or use an absolute FFmpeg path in the command construction.","Confirm the binary is executable if it exists but still raises PermissionError (an OSError subclass)."],"exampleFix":"# Dockerfile before\nFROM python:3.12-slim\n# after\nFROM python:3.12-slim\nRUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/*","handlingStrategy":"validation","validationCode":"import shutil\n\nif shutil.which(\"ffmpeg\") is None:\n    raise EnvironmentError(\"ffmpeg not found on PATH; install it before enabling Sonilo\")","typeGuard":null,"tryCatchPattern":"try:\n    proxy = generate_video_proxy(video)\nexcept SoniloError as exc:\n    if \"failed to run FFmpeg\" in str(exc):\n        fail_fast_with_ops_alert(\"FFmpeg missing or broken on worker\")\n    raise","preventionTips":["Add a startup check (shutil.which on ffmpeg) that refuses to enable Sonilo tasks when FFmpeg is absent.","Bake ffmpeg into the deployment image and pin the PATH in systemd or docker units."],"tags":["ffmpeg","environment","path","deployment"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}