The first second: two numbers I measure with ffmpeg before I trust a vertical cut
A commenter on my last post made a point I couldn't argue with. On a vertical feed, the decision to stay happens in the first second or two, long before any dead air in the middle can matter. He asked what my first second actually looked like.
I didn't know. So I measured the file.
Two numbers, both cheap:
- First word. When the speech starts.
- First caption. When the bottom band of the frame stops changing, which is when the text is fully up and readable.
The gap between them is the story of a head. If text lands half a second after the voice, the viewer hears a sentence while looking at a still portrait. If the text is up before the voice, nothing is wasted.
First word
ffmpeg -hide_banner -i cut.mp4 \ -af "silencedetect=noise=-35dB:d=0.08" -f null - 2>&1 | grep silence_end Speech begins where the opening silence ends. One catch: that only works if the file opens with silence. If the first frame already has sound, there is no silence_start: 0 and the onset is 0, not the first number in the log.
First caption
Do not trust your memory of the render. I once shipped a file with no text in it at all and only noticed by comparing frames, so this check is built on pixels.
Sample the caption band at the native frame rate, shrunk to a strip:
ffmpeg -i cut.mp4 -t 3 \ -vf "crop=iw:ih*0.26:0:ih*0.74,scale=108:48,fps=25" b_%04d.png Then diff each strip against frame 0. The first sustained difference is the caption arriving. The first run of unchanged strips after that is the caption settling, meaning the fade is done and the text is legible.
What my own cut measured
20.25s, 1080x1920, 25fps:
- first word at 0.157s
- band starts changing at 0.040s, still at 0.320s
- next band change at 2.52s
So the caption is fully up 0.16 seconds after the voice starts, and then it sits unchanged for 2.2 seconds. That is the part I'd fix. The caption isn't late, it's static. My face pushes in slowly the whole time and the words do not move at all.
The failure that makes the metric lie
Run the same check on a file with nothing in that band and it prints "still from 0.040s". A blank band is perfectly still. Stillness by itself praises a video with no text in it, which is exactly the mistake this check is supposed to catch.
So the script prints both: when the band starts changing, and when it stops. My earlier 26s cut had speech at 0.207s and a bottom band that never changed in the first three seconds. Constant, clean, and wrong.
The script
#!/usr/bin/env python3 """Measure the head of a vertical short: first speech onset and when the caption band stops moving. usage: python3 first_second.py INPUT.mp4 [BAND_FRACTION] BAND_FRACTION is the bottom share of the frame to watch for caption motion (default 0.26). If your captions sit higher, pass a bigger number. """ import json, os, re, shutil, subprocess, sys, tempfile SPEECH_NOISE = "-35dB" SPEECH_MIN = "0.08" VISIBLE_EPS = 1.5 # band must differ from frame 0 by this much to count as caption SETTLE_EPS = 0.5 # mean abs diff (0-255) below which two frames count as still SETTLE_WINDOW = 6 # consecutive still frame pairs required (25fps -> 0.24s) SAMPLE_SECONDS = 3.0 def run(cmd): return subprocess.run(cmd, capture_output=True, text=True) def probe(path): p = run(["ffprobe", "-v", "error", "-show_entries", "format=duration:stream=codec_type,width,height,r_frame_rate", "-of", "json", path]) d = json.loads(p.stdout or "{}") streams = d.get("streams", []) v = next((s for s in streams if s.get("codec_type") == "video"), {}) has_audio = any(s.get("codec_type") == "audio" for s in streams) fps = 25.0 rf = (v.get("r_frame_rate") or "25/1").split("/") if len(rf) == 2 and float(rf[1]): fps = float(rf[0]) / float(rf[1]) return { "duration": float(d.get("format", {}).get("duration") or 0), "width": v.get("width"), "height": v.get("height"), "fps": round(fps, 2), "audio": has_audio, } def first_speech(path): p = run(["ffmpeg", "-hide_banner", "-nostats", "-i", path, "-af", f"silencedetect=noise={SPEECH_NOISE}:d={SPEECH_MIN}", "-f", "null", "-"]) log = p.stderr # speech starts at the first silence_end; a file that opens with sound # has no silence_start at 0 and therefore starts at 0 if "silence_start: 0" not in log and "silence_start: 0.0" not in log: return 0.0 m = re.search(r"silence_end:\s*([0-9.]+)", log) return float(m.group(1)) if m else None def band_settle(path, height, band_fraction, fps): tmp = tempfile.mkdtemp(prefix="fs_") try: band_h = int(height * band_fraction) top = height - band_h run(["ffmpeg", "-hide_banner", "-loglevel", "error", "-i", path, "-t", str(SAMPLE_SECONDS), "-vf", f"crop=iw:{band_h}:0:{top},scale=108:48,fps={fps}", os.path.join(tmp, "b_%04d.png")]) files = sorted(os.listdir(tmp)) if not files: return None from PIL import Image, ImageChops, ImageStat ims = [Image.open(os.path.join(tmp, f)).convert("L") for f in files] base = ims[0] vs_start = [ImageStat.Stat(ImageChops.difference(im, base)).mean[0] for im in ims] diffs = [ImageStat.Stat(ImageChops.difference(ims[i], ims[i - 1])).mean[0] for i in range(1, len(ims))] visible = None for i in range(len(vs_start) - 3): if all(v > VISIBLE_EPS for v in vs_start[i:i + 3]): visible = round(i / fps, 3) break still = None start = int((visible or 0) * fps) for i in range(start, len(diffs) - SETTLE_WINDOW): if all(d < SETTLE_EPS for d in diffs[i:i + SETTLE_WINDOW]): still = round((i + 1) / fps, 3) break return {"visible": visible, "still": still} finally: shutil.rmtree(tmp, ignore_errors=True) def main(): if len(sys.argv) < 2: print(__doc__.strip()) sys.exit(2) path = sys.argv[1] band = float(sys.argv[2]) if len(sys.argv) > 2 else 0.26 info = probe(path) print(f"file {os.path.basename(path)}") print(f"duration {info['duration']:.2f}s {info['width']}x{info['height']} @ {info['fps']}fps") if not info["audio"]: print("speech no audio stream") else: onset = first_speech(path) print(f"speech first word at {onset:.3f}s" if onset is not None else "speech could not detect onset") cap = band_settle(path, info["height"] or 1920, band, info["fps"]) pct = int(band * 100) if not cap: print(f"caption no band data in the first {SAMPLE_SECONDS:.0f}s") elif cap["visible"] is None: print(f"caption bottom {pct}% never changes in the first {SAMPLE_SECONDS:.0f}s") elif cap["still"] is None: print(f"caption bottom {pct}% starts changing at {cap['visible']:.3f}s and never settles") else: print(f"caption bottom {pct}% changes at {cap['visible']:.3f}s, still from {cap['still']:.3f}s") if __name__ == "__main__": main() What I do with the numbers
- Speech later than ~0.4s: trim the head. Opening silence is not tension, it's a scroll trigger.
- Caption more than ~0.3s behind the voice: shorten the fade or cut it.
- Caption unchanged for more than ~2s: it's a still image now. Change the line, move the band, or let it out.
- Pick your band fraction by looking at three frames. 0.26 assumes bottom-third captions.
Limits: this reads pixels and audio, not attention. The platform where I post gives me view counts and completions, no drop-off curve, so I can't tell you where people left. If yours does show retention, read that first and use these numbers to explain it.
Thanks to @phongdesigns for the push that made me measure this instead of guessing.