First attempt on constraining CPU load
This commit is contained in:
@@ -24,6 +24,17 @@ WHISPER_DEVICE = os.getenv("WHISPER_DEVICE", "auto").strip()
|
||||
WHISPER_DEVICE_INDEX = int(os.getenv("WHISPER_DEVICE_INDEX", "0"))
|
||||
WHISPER_CPU_THREADS = int(os.getenv("WHISPER_CPU_THREADS", "4"))
|
||||
|
||||
# --- Host load guards / thread limits ---
|
||||
# Limit ffmpeg threads (helps keep CPU in check when multiple workers run)
|
||||
FFMPEG_THREADS = int(os.getenv("FFMPEG_THREADS", "1"))
|
||||
|
||||
# Tame BLAS/threadpools that libraries may spin up implicitly
|
||||
import os as _os_threads
|
||||
_os_threads.environ.setdefault("OMP_NUM_THREADS", str(WHISPER_CPU_THREADS))
|
||||
_os_threads.environ.setdefault("OPENBLAS_NUM_THREADS", "1")
|
||||
_os_threads.environ.setdefault("MKL_NUM_THREADS", "1")
|
||||
_os_threads.environ.setdefault("NUMEXPR_NUM_THREADS", "1")
|
||||
|
||||
# Whisper logging & resume controls
|
||||
WHISPER_LOG_SEGMENTS = os.getenv("WHISPER_LOG_SEGMENTS", "1") not in ("0", "false", "False")
|
||||
WHISPER_RESUME = os.getenv("WHISPER_RESUME", "1") not in ("0", "false", "False")
|
||||
@@ -481,7 +492,7 @@ def ensure_sidecar_next_to_media(sidecar: Path, media_path: Path, lang: str = "e
|
||||
shutil.copy2(sidecar, dst)
|
||||
elif sidecar.suffix.lower() == ".vtt":
|
||||
tmp_srt = sidecar.with_suffix(".srt")
|
||||
subprocess.run(["ffmpeg", "-nostdin", "-y", "-i", str(sidecar), str(tmp_srt)], check=True)
|
||||
subprocess.run(["ffmpeg", "-nostdin", "-y", "-threads", str(FFMPEG_THREADS), "-i", str(sidecar), str(tmp_srt)], check=True)
|
||||
dst = media_path.with_suffix(f".{lang}.srt")
|
||||
shutil.move(str(tmp_srt), dst)
|
||||
except Exception as e:
|
||||
@@ -787,6 +798,7 @@ def extract_audio(src: Path, outdir: Path) -> Path:
|
||||
# Force audio-only, mono, 16kHz WAV
|
||||
cmd = [
|
||||
"ffmpeg", "-nostdin", "-y",
|
||||
"-threads", str(FFMPEG_THREADS),
|
||||
"-i", str(src),
|
||||
"-vn", "-ac", "1", "-ar", "16000",
|
||||
"-f", "wav", str(wav_path),
|
||||
|
Reference in New Issue
Block a user