Normalize AI Clips to -14 LUFS with ffmpeg
Краткое содержание
Pixel shares a tested guide to normalizing Tiny Desk AI clips with ffmpeg's two-pass loudnorm filter, targeting -14 LUFS while keeping true peaks under control. It explains linear versus dynamic mode and tests the method on synthetic tones and eight public sample clips, helping the community avoid unexpected loudness and peak changes.
DEV Community
Why Is My Tiny Desk AI Clip Quieter Than Other Videos? Two-Pass ffmpeg loudnorm to -14 LUFS, and When It Goes "Dynamic" (Tested)
A question that comes up a lot once people start posting their Tiny Desk "Outstanding" AI clips next to other videos: why is mine so much quieter (or louder) than the clip before it? The usual answer you'll get is "normalize it to -14 LUFS". That's a fine target. But on these particular clips, the obvious ffmpeg command doesn't do what most people think it does, and on one file it made the peaks worse. This post has a ~90-line Python wrapper around ffmpeg's loudnorm filter that does the two-pass version properly. It copies the video stream bit for bit and tells you which mode loudnorm actually used. I tested it on synthetic tones where I know the right answer, then on the eight public sample clips on the Tiny Desk Outstanding home page, downloaded on November 16, 2026 (Asia/Shanghai). All outputs below are pasted exactly as they came out. Three numbers, quickly Integrated loudness (LUFS): how loud the whole clip feels on average, measured the way broadcast meters do (EBU R128 / ITU BS.1770). -14 LUFS is the target people quote most often for streaming and social video. Platforms don't all publish an exact figure, so treat it as a sensible target rather than a spec. True peak (dBTP): the highest point the waveform reaches between samples once it's turned back into sound. Keep it under about -1 dBTP so the lossy encoders on the other end don't clip. Loudness range (LU): how much the level moves around. A 15-second band clip barely moves: 0.7–2.2 LU on these samples. Why two passes, and what "linear" means loudnorm in one pass is a dynamic processor. It listens, guesses, and keeps adjusting the gain as the clip plays, with a limiter on top. In two-pass mode you measure first, then give loudnorm the measured values with linear=true, and it's supposed to apply one constant gain, like turning a volume knob once. The catch is in the word supposed. In ffmpeg 7.1's af_loudnorm.c, linear mode is only allowed if: if (s->measured_tp != 99 && s->measured_thresh != -70 && s->measured_lra != 0 && s->measured_i != 0) {
if ((offset_tp <= s->target_tp) && (s->measured_lra <= s->target_lra)) {
s->frame_type = LINEAR_MODE;
Here offset_tp is the measured true peak plus the gain you're asking for. So if turning the clip up (or not down enough) would push its peak above your true-peak target, ffmpeg quietly falls back to dynamic mode. It doesn't print an error. It just writes "normalization_type" : "dynamic" into the JSON it prints at the end. Most scripts never read that line. The script loudfix.py measures, normalizes, measures the encoded output again, and checks that the video stream wasn't touched. --prefer-linear changes what happens when linear gain isn't possible. Instead of letting loudnorm compress, it lowers the loudness target to the loudest level a single gain change can reach without going over the peak limit. #!/usr/bin/env python3
"""loudfix.py - two-pass loudness normalisation for a short clip, video untouched.
Pass 1 measures integrated loudness (LUFS), true peak (dBTP) and loudness range (LU)
with ffmpeg's loudnorm filter. Pass 2 feeds those numbers back so loudnorm can apply
one constant gain ("linear") instead of riding the level up and down ("dynamic").
The video stream is copied bit for bit; only the audio is re-encoded.
usage: python3 loudfix.py in.mp4 out.mp4 [--i -14] [--tp -1] [--lra 11] [--prefer-linear]
[--fade-in 0.03] [--measure-only]
"""
import argparse, json, re, subprocess, sys
def loudnorm_json(stderr):
# loudnorm prints its JSON block last on stderr
m = re.findall(r"{[^{}]\"input_i\"[^{}]}", stderr, re.S)
if not m:
sys.exit("no loudnorm JSON in ffmpeg output")
return json.loads(m[-1])
def measure(path, I, TP, LRA, pre=""):
cmd = ["ffmpeg", "-hide_banner", "-nostats", "-i", path, "-map", "0:a:0",
"-af", f"{pre}loudnorm=I={I}:TP={TP}:LRA={LRA}:print_format=json", "-f", "null", "-"]
return loudnorm_json(subprocess.run(cmd, c...

Powered by Readybot.io