harry0703/MoneyPrinterTurbo · critical · SoniloError

failed to run FFmpeg for Sonilo video proxy

Error message

failed to run FFmpeg for Sonilo video proxy

What it means

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.

Source

Thrown at app/services/sonilo.py:188

        "yuv420p",
        "-movflags",
        "+faststart",
        proxy_path,
    ]
    try:
        result = subprocess.run(
            command,
            capture_output=True,
            text=True,
            timeout=600,
            check=False,
        )
    except subprocess.TimeoutExpired as exc:
        _remove_file(proxy_path)
        raise SoniloError("Sonilo video proxy generation timed out") from exc
    except OSError as exc:
        _remove_file(proxy_path)
        raise SoniloError("failed to run FFmpeg for Sonilo video proxy") from exc
    if result.returncode != 0:
        _remove_file(proxy_path)
        detail = (result.stderr or "").strip().replace("\n", " ")[-500:]
        raise SoniloError(f"failed to generate Sonilo video proxy: {detail}")
    proxy_size = os.path.getsize(proxy_path) if os.path.isfile(proxy_path) else 0
    if proxy_size <= 0 or proxy_size > MAX_PROXY_BYTES:
        _remove_file(proxy_path)
        raise SoniloError("Sonilo video proxy is empty or exceeds the 300 MB limit")
    logger.info(
        f"Sonilo video proxy prepared: source={video_path}, size={proxy_size} bytes"
    )
    return proxy_path


def _parse_event(raw_line: bytes) -> dict[str, Any]:
    """严格解析单条 NDJSON,禁止静默忽略截断或非对象响应。"""
    try:
        event = json.loads(raw_line.decode("utf-8"))

View on GitHub (pinned to 1f9f19c202)

Solutions

  1. 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).
  2. For Docker images, add ffmpeg to the image build rather than relying on the host.
  3. For systemd units, set an explicit Environment PATH or use an absolute FFmpeg path in the command construction.
  4. Confirm the binary is executable if it exists but still raises PermissionError (an OSError subclass).

Example fix

# Dockerfile before
FROM python:3.12-slim
# after
FROM python:3.12-slim
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/*
Defensive patterns

Strategy: validation

Validate before calling

import shutil

if shutil.which("ffmpeg") is None:
    raise EnvironmentError("ffmpeg not found on PATH; install it before enabling Sonilo")

Try / catch

try:
    proxy = generate_video_proxy(video)
except SoniloError as exc:
    if "failed to run FFmpeg" in str(exc):
        fail_fast_with_ops_alert("FFmpeg missing or broken on worker")
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of harry0703/MoneyPrinterTurbo@1f9f19c202 (2026-08-14). Data as JSON: /api/errors/35efaa00926413d4. Report an issue: GitHub.