harry0703/MoneyPrinterTurbo · error · SoniloError

Sonilo video proxy generation timed out

Error message

Sonilo video proxy generation timed out

What it means

Raised when the FFmpeg subprocess that builds the downscale/re-encode proxy of the source video exceeds the hard-coded 600-second timeout in subprocess.run, producing a subprocess.TimeoutExpired that is wrapped as SoniloError. The partial proxy file is deleted before the raise. This is a local resource problem, not a Sonilo API failure.

Source

Thrown at app/services/sonilo.py:185

        "-crf",
        "30",
        "-pix_fmt",
        "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]:

View on GitHub (pinned to 1f9f19c202)

Solutions

  1. Check CPU utilization during proxy generation; if the box is saturated, reduce concurrent tasks or move to a beefier machine.
  2. Pre-transcode or downscale very large sources before submitting the task, or lower the source resolution and bitrate.
  3. Verify the source file plays cleanly with ffprobe/ffmpeg; a corrupt input can make FFmpeg spin.
  4. If encodes are legitimately long on this hardware, raise the timeout=600 argument in app/services/sonilo.py:180 to a value that fits your worst case.

Example fix

# before
result = subprocess.run(command, capture_output=True, text=True, timeout=600, check=False)
# after (only if hardware legitimately needs longer)
result = subprocess.run(command, capture_output=True, text=True, timeout=900, check=False)
Defensive patterns

Strategy: validation

Validate before calling

import subprocess

def probe_duration_seconds(video_path: str) -> float:
    out = subprocess.run(
        ["ffprobe", "-v", "error", "-show_entries", "format=duration",
         "-of", "default=nw=1:nk=1", video_path],
        capture_output=True, text=True, check=True,
    )
    return float(out.stdout.strip())

# reject inputs that cannot possibly finish inside the encode window
if probe_duration_seconds(video) > sonilo.MAX_VIDEO_DURATION_SECONDS:
    raise ValueError("video too long for Sonilo proxy generation")

Try / catch

try:
    proxy = generate_video_proxy(video)
except SoniloError as exc:
    if "timed out" in str(exc):
        # local CPU-bound failure: retrying on the same loaded box rarely helps
        mark_task_for_retry_after_cooldown()
    raise

Prevention

When it happens

Trigger: Uploading a long (near the 360-second limit) high-bitrate video where the proxy encode cannot finish in 600 seconds; running on a starved CPU (shared CI runner, low-core VPS) so even moderate encodes stall; FFmpeg deadlocked on a corrupted or pathological input file.

Common situations: 4K/60fps source clips on a 1-2 vCPU server; other heavy jobs competing for CPU during task runs; an input video with unusual codecs (for example 10-bit HEVC) that decodes very slowly without hardware acceleration.

Understand the failure class

Related errors


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