DEV Community

Peiguan
Peiguan

Posted on

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;
Enter fullscreen mode Exit fullscreen 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, capture_output=True, text=True).stderr)

def sample_rate(path):
    out = subprocess.run(["ffprobe", "-v", "error", "-select_streams", "a:0", "-show_entries",
                          "stream=sample_rate", "-of", "csv=p=0", path],
                         capture_output=True, text=True, check=True).stdout.strip()
    return int(out)

def video_md5(path):
    cmd = ["ffmpeg", "-v", "error", "-i", path, "-map", "0:v:0", "-c", "copy", "-f", "md5", "-"]
    return subprocess.run(cmd, capture_output=True, text=True, check=True).stdout.strip()

def linear_ok(m, I, TP, LRA):
    """Same test ffmpeg 7.1 af_loudnorm.c uses before it agrees to linear mode."""
    mi, mtp, mlra = float(m["input_i"]), float(m["input_tp"]), float(m["input_lra"])
    if mlra == 0 or mi == 0:      # 0 is read as "not supplied" -> dynamic
        return False
    return mtp + (I - mi) <= TP and mlra <= LRA

def normalise(src, dst, I, TP, LRA, fade=0.0, prefer_linear=False):
    pre = f"afade=t=in:d={fade}," if fade > 0 else ""  # optional: soften a click in the first frames
    m = measure(src, I, TP, LRA, pre)
    if prefer_linear and not linear_ok(m, I, TP, LRA):
        # quietest change that never compresses: let the peak land 0.1 dB under TP
        I = round(min(I, float(m["input_i"]) + TP - float(m["input_tp"]) - 0.1), 2)
        LRA = max(LRA, float(m["input_lra"]))
    sr = sample_rate(src)  # loudnorm resamples to 192 kHz internally; go back to the source rate
    af = (pre + f"loudnorm=I={I}:TP={TP}:LRA={LRA}:linear=true:"
          f"measured_I={m['input_i']}:measured_TP={m['input_tp']}:"
          f"measured_LRA={m['input_lra']}:measured_thresh={m['input_thresh']}:"
          f"offset={m['target_offset']}:print_format=json,aresample={sr}")
    cmd = ["ffmpeg", "-hide_banner", "-nostats", "-y", "-i", src, "-map", "0:v:0", "-map", "0:a:0",
           "-c:v", "copy", "-af", af, "-c:a", "aac", "-b:a", "192k",
           "-movflags", "+faststart", dst]
    r = subprocess.run(cmd, capture_output=True, text=True)
    if r.returncode:
        sys.exit(r.stderr[-2000:])
    p2 = loudnorm_json(r.stderr)
    return m, p2, I

def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("src"); ap.add_argument("dst", nargs="?")
    ap.add_argument("--i", type=float, default=-14.0)
    ap.add_argument("--tp", type=float, default=-1.0)
    ap.add_argument("--lra", type=float, default=11.0)
    ap.add_argument("--fade-in", type=float, default=0.0, help="fade-in seconds, applied before both passes (0 = off)")
    ap.add_argument("--prefer-linear", action="store_true",
                    help="if linear gain would overshoot TP, lower the target instead of compressing")
    ap.add_argument("--measure-only", action="store_true")
    a = ap.parse_args()
    if a.measure_only or not a.dst:
        m = measure(a.src, a.i, a.tp, a.lra)
        print(f"{a.src}: {m['input_i']} LUFS, {m['input_tp']} dBTP, LRA {m['input_lra']} LU")
        return
    m, p2, used_i = normalise(a.src, a.dst, a.i, a.tp, a.lra, a.fade_in, a.prefer_linear)
    after = measure(a.dst, a.i, a.tp, a.lra)
    print(f"before: {m['input_i']} LUFS, {m['input_tp']} dBTP, LRA {m['input_lra']} LU")
    print(f"mode:   {p2['normalization_type']}  (target {used_i} LUFS, gain asked: {used_i - float(m['input_i']):+.2f} dB)")
    print(f"after:  {after['input_i']} LUFS, {after['input_tp']} dBTP, LRA {after['input_lra']} LU")
    print(f"video stream identical: {video_md5(a.src) == video_md5(a.dst)}")

if __name__ == "__main__":
    main()
Enter fullscreen mode Exit fullscreen mode

Two details matter more than they look:

  • loudnorm resamples to 192 kHz internally. Without the aresample back to the source rate, you get a 192 kHz AAC track that some players and editors handle badly.
  • -c:v copy plus the MD5 of the video packets proves the picture is untouched. Only the audio is re-encoded (AAC, 192 kb/s).

Self-test first

Before trusting it on real clips, I fed it two synthetic 15-second files with a gray video track:

  • a 1 kHz sine with a -20 dBFS peak, which should measure about -23 LUFS
  • the same tone with a slow ±25% amplitude wobble, so it has a non-zero loudness range
$ python3 loudfix.py sine_peak-20dBFS.mp4 s1.mp4
before: -23.05 LUFS, -19.13 dBTP, LRA 0.00 LU
mode:   dynamic  (target -14.0 LUFS, gain asked: +9.05 dB)
after:  -14.05 LUFS, -9.67 dBTP, LRA 0.00 LU
video stream identical: True
$ python3 loudfix.py wobble.mp4 w1.mp4
before: -25.08 LUFS, -19.98 dBTP, LRA 1.20 LU
mode:   linear  (target -14.0 LUFS, gain asked: +11.08 dB)
after:  -14.02 LUFS, -8.90 dBTP, LRA 1.20 LU
video stream identical: True
Enter fullscreen mode Exit fullscreen mode

The plain sine measures -23.05 LUFS, as expected. The test also caught the first surprise: the plain sine went dynamic even though a +9 dB gain leaves its peak around -10 dBTP. That's the measured_lra != 0 check in the snippet above. A perfectly steady tone has a loudness range of exactly 0.00, and ffmpeg reads 0 as "not supplied". The wobbling tone (LRA 1.20) went linear and landed at -14.02. Steady test tones are a bad way to test loudnorm's linear mode.

The eight sample clips

Here's every sample clip, once with the defaults (-14 LUFS, -1 dBTP) and once with --prefer-linear. File names are the first 8 characters of each sample's SHA-256 name on the site.

== 0299078c default (-14 LUFS, -1 dBTP)
before: -13.49 LUFS, 1.32 dBTP, LRA 1.70 LU
mode:   dynamic  (target -14.0 LUFS, gain asked: -0.51 dB)
after:  -13.95 LUFS, -0.37 dBTP, LRA 1.90 LU
video stream identical: True
== 0299078c --prefer-linear
before: -13.49 LUFS, 1.32 dBTP, LRA 1.70 LU
mode:   linear  (target -15.91 LUFS, gain asked: -2.42 dB)
after:  -15.95 LUFS, -0.99 dBTP, LRA 1.70 LU
video stream identical: True
== 632c0129 default (-14 LUFS, -1 dBTP)
before: -13.55 LUFS, 0.01 dBTP, LRA 1.70 LU
mode:   dynamic  (target -14.0 LUFS, gain asked: -0.45 dB)
after:  -13.96 LUFS, -0.64 dBTP, LRA 1.80 LU
video stream identical: True
== 632c0129 --prefer-linear
before: -13.55 LUFS, 0.01 dBTP, LRA 1.70 LU
mode:   linear  (target -14.66 LUFS, gain asked: -1.11 dB)
after:  -14.70 LUFS, -1.18 dBTP, LRA 1.80 LU
video stream identical: True
== 8256cd87 default (-14 LUFS, -1 dBTP)
before: -14.27 LUFS, -1.55 dBTP, LRA 2.00 LU
mode:   linear  (target -14.0 LUFS, gain asked: +0.27 dB)
after:  -14.01 LUFS, -1.32 dBTP, LRA 1.90 LU
video stream identical: True
== 8256cd87 --prefer-linear
before: -14.27 LUFS, -1.55 dBTP, LRA 2.00 LU
mode:   linear  (target -14.0 LUFS, gain asked: +0.27 dB)
after:  -14.01 LUFS, -1.32 dBTP, LRA 1.90 LU
video stream identical: True
== 875d2458 default (-14 LUFS, -1 dBTP)
before: -13.30 LUFS, -0.33 dBTP, LRA 0.70 LU
mode:   linear  (target -14.0 LUFS, gain asked: -0.70 dB)
after:  -14.04 LUFS, -1.08 dBTP, LRA 0.70 LU
video stream identical: True
== 875d2458 --prefer-linear
before: -13.30 LUFS, -0.33 dBTP, LRA 0.70 LU
mode:   linear  (target -14.0 LUFS, gain asked: -0.70 dB)
after:  -14.04 LUFS, -1.08 dBTP, LRA 0.70 LU
video stream identical: True
== 947f5eb2 default (-14 LUFS, -1 dBTP)
before: -13.57 LUFS, 0.02 dBTP, LRA 1.90 LU
mode:   dynamic  (target -14.0 LUFS, gain asked: -0.43 dB)
after:  -13.98 LUFS, -0.94 dBTP, LRA 1.70 LU
video stream identical: True
== 947f5eb2 --prefer-linear
before: -13.57 LUFS, 0.02 dBTP, LRA 1.90 LU
mode:   linear  (target -14.69 LUFS, gain asked: -1.12 dB)
after:  -14.71 LUFS, -1.15 dBTP, LRA 1.90 LU
video stream identical: True
== db033545 default (-14 LUFS, -1 dBTP)
before: -17.91 LUFS, -2.76 dBTP, LRA 1.60 LU
mode:   dynamic  (target -14.0 LUFS, gain asked: +3.91 dB)
after:  -14.26 LUFS, -0.83 dBTP, LRA 1.50 LU
video stream identical: True
== db033545 --prefer-linear
before: -17.91 LUFS, -2.76 dBTP, LRA 1.60 LU
mode:   linear  (target -16.25 LUFS, gain asked: +1.66 dB)
after:  -16.30 LUFS, -1.13 dBTP, LRA 1.60 LU
video stream identical: True
== db09b1c5 default (-14 LUFS, -1 dBTP)
before: -17.00 LUFS, 3.54 dBTP, LRA 2.00 LU
mode:   dynamic  (target -14.0 LUFS, gain asked: +3.00 dB)
after:  -14.25 LUFS, 5.23 dBTP, LRA 1.90 LU
video stream identical: True
== db09b1c5 --prefer-linear
before: -17.00 LUFS, 3.54 dBTP, LRA 2.00 LU
mode:   linear  (target -21.64 LUFS, gain asked: -4.64 dB)
after:  -21.66 LUFS, 3.60 dBTP, LRA 1.90 LU
video stream identical: True
== f7ff5268 default (-14 LUFS, -1 dBTP)
before: -17.39 LUFS, -2.99 dBTP, LRA 2.20 LU
mode:   dynamic  (target -14.0 LUFS, gain asked: +3.39 dB)
after:  -13.91 LUFS, -0.87 dBTP, LRA 2.30 LU
video stream identical: True
== f7ff5268 --prefer-linear
before: -17.39 LUFS, -2.99 dBTP, LRA 2.20 LU
mode:   linear  (target -15.5 LUFS, gain asked: +1.89 dB)
after:  -15.52 LUFS, -1.08 dBTP, LRA 2.30 LU
video stream identical: True
Enter fullscreen mode Exit fullscreen mode

The same data as a table. "Default" is -14 LUFS / -1 dBTP:

Clip (home-page caption) Before Default mode → after --prefer-linear → after
0299078c desk trio in leather, teal, navy bomber -13.49 LUFS, +1.32 dBTP dynamic → -13.95, -0.37 dBTP linear at -15.91 → -15.95, -0.99
632c0129 cats at the desk -13.55, +0.01 dynamic → -13.96, -0.64 linear at -14.66 → -14.70, -1.18
8256cd87 hoodie at the keys (480p) -14.27, -1.55 linear → -14.01, -1.32 same
875d2458 4-second gold-jacket close-up -13.30, -0.33 linear → -14.04, -1.08 same
947f5eb2 red-haired singer -13.57, +0.02 dynamic → -13.98, -0.94 linear at -14.69 → -14.71, -1.15
db033545 alternate 10-second performance -17.91, -2.76 dynamic → -14.26, -0.83 linear at -16.25 → -16.30, -1.13
db09b1c5 Whole Band reference video -17.00, +3.54 dynamic → -14.25, +5.23 linear at -21.64 → -21.66, +3.60
f7ff5268 longer cut of the same five -17.39, -2.99 dynamic → -13.91, -0.87 linear at -15.50 → -15.52, -1.08

What this says:

  1. Most recast clips are already at about -13.5 LUFS. Five of the eight are within 0.75 LU of -14. "Normalizing" them means turning them down by about half a decibel, which nobody will hear. If your clip measures between about -15 and -13 LUFS, you can skip this step.
  2. Six of eight went dynamic at the defaults. The loud ones went dynamic because their true peaks already sit at or above 0 dBTP. Even a -0.5 dB change can't bring a +1.32 dBTP peak under -1. The quiet ones went dynamic because +3 to +4 dB of gain would push their peaks over the limit. Dynamic mode did little harm here: loudness range moved by 0.1–0.2 LU. But it isn't the "one volume knob" people expect.
  3. The quiet clips are the ones worth fixing. db033545 and f7ff5268 sit around -17.4 to -17.9 LUFS, more than 3 LU under their neighbours. Platforms that normalize playback may only turn loud uploads down, so a quiet upload can just stay quiet. Here you have to pick: -14 with a little limiting (dynamic), or -16.3 / -15.5 with a pure gain change (--prefer-linear).
  4. Re-encoding moves the peak. Several outputs measure a few tenths of a dB above the -1 dBTP target (for example -0.37 and -0.64). The ceiling applies inside the filter, and the lossy AAC encode that follows can overshoot it a little. If you need a strict ceiling, ask for --tp -1.5. Always measure the file you're going to upload, not the filter's output.

The 13-millisecond click

The reference clip, db09b1c5, came out with a true peak of +5.23 dBTP after normalization, higher than before. Locating the highest sample with NumPy (decode to float, argmax of the absolute value) put it at 0.013 s. In the decoded source audio, the waveform jumps from near zero to +1.49 in under a millisecond at that point and stays above full scale for 63 samples (about 1.3 ms). It's a thump right at the start. When I wrote loudnorm's output to a float WAV, the same spot peaked at 0.89, so the limiter had caught it. After AAC encoding it peaked at 1.82: the encoder rebuilt the sharp edge as an even bigger overshoot.

None of the other seven samples has anything like it. Their loudest samples are ordinary musical peaks, between 0.71 and 1.06 of full scale. But it's a good reminder that one bad edge can control the "true peak" of a whole file. A short fade-in removes the click. A 20 ms fade wasn't enough, because the click sits at 13 ms, where a 20 ms fade is already about two-thirds open. 50 ms was:

== db09b1c5 default + --fade-in 0.05
before: -17.01 LUFS, -1.80 dBTP, LRA 2.00 LU
mode:   dynamic  (target -14.0 LUFS, gain asked: +3.01 dB)
after:  -14.25 LUFS, 0.38 dBTP, LRA 1.90 LU
video stream identical: True
== db09b1c5 --prefer-linear --fade-in 0.05
before: -17.01 LUFS, -1.80 dBTP, LRA 2.00 LU
mode:   linear  (target -16.31 LUFS, gain asked: +0.70 dB)
after:  -16.37 LUFS, -1.11 dBTP, LRA 1.90 LU
video stream identical: True
Enter fullscreen mode Exit fullscreen mode

With the click gone, the measured true peak drops from +3.54 to -1.80 dBTP. Now --prefer-linear only needs a +0.70 dB gain and stays under the limit after encoding (-1.11 dBTP). A 50 ms fade on a clip that opens mid-song is hard to hear. If you'd rather not touch the start at all, use the default dynamic mode and accept a little limiting.

A short recipe

# 1. measure. If it's within about 1 LU of -14, stop here
python3 loudfix.py my_clip.mp4 --measure-only

# 2. quiet clip, and you want -14 even if a limiter is involved
python3 loudfix.py my_clip.mp4 my_clip_-14.mp4

# 3. quiet clip, and you want a pure volume change (lands a bit under -14)
python3 loudfix.py my_clip.mp4 my_clip_lin.mp4 --prefer-linear

# 4. peaks still over your ceiling after encoding? leave more headroom
python3 loudfix.py my_clip.mp4 my_clip_lin.mp4 --prefer-linear --tp -1.5
Enter fullscreen mode Exit fullscreen mode

Run this on your own downloaded file, after any edits (captions, music, voice-over). Run it last, because every re-encode of the audio can move the peak again.

Where the clips come from

The Tiny Desk Outstanding studio recasts the same 15-second vertical reference, with its original soundtrack, in three scenes: Just Me, Back Row and Whole Band (up to five seats). I checked the pricing page on November 16, 2026 at 12:24 (Asia/Shanghai). Every scene costs the same: $9.98 (998 credits) at 480p, $12.98 (1,298) at 720p, $24.98 (2,498) at 1080p and $39.98 (3,998) at 4K, before tax. There's no free preview render; the FAQ explains how the upfront credit quote works. It's an independent parody tool and isn't affiliated with NPR.

Tested with Python 3.13.5 and ffmpeg 7.1.5 (native AAC encoder).

Top comments (0)