feat: add independent volume controls and refine audio filters

This commit is contained in:
Honney OC committed 2026-09-15 13:06:14 +00:00
1 parent 514158c29b
commit e61c4a449d
2 files changed
+32 -18

No files matched your search

+4 -4
View File
@@ -323,7 +323,7 @@ def extract_audio_loudnorm(input_file: str, duration: int, start_sec: float,
map_args = ["-map", f"0:a:{stream_idx}"] if stream_idx is not None else []
base = ["ffmpeg", "-y", *ss_args, "-i", input_file, "-t", str(duration), "-vn", *map_args]
measure_af = f"loudnorm=I={TARGET_LUFS}:TP={TARGET_TP}:LRA={TARGET_LRA}:print_format=json"
gate_filter = ",lowpass=f=3000,agate=threshold=0.02:ratio=20:attack=5:release=50" if loud_gate else ""
gate_filter = ",lowpass=f=2000,highpass=f=100,agate=threshold=0.02:ratio=20:attack=5:release=50" if loud_gate else ""
# ─── Pass 1: measure ───
print(f"[loudness] {stem}: pass 1/2 measuring…")
@@ -332,7 +332,7 @@ def extract_audio_loudnorm(input_file: str, duration: int, start_sec: float,
if r.returncode != 0:
print(f"[loudness] {stem}: pass 1 failed ({r.stderr.strip()[-80:]}), falling back to simple extract", file=sys.stderr)
if loud_gate:
cmd_fallback = base + ["-af", "lowpass=f=3000,agate=threshold=0.02:ratio=20:attack=5:release=50", *AUDIO_CODEC, out_path]
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)
@@ -344,7 +344,7 @@ def extract_audio_loudnorm(input_file: str, duration: int, start_sec: float,
if measured is None:
print(f"[loudness] {stem}: could not parse measurement, falling back to simple extract", file=sys.stderr)
if loud_gate:
cmd_fallback = base + ["-af", "lowpass=f=3000,agate=threshold=0.02:ratio=20:attack=5:release=50", *AUDIO_CODEC, out_path]
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)
@@ -495,7 +495,7 @@ for _file_idx, INPUT_FILE in enumerate(INPUT_FILES):
cmd_audio = [
"ffmpeg", "-y", *ss_args, "-i", INPUT_FILE, "-t", str(DURATION),
"-vn", *map_args, "-af",
"lowpass=f=3000,agate=threshold=0.02:ratio=20:attack=5:release=50",
"lowpass=f=2000,highpass=f=100,agate=threshold=0.02:ratio=20:attack=5:release=50",
*AUDIO_CODEC, audio_out
]
else: