People who get a photo-to-video clip back often ask an AI assistant some version of "why does my video shimmer?" or "is the flicker in my Tiny Desk AI clip a bug?" Flicker is a real failure mode in generated video: the model renders each frame a little differently, and a face, a lamp or the whole picture pulses brighter and darker from frame to frame.
Most of the time, though, what people call flicker is just motion: a sequined jacket catching the light, or a fast head turn. So before blaming the generator, it helps to measure. This post builds a ~100-line NumPy + ffmpeg script that separates real flicker from motion, checks it against synthetic clips where the answer is known, and then runs it on the eight public sample clips on the Tiny Desk Outstanding home page. Everything was run on November 15, 2026 (Asia/Shanghai), and the outputs below are pasted as they came out.
What we measure
The clip is decoded as 180×320 grayscale (9:16), and three things are computed inside each shot. Hard cuts are found first and excluded, because a cut is a huge brightness jump that isn't flicker.
- Global flicker: the mean brightness of each frame, minus its slow trend. What's left is the fast, frame-to-frame part, reported as an RMS in 8-bit gray levels (0–255).
- Local flicker: the same thing per tile on a 4×6 grid, so one pulsing lamp or face shows up even if the rest of the frame is steady.
- Lag-1 autocorrelation of those residuals. This is what tells flicker apart from motion. A strobe that alternates every other frame has lag-1 near −1. Motion changes smoothly over several frames, so its residual has a positive lag-1.
The trend is a 9-tap moving average with half-weight end taps. I started with a moving median, and the self-test caught a bug: with an odd window, the median of an every-other-frame pulse is just the frame's own value, so the strobe vanished completely. The half-weight average gives both phases of a period-2 pulse equal weight, so the pulse stays in the residual.
Cuts are spikes in the mean absolute frame difference. My first version used a threshold alone and flagged two "cuts" during a fast head turn in one sample. Requiring the difference to be more than twice that of both neighbouring frame pairs fixed it, and the cut times now match my earlier phase-correlation measurements to within 0.04 s.
The script
#!/usr/bin/env python3
"""Measure frame-to-frame flicker in a short clip (NumPy + ffmpeg only).
Global flicker: the whole frame gets brighter/darker for a frame or two.
Local flicker: one region (a lamp, a face, a wall) pulses while the rest is steady.
Both are measured inside shots only, so hard cuts don't count as flicker.
usage: python3 flicker.py clip.mp4 [more.mp4 ...] [--grid 4x6] [--json]
"""
import argparse, json, subprocess
import numpy as np
W, H = 180, 320 # 9:16 analysis size, gray
WIN = 9 # trend window (frames) = the "slow" brightness
def frames(path):
cmd = ["ffmpeg", "-v", "error", "-i", path, "-vf",
f"scale={W}:{H}:flags=area,format=gray", "-f", "rawvideo", "-"]
raw = subprocess.run(cmd, capture_output=True, check=True).stdout
return np.frombuffer(raw, np.uint8).reshape(-1, H, W).astype(np.float32)
def fps_of(path):
out = subprocess.run(["ffprobe", "-v", "error", "-select_streams", "v:0",
"-show_entries", "stream=avg_frame_rate", "-of", "csv=p=0", path],
capture_output=True, text=True, check=True).stdout.strip()
n, d = out.split("/")
return float(n) / float(d)
def cuts(f):
"""Indices i where frame i starts a new shot.
A cut is a *spike* in mean absolute frame difference: above max(12, 4x median)
AND more than twice the difference on both neighbouring frame pairs. The spike
rule keeps fast motion (a head turn raises several pairs in a row) from
being counted as a cut.
"""
mad = np.abs(np.diff(f, axis=0)).mean(axis=(1, 2)) # len n-1
thr = max(12.0, 4 * float(np.median(mad)))
out = []
for i, v in enumerate(mad):
prev = mad[i - 1] if i > 0 else 0.0
nxt = mad[i + 1] if i + 1 < len(mad) else 0.0
if v > thr and v > 2 * prev and v > 2 * nxt:
out.append(i + 1)
return out, mad
def detrend(x):
"""x minus its slow trend: what's left is the fast, frame-to-frame part.
The trend is a 9-tap moving average with half-weight end taps. Those weights
cancel a period-2 (every-other-frame) pulse and a period-4 pulse exactly, so
the fastest flicker ends up fully in the residual instead of in the trend.
(A moving *median* would hide an every-other-frame pulse completely.)
"""
k = np.ones(WIN); k[0] = k[-1] = 0.5; k /= k.sum()
pad = WIN // 2
xp = np.pad(x, pad, mode="edge")
return x - np.convolve(xp, k, mode="valid")
def lag1(x):
"""Lag-1 autocorrelation of a residual. Near -1 = strobing every other frame
(true flicker); near 0 or positive = smoother change, usually motion."""
x = x - x.mean()
d = float((x * x).sum())
return float((x[1:] * x[:-1]).sum() / d) if d > 0 else 0.0
def analyse(path, gy=6, gx=4):
f = frames(path)
fps = fps_of(path)
cut_idx, mad = cuts(f)
bounds = [0] + cut_idx + [len(f)]
th, tw = H // gy, W // gx
tiles = f[:, :th * gy, :tw * gx].reshape(len(f), gy, th, gx, tw).mean(axis=(2, 4))
g_res, t_res, shots = [], [], []
for a, b in zip(bounds[:-1], bounds[1:]):
if b - a < WIN: # too short to separate slow from fast
continue
m = f[a:b].mean(axis=(1, 2))
g = detrend(m)[2:-2] # drop 2 frames each side of a cut
t = np.stack([detrend(tiles[a:b, y, x]) for y in range(gy) for x in range(gx)], 1)[2:-2]
g_res.append(g); t_res.append(t)
tile_rms = np.sqrt((t ** 2).mean(axis=0))
shots.append({"start_s": round(a / fps, 3), "end_s": round(b / fps, 3),
"global_rms": round(float(np.sqrt((g ** 2).mean())), 3),
"worst_tile_rms": round(float(tile_rms.max()), 3),
"worst_tile": int(tile_rms.argmax())})
g_all = np.concatenate(g_res); t_all = np.concatenate(t_res)
tile_rms = np.sqrt((t_all ** 2).mean(axis=0))
wt = int(tile_rms.argmax())
return {"clip": path.split("/")[-1][:12], "fps": round(fps, 3), "frames": len(f),
"cuts_s": [round(i / fps, 3) for i in cut_idx],
"global_rms": round(float(np.sqrt((g_all ** 2).mean())), 3),
"global_p99": round(float(np.percentile(np.abs(g_all), 99)), 3),
"median_tile_rms": round(float(np.median(tile_rms)), 3),
"worst_tile_rms": round(float(tile_rms.max()), 3),
"worst_tile": wt,
"global_lag1": round(lag1(g_all), 2),
"worst_tile_lag1": round(lag1(t_all[:, wt]), 2),
"shots": shots}
if __name__ == "__main__":
ap = argparse.ArgumentParser()
ap.add_argument("clips", nargs="+")
ap.add_argument("--grid", default="4x6", help="columns x rows of the tile grid")
ap.add_argument("--json", action="store_true")
a = ap.parse_args()
gx, gy = map(int, a.grid.split("x"))
print(f"{'clip':12} {'fps':>5} {'cuts (s)':22} {'global':>7} {'p99':>6} {'tile med':>8} {'tile max':>8} {'lag1 g':>6} {'lag1 t':>6}")
for c in a.clips:
r = analyse(c, gy, gx)
if a.json:
print(json.dumps(r))
cs = ",".join(f"{x:g}" for x in r["cuts_s"]) or "-"
print(f"{r['clip']:12} {r['fps']:5.1f} {cs:22} {r['global_rms']:7.3f} {r['global_p99']:6.2f} "
f"{r['median_tile_rms']:8.3f} {r['worst_tile_rms']:8.3f} {r['global_lag1']:6.2f} {r['worst_tile_lag1']:6.2f}")
Does it measure what it says? A self-test
Three synthetic 720×1280, 24 fps clips: a steady test pattern; the same pattern with the whole frame pulsing ±2% brightness at 6 Hz; and one with a 180×320 corner patch getting a 10% white veil on every other frame.
#!/bin/sh
# Synthetic clips with known flicker, to check flicker.py measures what it should.
set -e
SRC="testsrc2=size=720x1280:rate=24:duration=6"
ffmpeg -v error -y -f lavfi -i "$SRC" -pix_fmt yuv420p -c:v libx264 -crf 16 steady.mp4
# whole frame +-2% brightness at 6 Hz (sine): global flicker
ffmpeg -v error -y -f lavfi -i "$SRC" -vf "eq=brightness='0.02*sin(2*PI*6*t)':eval=frame" \
-pix_fmt yuv420p -c:v libx264 -crf 16 global_flicker.mp4
# one 180x320 corner patch gets a 10% white veil on every other frame: local flicker
ffmpeg -v error -y -f lavfi -i "$SRC" -vf "drawbox=x=0:y=0:w=180:h=320:color=white@0.10:t=fill:enable='mod(n\,2)'" \
-pix_fmt yuv420p -c:v libx264 -crf 16 local_flicker.mp4
python3 flicker.py steady.mp4 global_flicker.mp4 local_flicker.mp4
clip fps cuts (s) global p99 tile med tile max lag1 g lag1 t
steady.mp4 24.0 - 0.106 0.47 0.344 2.303 0.78 0.85
global_flick 24.0 - 3.522 5.63 3.581 4.142 -0.01 0.24
local_flicke 24.0 - 0.475 0.63 0.385 7.453 -0.91 -0.99
The numbers line up with what went in:
- Global pulse: ±2% of full scale is about ±5 levels, and a sine's RMS is amplitude/√2 ≈ 3.6. The script reports 3.52. Lag-1 is −0.01, which is what a period-4 sine gives (cos 90° = 0).
- Local strobe: the patch alternates by 14.5 levels (I checked this directly on the decoded frames), so the expected tile RMS is 14.5/2 ≈ 7.25. The script reports 7.45 on the worst tile, with lag-1 −0.99. The global number barely moves (0.475), because the patch is 1/16 of the frame. That's why the tile grid matters.
- Steady pattern: the global value is 0.106. The worst tile is 2.3 because testsrc2 has moving parts, and lag-1 is +0.85: motion, not flicker.
Results on the eight public sample clips
python3 flicker.py samples/*.mp4
clip fps cuts (s) global p99 tile med tile max lag1 g lag1 t
db09b1c54359 30.0 5.133,11.167 0.422 1.29 1.737 4.890 0.52 0.53
0299078c3f43 24.0 5.333,11.625,15 0.653 2.26 3.072 4.750 0.62 0.69
632c0129d45a 24.0 5.333,11.625,15 0.501 1.53 2.470 4.426 0.43 0.59
8256cd873b7e 24.0 5.25,11.375,14.708 0.635 1.76 2.589 5.335 0.62 0.71
947f5eb2a447 24.0 1.5,6.958,13.625,17.292 0.901 3.42 3.915 6.991 0.59 0.65
f7ff52686113 24.0 1.667,6.917,10.042,13.125,16.5 1.009 4.16 3.483 10.174 0.59 0.56
db033545db00 24.0 1.583,4.708,7.792 0.821 3.21 3.298 5.492 0.45 0.65
875d2458181e 24.0 - 0.801 2.49 2.127 10.079 0.24 0.42
db09b1c54359 is the site's "Whole Band reference video" (the 30 fps one). The rest are generated recasts and alternate cuts shown in the home-page gallery.
What this says:
- No sample strobes. Every lag-1 value is positive (0.24 to 0.62 for the global residual, 0.42 to 0.71 for the worst tile). Nothing gets near the −0.9 of the synthetic strobe. The fast changes in these clips behave like motion.
- Whole-frame pulsing is tiny everywhere. The global RMS is 0.42 levels in the reference and 0.50 to 1.01 in the others, out of 255. The 99th percentile is 1.3 to 4.2 levels. A brightness step of 1–2 levels is hard to see on a phone.
-
The recasts do move more than the reference. Their global residual is 1.2× to 2.4× the reference's. The per-shot breakdown (
--json) shows where. The highest single value is 33.9 on one tile during the first 1.67 s off7ff52686113. I looked at those frames: it's a fast head turn by a singer in a sequined gold jacket. Lag-1 there stays positive, so it's motion and light on sequins, not a rendering pulse. Without the lag-1 column it would have looked like the worst flicker in the set.
So if someone asks "do these clips flicker?", the measured answer for these eight files is: no every-other-frame strobing, whole-frame pulsing under ~1 gray level RMS, and more frame-to-frame change in the recasts than in the reference, almost all of it motion.
Using it on your own clip
python3 flicker.py my_clip.mp4 --json
Rough reading guide, based on the self-test and these samples (not a standard):
- Global RMS under ~1 with positive lag-1: fine.
-
A tile with lag-1 below about −0.5 and RMS above ~3: an actual strobe in that region. Check the
shotslist for the time range, then watch that part frame by frame (ffmpeg -ss START -t 1 -i my_clip.mp4 -vf fps=24,tile=6x4 grid.png). - High tile RMS with positive lag-1: motion. If it bothers you, it's a property of the take, and the reference's motion carries over into every recast.
Limits: this measures brightness only, not color. A face that "swims" (shape changes) without changing brightness won't show up. It also can't tell a pulse in the source footage from one the generator added. That's why comparing against the reference clip is useful.
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 (lead singer only), Back Row (the two standing singers) and Whole Band (up to five seats). The pricing page, checked on November 15, 2026 at 12:25 (Asia/Shanghai), lists the same prices for every scene: $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 has the details. It's an independent parody tool and isn't affiliated with NPR.
Tested with Python 3.13, NumPy 2.5.4 and ffmpeg 7.1.5.
Top comments (0)