We built 18 versions of one ad with FFmpeg: 3 hooks, 2 calls to action, 3 ratios
One master cut, three hook options, two end cards and three aspect ratios, joined by script without re-encoding. We ran the whole grid on three source clips from Tears of Steel, one cold run and three timed runs each, then checked every file, the text positions and the loudness at the joins.
Tested by us on Nov 7, 2026, on the clips and machine listed below. Every number on this page was measured in that run.
The result
It builds the whole grid by script, with FFmpeg only. From each source clip it wrote 18 files (3 hooks x 2 calls to action x 3 aspect ratios), all named by the scheme hook<A-C>_cta<X-Y>_<ratio>.mp4, in a median of 95.2, 107.2 and 101.8 seconds on a CPU-only laptop. All 18 names were present and none was twice on all 3 clips; each ratio had one single set of encode settings, so the join could be a stream copy with no re-encode.
Lengths: planned 36 s, real 36.021 s in the shortest file and 36.021 s in the longest. The audio track ran up to 0.021 s longer than the picture in a file. Text: 45 of 45 text lines (hook and end-card lines on all three ratios) sat inside the safe zone.
What it made




Footage: Tears of Steel, (c) Blender Foundation, mango.blender.org, CC-BY 3.0. These are files we made from it; they are shown under the same licence terms.
Four of the 18 files from the clip tos_a, as frames: the hook at 9:16, the end card at 9:16, the hook at 1:1 and the hook at 16:9.
What failed or surprised us
- Our first version missed the safe zone on four of five text lines. We centred each text line in the frame. At 9:16 Google's zone leaves 48 px on the left and 192 px on the right, so a centred line wider than 840 px runs into the right margin, where the platform's buttons sit. On the three clips, 11, 11 and 11 of 15 text lines were inside, and the lines that failed were the same on every clip: end card X at 9:16, end card Y at 9:16, hook B at 9:16, hook C at 9:16. We changed the script to centre each line in the zone and shrink long lines to fit; the first version's result file is kept. With the change, 45 of 45 lines were inside. The price: the longest hook line at 9:16 is drawn at 46 px on a 1920 px tall frame, which is small.
- Swapping a hook changes the loudness a lot. The first 3 seconds measured -27.5 to -11.2 LUFS against -18.1 to -10.6 LUFS for the master. The largest gap was 16.9 LU (hook A on tos_b: -27.5 against -10.6 LUFS). We did not level the hooks. A real grid should, and the guide's advice to listen at every join stands.
- Parts that do not match join without an error and come out wrong. We joined a hook made at 30 fps and 44.1 kHz to the master by stream copy. FFmpeg exited with code 0 and printed "Non-monotonic DTS" warnings. The joined file declares 30/1 frames per second for everything and holds 810 frames, which play for 27 s at that rate, for 33 s of content. Its container length is 35.94 s and its video stream says 26.4 s, so picture and sound end at different times.
- Every file's audio ran 0.021 s longer than its picture. We did not test whether it shows on a phone.
- A fixed centre crop is soft and can lose the subject. The 9:16 version is a 300 px wide slice of a 1280 px wide frame, enlarged 3.6 times, and it looked soft in the frames we looked at. A fixed crop does not follow a moving subject; the wide-to-vertical test chooses a crop for each shot.
What we tested and how
- Tool: ad-variations version FFmpeg 8.1.2 (concat demuxer, drawtext), LGPL/GPL (FFmpeg build) licence.
- Settings compared: {"steps":"master 30 s + 3 hook options (3 s) + 2 end cards (3 s), three ratios (9:16 crop, 1:1 crop, 16:9 crop), identical encode settings per part, stream-copy join"}.
- Input clips: Tears of Steel, (CC) Blender Foundation, mango.blender.org, CC-BY 3.0. 60 s excerpts re-encoded to H.264 720p.
tos_a: 60 s starting at 20 s of the film, SHA-256945262dcbe106f1e...tos_b: 60 s starting at 180 s of the film, SHA-2564097773b615cddfa...tos_c: 60 s starting at 360 s of the film, SHA-2563d3a8cd015310349...
- Machine: AMD Ryzen 7 7735U (8 cores, 16 threads), integrated Radeon 680M, not used (CPU-only runs), 31.2 GB RAM, Windows 11 10.0.26300. The laptop was shared with other work, so timings are what a busy machine gives, not a clean benchmark.
- Runs: one cold run, then three timed runs per clip and setting. Run on 2026-11-07.
The job: one finished ad into many versions. Our master is 30 seconds of the clip. The hook options are three different 3-second pieces of the clip, each with a line of text on a dark box. The call to action options are two 3-second end cards with two lines of text and silent audio. The ratios are 9:16 (1080x1920), 1:1 (1080x1080) and 16:9 (1280x720), each made as a crop of the 1280x534 source, not a squeeze. All parts of one ratio use the same size, 24 fps, H.264, yuv420p and AAC at 48 kHz stereo, and FFmpeg's concat demuxer joins hook, master and end card by stream copy.
We ran the script as one process tree: one cold run and three timed runs per source clip. We then checked the last run's 18 files: names against the plan, encode settings per ratio, planned against real length, audio length against picture length, the loudness of each hook against the master, and every text line against the same frame without text, measured against a safe zone (9:16: Google's published vertical zone; 1:1 and 16:9: 6 percent in from each edge). Last, we made one deliberate mismatch, a hook at 30 fps and 44.1 kHz joined to the master by stream copy.
Measurements by clip
The whole grid, per source clip (18 files each)
| Clip | Cold run (s) | Timed runs (s) | Median run (s) | Peak memory (MB) | Files | Total size (MB) | Largest file (MB) | SHA-256 of the sheet (first 16) |
|---|---|---|---|---|---|---|---|---|
| tos_a | 85.2 | 74.2, 96.9, 95.2 | 95.2 | 719 | 18 | 202.4 | 14.6 | 3b48f17db497a47e |
| tos_b | 107.4 | 107.2, 118, 107 | 107.2 | 737 | 18 | 252.5 | 17.5 | e47da4fdb63e818e |
| tos_c | 103.2 | 103.1, 101.8, 98.2 | 101.8 | 721 | 18 | 178.9 | 14.0 | d18b50cfa9ae7f54 |
Where the time went (median of the three timed runs, seconds)
| Clip | 1. Encode 18 parts (master, 3 hooks, 2 end cards, 3 ratios) | 2. Join 18 versions by stream copy | CPU load just before the four runs (%) |
|---|---|---|---|
| tos_a | 70.7 | 22.5 | 11, 18, 16, 13 |
| tos_b | 81.8 | 24 | 11, 15, 18, 11 |
| tos_c | 76.2 | 23.3 | 13, 26, 2, 21 |
Did the grid come out as planned?
| Clip | All 18 names present, none twice | Encode settings per ratio (sets found) | Planned length (s) | Real length, shortest to longest (s) | Largest audio-to-picture length gap (s) | Text lines inside the safe zone / checked |
|---|---|---|---|---|---|---|
| tos_a | yes | 9x16: 1, 1x1: 1, 16x9: 1 | 36 | 36.021 to 36.021 | 0.021 | 15 / 15 |
| tos_b | yes | 9x16: 1, 1x1: 1, 16x9: 1 | 36 | 36.021 to 36.021 | 0.021 | 15 / 15 |
| tos_c | yes | 9x16: 1, 1x1: 1, 16x9: 1 | 36 | 36.021 to 36.021 | 0.021 | 15 / 15 |
What a swapped hook does to loudness (9:16 files, LUFS of the first 3 s against the master)
| Clip | Hook A: hook / master | Hook B: hook / master | Hook C: hook / master |
|---|---|---|---|
| tos_a | -21.4 / -18.1 | -19.1 / -18.1 | -19.1 / -18.1 |
| tos_b | -27.5 / -10.6 | -21.1 / -10.6 | -20.6 / -10.6 |
| tos_c | -23.1 / -11.4 | -21 / -11.4 | -11.2 / -11.4 |
Reproduce it
"""One master ad, many versions: 3 hooks x 2 calls to action x 3 aspect ratios = 18 files, built by script with FFmpeg only.
usage: python pipeline_ad_variations.py clip.mp4 workdir
Needs ffmpeg (set FFMPEG, default: ffmpeg). Prints one JSON line with the seconds each stage took.
The parts of one ratio are all encoded with the same size, frame rate, codec and audio settings, so the join is a stream copy
(concat demuxer, no re-encode). The master is seconds 14 to 44 of the clip. The hooks are three different 3-second pieces of the clip with a
text line drawn on them. The calls to action are two 3-second end cards with a text line and silent audio. Text sits inside Google's
vertical safe zone on 9:16 and at least 6 percent in from every edge on the other ratios.
Written: parts/<ratio>/*.mp4, out/hook<X>_cta<Y>_<ratio>.mp4, sheet.csv (name, hook, cta, ratio, planned and real length, size, sha256).
"""
import csv
import hashlib
import json
import os
import shutil
import subprocess
import sys
import time
FFMPEG = os.environ.get("FFMPEG", "ffmpeg")
FFPROBE = os.path.join(os.path.dirname(FFMPEG), "ffprobe") if os.path.dirname(FFMPEG) else "ffprobe"
clip, work = os.path.abspath(sys.argv[1]), os.path.abspath(sys.argv[2])
if os.path.isdir(work):
shutil.rmtree(work)
os.makedirs(work)
times = {}
FONT = "C\\:/Windows/Fonts/arialbd.ttf"
MASTER = (14.0, 30.0) # start, length
HOOKS = {"A": (50.0, "THE BIG REVEAL"), "B": (2.0, "ONE MINUTE FROM THE FILM"), "C": (8.0, "WATCH TILL THE END")} # clip start second, text
CTAS = {"X": ("WATCH THE FULL FILM", "mango.blender.org"), "Y": ("MORE FROM BLENDER", "blender.org")}
HOOK_S, CTA_S = 3.0, 3.0
# ratio: (width, height, crop filter on the 1280x534 source, text size, text y as a fraction of the height)
RATIOS = {"9x16": (1080, 1920, "crop=300:534:490:0,scale=1080:1920", 76, 0.40), "1x1": (1080, 1080, "crop=534:534:373:0,scale=1080:1080", 64, 0.72), "16x9": (1280, 720, "crop=950:534:165:0,scale=1280:720", 48, 0.80)}
# horizontal safe zone per ratio: 9:16 is Google's published vertical zone (48 px left, 192 px right); the others are 6 percent in from each side
ZONE = {"9x16": lambda w: (48, w - 192), "1x1": lambda w: (int(w * 0.06), int(w * 0.94)), "16x9": lambda w: (int(w * 0.06), int(w * 0.94))}
ENC = ["-c:v", "libx264", "-crf", "21", "-preset", "veryfast", "-pix_fmt", "yuv420p", "-r", "24", "-c:a", "aac", "-b:a", "128k", "-ar", "48000", "-ac", "2"]
def ff(args, cwd=None):
r = subprocess.run([FFMPEG, "-v", "error", "-y", *args], capture_output=True, text=True, cwd=cwd)
if r.returncode != 0:
raise RuntimeError(r.stderr[-1500:])
def sha(p):
h = hashlib.sha256()
with open(p, "rb") as f:
for b in iter(lambda: f.read(1 << 20), b""):
h.update(b)
return h.hexdigest()
def dur(p, stream=None):
args = [FFPROBE, "-v", "error", *(["-select_streams", stream] if stream else []), "-show_entries", "stream=duration" if stream else "format=duration", "-of", "csv=p=0", p]
return float(subprocess.run(args, capture_output=True, text=True).stdout.split()[0])
def text(s, size, yfrac, h, w, zone):
"""One line of text on a dark box, centred in the safe zone (not in the frame) and shrunk so the box stays inside it. zone = (left, right) in px."""
x0, x1 = zone
size = min(size, int((x1 - x0 - 40) * 0.95 / (len(s) * 0.68))) # 0.68 em per bold capital, 18 px box border each side
return f"drawtext=fontfile='{FONT}':text='{s}':fontsize={size}:fontcolor=white:box=1:boxcolor=black@0.6:boxborderw=18:x={(x0 + x1) // 2}-text_w/2:y={int(h * yfrac)}"
# 1. parts for each ratio: the master, three hooks, two end cards, all with identical encode settings
t0 = time.perf_counter()
for rn, (w, h, crop, size, yf) in RATIOS.items():
d = os.path.join(work, "parts", rn)
os.makedirs(d)
ff(["-ss", str(MASTER[0]), "-t", str(MASTER[1]), "-i", clip, "-vf", f"{crop},setsar=1", *ENC, os.path.join(d, "master.mp4")])
for k, (st, s) in HOOKS.items():
ff(["-ss", str(st), "-t", str(HOOK_S), "-i", clip, "-vf", f"{crop},setsar=1,{text(s, size, yf, h, w, ZONE[rn](w))}", *ENC, os.path.join(d, f"hook{k}.mp4")])
for k, (l1, l2) in CTAS.items():
ff(["-f", "lavfi", "-i", f"color=c=0x14213d:s={w}x{h}:r=24:d={CTA_S}", "-f", "lavfi", "-i", f"anullsrc=r=48000:cl=stereo:d={CTA_S}",
"-vf", f"{text(l1, size, yf - 0.06, h, w, ZONE[rn](w))},{text(l2, int(size * 0.7), yf + 0.06, h, w, ZONE[rn](w))}", "-t", str(CTA_S), *ENC, os.path.join(d, f"cta{k}.mp4")])
times["parts_s"] = round(time.perf_counter() - t0, 2)
# 2. the grid: join hook + master + call to action by stream copy
t0 = time.perf_counter()
os.makedirs(os.path.join(work, "out"))
rows = []
for rn in RATIOS:
d = os.path.join(work, "parts", rn)
for hk in HOOKS:
for ck in CTAS:
name = f"hook{hk}_cta{ck}_{rn}.mp4"
lst = os.path.join(work, f"list_{name}.txt")
open(lst, "w").write("".join(f"file '{os.path.join(d, p).replace(chr(92), '/')}'\n" for p in (f"hook{hk}.mp4", "master.mp4", f"cta{ck}.mp4")))
outp = os.path.join(work, "out", name)
ff(["-f", "concat", "-safe", "0", "-i", lst, "-c", "copy", "-movflags", "+faststart", outp])
os.remove(lst)
rows.append({"name": name, "hook": hk, "cta": ck, "ratio": rn, "planned_s": HOOK_S + MASTER[1] + CTA_S, "real_s": round(dur(outp), 3), "video_s": round(dur(outp, "v:0"), 3), "audio_s": round(dur(outp, "a:0"), 3),
"bytes": os.path.getsize(outp), "sha256": sha(outp)})
times["join_s"] = round(time.perf_counter() - t0, 2)
with open(os.path.join(work, "sheet.csv"), "w", newline="") as f:
wr = csv.DictWriter(f, fieldnames=list(rows[0]))
wr.writeheader()
wr.writerows(rows)
print(json.dumps(times))
# run: python pipeline_ad_variations.py clip.mp4 workdirThe exact script we ran for the timings. It needs only ffmpeg and ffprobe (set FFMPEG to the ffmpeg path, or have both on your path) and the Arial Bold font file at the path in the script. Run it once per source clip.
Method and limits
- The master, the hook pieces and the source clip are all the same film, so this tests the mechanics of building a grid, not whether a hook works. We did not test which version performs better.
- The hook and call to action lines are neutral text we wrote for the test. A real grid needs claims approved by the client.
- The 16:9 and 1:1 versions are crops of a 2.4:1 picture; the 9:16 crop is 300 px wide and was enlarged to 1080 px.
- CPU only, on a laptop shared with other work. 0 runs were discarded and redone because another encoder, browser or script of ours was busy during them. Windows background processes (the antivirus, the screensaver, search) did use CPU during the runs; they are listed in the result file, and the run times carry that noise.
- Footage: Tears of Steel, (CC) Blender Foundation, mango.blender.org, CC-BY 3.0.
Page checked on Nov 4, 2026.