From 06730a1be95daac577d764fbdfd4e292a3fa82bc Mon Sep 17 00:00:00 2001 From: Honney OC Date: Tue, 15 Sep 2026 21:06:27 +0000 Subject: [PATCH] fix: skip loudnorm when measured loudness is -inf (silent segment) --- extract.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/extract.py b/extract.py index 165a671..9c8cdb6 100644 --- a/extract.py +++ b/extract.py @@ -359,6 +359,18 @@ def extract_audio_loudnorm(input_file: str, duration: int, start_sec: float, offset = measured.get("target_offset", "0") print(f"[loudness] {stem}: measured I={mi} LUFS, TP={mtp} dBTP, LRA={mlra}, offset={offset} dB") + # ─── Guard: silent segment produces -inf — skip loudnorm ─── + if mi == "-inf" or mtp == "-inf" or "inf" in str(mi).lower() or "inf" in str(mtp).lower(): + print(f"[loudness] {stem}: segment is silent or near-silent, skipping loudnorm", file=sys.stderr) + if loud_gate: + cmd_fallback = base + ["-af", "lowpass=f=2000,highpass=f=100,agate=threshold=0.02:ratio=20:attack=5:release=50", *AUDIO_CODEC, out_path] + else: + cmd_fallback = base + [*AUDIO_CODEC, out_path] + r2 = subprocess.run(cmd_fallback, capture_output=True, text=True) + if r2.returncode != 0: + sys.exit(f"ffmpeg (audio) failed:\n{r2.stderr}") + return + # ─── Pass 2: apply with measured values ─── print(f"[loudness] {stem}: pass 2/2 applying loudnorm → {TARGET_LUFS} LUFS…") apply_af = (f"loudnorm=I={TARGET_LUFS}:TP={TARGET_TP}:LRA={TARGET_LRA}"