If you have ever run FFmpeg's single-pass loudnorm filter on a talking-head video, podcast, or voiceover, you have probably heard the dreaded background pumping effect: every time the speaker pauses for half a second, room tone and AC hum swell up like an airplane cabin, then slam back down on the next syllable.
Why? Because single-pass loudnorm runs in dynamic mode, constantly adjusting gain frame-by-frame.
The fix takes ~40 lines of zero-dependency Python: run Pass 1 to measure your track's true integrated loudness (input_i, input_lra, input_tp, input_thresh, target_offset) as JSON, then feed those exact measurements into Pass 2 with linear=true for transparent, zero-pumping broadcast loudness.
Target Standards Quick Reference
| Platform / Use Case | Target Integrated (I) |
True Peak (TP) |
Loudness Range (LRA) |
|---|---|---|---|
| YouTube / Shorts / Reels / TikTok | -14.0 LUFS |
-1.5 dBTP |
11 LU |
| Apple Podcasts / Spotify (Stereo) | -16.0 LUFS |
-1.5 dBTP |
7 LU |
| Mono Spoken Podcast | -19.0 LUFS |
-1.5 dBTP |
7 LU |
Complete Zero-Dependency Python Script (two_pass_loudnorm.py)
Works on any .wav, .mp3, or .mp4 (copies the video stream losslessly with -c:v copy if you pass a video file!):
import json
import re
import subprocess
import sys
from pathlib import Path
TARGET_I = -14.0 # -14.0 for YouTube/Shorts, -16.0 for stereo podcasts
TARGET_TP = -1.5 # True peak ceiling in dBTP
TARGET_LRA = 11.0 # Loudness range target
def measure_loudness(src: Path) -> dict:
cmd = [
"ffmpeg", "-hide_banner", "-i", str(src),
"-af", f"loudnorm=I={TARGET_I}:TP={TARGET_TP}:LRA={TARGET_LRA}:print_format=json",
"-f", "null", "-",
]
proc = subprocess.run(cmd, capture_output=True, text=True, check=True)
# FFmpeg writes loudnorm JSON stats to stderr
match = re.search(r"\{\s*\"input_i\"[\s\S]*?\}", proc.stderr)
if not match:
raise RuntimeError("Could not parse FFmpeg loudnorm JSON output.")
return json.loads(match.group(0))
def apply_linear_master(src: Path, dst: Path, stats: dict) -> None:
af = (
f"loudnorm=I={TARGET_I}:TP={TARGET_TP}:LRA={TARGET_LRA}:"
f"measured_I={stats['input_i']}:"
f"measured_LRA={stats['input_lra']}:"
f"measured_TP={stats['input_tp']}:"
f"measured_thresh={stats['input_thresh']}:"
f"offset={stats['target_offset']}:"
f"linear=true:print_format=summary"
)
is_video = src.suffix.lower() in {".mp4", ".mov", ".mkv"}
cmd = ["ffmpeg", "-y", "-hide_banner", "-i", str(src), "-af", af]
if is_video:
cmd += ["-c:v", "copy", "-c:a", "aac", "-b:a", "192k", "-movflags", "+faststart"]
else:
cmd += ["-ar", "48000", "-c:a", "pcm_s24le"]
cmd.append(str(dst))
subprocess.run(cmd, check=True)
if __name__ == "__main__":
src = Path(sys.argv[1])
dst = src.with_stem(f"{src.stem}_mastered")
stats = measure_loudness(src)
print(f"Measured: {stats['input_i']} LUFS | Peak: {stats['input_tp']} dBTP | Offset: {stats['target_offset']} dB")
apply_linear_master(src, dst, stats)
print(f"Saved clean linear master -> {dst}")
3 Subtle Gotchas That Trip Up Production Pipelines
-
Always check
normalization_typein the Pass-2 summary: If a recording has an extreme dynamic spike (like a sudden clap or mic bump 15 dB louder than speech),loudnormwill silently fall back fromlineartodynamicmode to protect the-1.5 dBTPceiling. Placing a gentle soft limiter orhighpass=f=75,acompressor=threshold=-18dB:ratio=2.5:attack=10:release=120before Pass 1 keeps Pass 2 locked cleanly in truelinearmode! -
Don't ignore
offset={stats['target_offset']}: Skippingtarget_offsetleaves your final output off by0.3–1.2 LUfrom target on short clips. Passing all 5 measured keys guarantees dead-on accuracy within±0.1 LU. -
Sample Rate Safety (
-ar 48000): Internally, FFmpeg'sloudnormupsamples to192 kHzto calculate true inter-sample peaks. Always pin-ar 48000(or44100) on output so you don't accidentally ship giant 192 kHz WAV files!
Want a Turnkey Offline Creator & Dev Toolkit?
Feel free to copy and modify the script above for any personal or client project! If you'd like a ready-to-run ZIP containing a batch 9:16 FFmpeg reframer, 12 copy-paste FFmpeg creator recipes, and our 20KB zero-dependency Offline HTML PDF Invoice Generator, you can grab the Offline Dev & Creator Starter Code Kit ($2.99 one-time, zero subscriptions) here:
👉 Offline Dev & Creator Starter Code Kit ($2.99 on Payhip)
Shout-out to everyone who brought up two-pass loudnorm on my last FFmpeg post — what other audio/video automation pain points are you scripting with Python right now?
Top comments (0)