fix: add lowpass filter at 3000Hz before agate in audio extraction
This commit is contained in:
1 parent
dba450781d
commit
7cef142abb
1 file changed
+4
-4
+4
-4
@@ -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 []
|
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]
|
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"
|
measure_af = f"loudnorm=I={TARGET_LUFS}:TP={TARGET_TP}:LRA={TARGET_LRA}:print_format=json"
|
||||||
gate_filter = ",agate=threshold=0.02:ratio=20:attack=5:release=50" if loud_gate else ""
|
gate_filter = ",lowpass=f=3000,agate=threshold=0.02:ratio=20:attack=5:release=50" if loud_gate else ""
|
||||||
|
|
||||||
# ─── Pass 1: measure ───
|
# ─── Pass 1: measure ───
|
||||||
print(f"[loudness] {stem}: pass 1/2 measuring…")
|
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:
|
if r.returncode != 0:
|
||||||
print(f"[loudness] {stem}: pass 1 failed ({r.stderr.strip()[-80:]}), falling back to simple extract", file=sys.stderr)
|
print(f"[loudness] {stem}: pass 1 failed ({r.stderr.strip()[-80:]}), falling back to simple extract", file=sys.stderr)
|
||||||
if loud_gate:
|
if loud_gate:
|
||||||
cmd_fallback = base + ["-af", f"agate=threshold=0.02:ratio=20:attack=5:release=50", *AUDIO_CODEC, out_path]
|
cmd_fallback = base + ["-af", "lowpass=f=3000,agate=threshold=0.02:ratio=20:attack=5:release=50", *AUDIO_CODEC, out_path]
|
||||||
else:
|
else:
|
||||||
cmd_fallback = base + [*AUDIO_CODEC, out_path]
|
cmd_fallback = base + [*AUDIO_CODEC, out_path]
|
||||||
r2 = subprocess.run(cmd_fallback, capture_output=True, text=True)
|
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:
|
if measured is None:
|
||||||
print(f"[loudness] {stem}: could not parse measurement, falling back to simple extract", file=sys.stderr)
|
print(f"[loudness] {stem}: could not parse measurement, falling back to simple extract", file=sys.stderr)
|
||||||
if loud_gate:
|
if loud_gate:
|
||||||
cmd_fallback = base + ["-af", f"agate=threshold=0.02:ratio=20:attack=5:release=50", *AUDIO_CODEC, out_path]
|
cmd_fallback = base + ["-af", "lowpass=f=3000,agate=threshold=0.02:ratio=20:attack=5:release=50", *AUDIO_CODEC, out_path]
|
||||||
else:
|
else:
|
||||||
cmd_fallback = base + [*AUDIO_CODEC, out_path]
|
cmd_fallback = base + [*AUDIO_CODEC, out_path]
|
||||||
r2 = subprocess.run(cmd_fallback, capture_output=True, text=True)
|
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 = [
|
cmd_audio = [
|
||||||
"ffmpeg", "-y", *ss_args, "-i", INPUT_FILE, "-t", str(DURATION),
|
"ffmpeg", "-y", *ss_args, "-i", INPUT_FILE, "-t", str(DURATION),
|
||||||
"-vn", *map_args, "-af",
|
"-vn", *map_args, "-af",
|
||||||
"agate=threshold=0.02:ratio=20:attack=5:release=50",
|
"lowpass=f=3000,agate=threshold=0.02:ratio=20:attack=5:release=50",
|
||||||
*AUDIO_CODEC, audio_out
|
*AUDIO_CODEC, audio_out
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in new issue
Block a user