Adding deque to avoid large amounts of memory used to hold log output

This commit is contained in:
2026-07-23 22:40:38 +02:00
parent 0d48a38516
commit c3e892cf89
+11 -2
View File
@@ -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)