From 47e531548701b8766b7924435ad4df3cd8a670f1 Mon Sep 17 00:00:00 2001 From: gahusb Date: Sat, 9 May 2026 01:01:03 +0900 Subject: [PATCH] =?UTF-8?q?fix(music-lab):=20ffmpeg=20=EC=9D=B8=EC=BD=94?= =?UTF-8?q?=EB=94=A9=20=EA=B0=80=EC=86=8D=20+=20=ED=83=80=EC=9E=84?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=ED=99=95=EC=9E=A5=20(=EC=A0=80=EC=84=B1?= =?UTF-8?q?=EB=8A=A5=20CPU=20=EB=8C=80=EC=9D=91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - preset fast → ultrafast (5-10x 가속, J4025 같은 저성능 CPU에서 5분 내 완료) - tune stillimage 추가 (정적 배경 + 파형 오버레이에 최적) - threads 0 — 모든 CPU 코어 활용 - VIDEO_TIMEOUT_S 300 → 600 (안전 마진) - subprocess.TimeoutExpired 캐치하여 명확한 에러 메시지 --- music-lab/app/pipeline/video.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/music-lab/app/pipeline/video.py b/music-lab/app/pipeline/video.py index 2e66dff..4830e2a 100644 --- a/music-lab/app/pipeline/video.py +++ b/music-lab/app/pipeline/video.py @@ -7,7 +7,7 @@ from . import storage logger = logging.getLogger("music-lab.video") -VIDEO_TIMEOUT_S = 300 # 5분 +VIDEO_TIMEOUT_S = 600 # 10분 — Celeron J4025 같은 저성능 CPU 여유 class VideoGenerationError(Exception): @@ -28,7 +28,10 @@ def generate(*, pipeline_id: int, audio_path: str, cover_path: str, cmd = _build_visualizer_cmd(audio_path, cover_path, out_path, w, h) logger.info("ffmpeg 실행: %s", " ".join(cmd)) - result = subprocess.run(cmd, capture_output=True, text=True, timeout=VIDEO_TIMEOUT_S) + try: + result = subprocess.run(cmd, capture_output=True, text=True, timeout=VIDEO_TIMEOUT_S) + except subprocess.TimeoutExpired: + raise VideoGenerationError(f"ffmpeg 타임아웃 ({VIDEO_TIMEOUT_S}s) — CPU 부하 또는 입력 파일 문제") if result.returncode != 0: raise VideoGenerationError(f"ffmpeg 실패: {result.stderr[-800:]}") @@ -49,7 +52,11 @@ def _build_visualizer_cmd(audio: str, bg: str, out: str, w: str, h: str) -> list f"[1:a]showwaves=s={w}x200:mode=cline:colors=0xFF4444@0.8[wave];" f"[bg][wave]overlay=0:({h}-200)[out]", "-map", "[out]", "-map", "1:a", - "-c:v", "libx264", "-preset", "fast", "-crf", "23", + "-c:v", "libx264", + "-preset", "ultrafast", # was "fast" — ultrafast is 5-10x faster on weak CPUs + "-tune", "stillimage", # 정적 배경 + 파형 오버레이는 stillimage 튜닝이 적합 + "-threads", "0", # use all available CPU cores + "-crf", "23", "-c:a", "aac", "-b:a", "192k", "-shortest", out, ]