fix: skip loudnorm when measured loudness is -inf (silent segment)
This commit is contained in:
1 parent
1a2deb88a0
commit
06730a1be9
1 file changed
+12
+12
@@ -359,6 +359,18 @@ def extract_audio_loudnorm(input_file: str, duration: int, start_sec: float,
|
|||||||
offset = measured.get("target_offset", "0")
|
offset = measured.get("target_offset", "0")
|
||||||
print(f"[loudness] {stem}: measured I={mi} LUFS, TP={mtp} dBTP, LRA={mlra}, offset={offset} dB")
|
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 ───
|
# ─── Pass 2: apply with measured values ───
|
||||||
print(f"[loudness] {stem}: pass 2/2 applying loudnorm → {TARGET_LUFS} LUFS…")
|
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}"
|
apply_af = (f"loudnorm=I={TARGET_LUFS}:TP={TARGET_TP}:LRA={TARGET_LRA}"
|
||||||
|
|||||||
Reference in new issue
Block a user