From c3e892cf89c7443348b3ce2f8769aa6e96155ced Mon Sep 17 00:00:00 2001 From: jenstandstad Date: Thu, 23 Jul 2026 22:40:38 +0200 Subject: [PATCH] Adding deque to avoid large amounts of memory used to hold log output --- gnommo/preprocessor.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gnommo/preprocessor.py b/gnommo/preprocessor.py index 9c55450..77d236b 100644 --- a/gnommo/preprocessor.py +++ b/gnommo/preprocessor.py @@ -332,8 +332,17 @@ def set_ffmpeg_loglevel(level: Optional[str]) -> None: def run_ffmpeg_with_progress(cmd, duration, description="Processing", loglevel=None): + from collections import deque + cmd = cmd.copy() + # Retain only a bounded tail of FFmpeg's output. FFmpeg emits a -progress block + # every second (plus any per-frame warnings), so on a long or stuck-at-99% run an + # unbounded list grows in Python until it eats all RAM — which is what OOM'd the + # 66 GB render box while ffmpeg sat at the last frame. The last N lines are all + # the error path ever needs. + _LOG_TAIL = 5000 + # Explicit call arg wins, else the module-level setting, else the quiet bar. level = loglevel if loglevel is not None else _FFMPEG_LOGLEVEL stream = level is not None @@ -349,7 +358,7 @@ def run_ffmpeg_with_progress(cmd, duration, description="Processing", loglevel=N cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1, universal_newlines=True, ) - logs = [] + logs = deque(maxlen=_LOG_TAIL) for line in iter(p.stdout.readline, ""): logs.append(line) sys.stdout.write(line) @@ -384,7 +393,7 @@ def run_ffmpeg_with_progress(cmd, duration, description="Processing", loglevel=N last_percent = 0 seen_any_progress = False last_log_line = "" - logs = [] + logs = deque(maxlen=_LOG_TAIL) def draw(percent, suffix=""): filled = int(bar_width * percent / 100)