Adding deque to avoid large amounts of memory used to hold log output
This commit is contained in:
+11
-2
@@ -332,8 +332,17 @@ def set_ffmpeg_loglevel(level: Optional[str]) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def run_ffmpeg_with_progress(cmd, duration, description="Processing", loglevel=None):
|
def run_ffmpeg_with_progress(cmd, duration, description="Processing", loglevel=None):
|
||||||
|
from collections import deque
|
||||||
|
|
||||||
cmd = cmd.copy()
|
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.
|
# Explicit call arg wins, else the module-level setting, else the quiet bar.
|
||||||
level = loglevel if loglevel is not None else _FFMPEG_LOGLEVEL
|
level = loglevel if loglevel is not None else _FFMPEG_LOGLEVEL
|
||||||
stream = level is not None
|
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,
|
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||||
text=True, bufsize=1, universal_newlines=True,
|
text=True, bufsize=1, universal_newlines=True,
|
||||||
)
|
)
|
||||||
logs = []
|
logs = deque(maxlen=_LOG_TAIL)
|
||||||
for line in iter(p.stdout.readline, ""):
|
for line in iter(p.stdout.readline, ""):
|
||||||
logs.append(line)
|
logs.append(line)
|
||||||
sys.stdout.write(line)
|
sys.stdout.write(line)
|
||||||
@@ -384,7 +393,7 @@ def run_ffmpeg_with_progress(cmd, duration, description="Processing", loglevel=N
|
|||||||
last_percent = 0
|
last_percent = 0
|
||||||
seen_any_progress = False
|
seen_any_progress = False
|
||||||
last_log_line = ""
|
last_log_line = ""
|
||||||
logs = []
|
logs = deque(maxlen=_LOG_TAIL)
|
||||||
|
|
||||||
def draw(percent, suffix=""):
|
def draw(percent, suffix=""):
|
||||||
filled = int(bar_width * percent / 100)
|
filled = int(bar_width * percent / 100)
|
||||||
|
|||||||
Reference in New Issue
Block a user