Write talking-head scripts and produce Instagram reels and YouTube shorts
96%
Does it follow best practices?
Impact
98%
1.07xAverage score across 8 eval scenarios
Low
Low-risk findings worth noting
#!/usr/bin/env python3
"""Generate a DaVinci Resolve Fusion title (.comp) that matches the Hyperframes title look.
The open-source path renders an animated title with Hyperframes (HTML + GSAP,
`render_hyperframes.py`) into an opaque clip. This is the Resolve-native
equivalent: a Fusion composition with alpha that a Resolve timeline composites
live over the footage, so wording, timing and position stay editable in the
Inspector and the title renders in the same pass as the master. Both share the
same design and the same spec (title, emphasised words, subtitle).
Design (identical to assets/hyperframes-motion title): Instrument Serif, white
title with the emphasised words inline in italic accent colour, an accent bar
above, a subtitle below, a soft dark band behind; entrance staggered word by
word (0.055 s per word), exit at 3.25 s; transparent after 3.8 s. The block
is centred on the frame.
How it works: one Text+ node per word. Text+ has one style per node, so per-word
nodes are what makes inline emphasis and a word stagger possible without the
UI-only Character Level Styling modifier. Word positions are laid out here
from the font's metrics (Pillow reads the TTF), so Fusion only draws.
Calibration, measured on Resolve 21 with Instrument Serif at 2160x3840: Text+
`Size` 0.155 renders glyphs at 204.8 px of frame height and `Center` is always
the centre of the text's em box, whatever justification is set. Both are
baked into SIZE_PER_FRAC and the layout below; re-measure if you change fonts
(render "HIHIHIHI", compare its width to Pillow's `getlength`).
Requires: Pillow, the font's TTF files readable here (--font-dir), and the
same family installed on the machine running Resolve (Text+ looks it up by
family name). No Resolve connection is needed to generate the file.
Usage:
fusion_title.py --title "Skills are not enough" --emph not,enough \\
--sub "Non-deterministic by design. You need rules." --out work/motion/title_r04.comp
fusion_title.py --spec work/motion/titles.json --id r04 --out work/motion/title_r04.comp
fusion_title.py ... --aspect 9:16 --resolution 4k --duration 4 --exit 3.25
Then, with Resolve Studio open (see references/fusion-titles.md):
resolve_title.py apply --timeline r04_master --comp work/motion/title_r04.comp --track 2
"""
import argparse
import json
import os
import sys
from pathlib import Path
try:
from PIL import ImageFont
except ImportError: # pragma: no cover
sys.exit("Pillow is required (pip install pillow): it measures the words for layout.")
sys.path.insert(0, str(Path(__file__).resolve().parent))
from render_reel import ASPECTS # noqa: E402
from safe_zones import ZONES # noqa: E402
FONT_DIRS = [
"~/.fonts",
"~/Library/Fonts",
"/Library/Fonts",
"/usr/share/fonts",
"/usr/local/share/fonts",
]
SIZE_PER_FRAC = (
0.155 * 3840 / 204.8
) # Text+ Size per (glyph px / frame height): measured 0.155 -> 204.8 px at 3840
FPS = 30
CH = [
"TopLeftRed",
"TopLeftGreen",
"TopLeftBlue",
"TopLeftAlpha",
"TopRightRed",
"TopRightGreen",
"TopRightBlue",
"TopRightAlpha",
"BottomLeftRed",
"BottomLeftGreen",
"BottomLeftBlue",
"BottomLeftAlpha",
"BottomRightRed",
"BottomRightGreen",
"BottomRightBlue",
"BottomRightAlpha",
]
def hex_rgb(h):
h = h.lstrip("#")
return tuple(int(h[i : i + 2], 16) / 255 for i in (0, 2, 4))
def find_font(font_dir, name):
for d in ([font_dir] if font_dir else []) + FONT_DIRS:
p = Path(os.path.expanduser(d)) / name
if p.is_file():
return str(p)
sys.exit(f"Font file {name} not found in {font_dir or FONT_DIRS} — pass --font-dir.")
def spline(name, keys):
"""BezierSpline with handles that emulate GSAP's power2/3 easing.
keys: (frame, value, ease) where ease is how the segment ARRIVING at this key eases:
'out' (fast start, soft landing), 'in' (soft start, fast end) or 'lin'.
"""
parts = []
for i, (f, v, _) in enumerate(keys):
s = f"[{f}] = {{ {v:.5f}"
if i + 1 < len(keys):
nf, nv, ease = keys[i + 1]
if ease == "out":
s += f", RH = {{ {f + (nf - f) * 0.2:.3f}, {v + (nv - v) * 0.8:.5f} }}"
elif ease == "in":
s += f", RH = {{ {f + (nf - f) * 0.6:.3f}, {v:.5f} }}"
else:
s += f", RH = {{ {f + (nf - f) / 3:.3f}, {v + (nv - v) / 3:.5f} }}"
if i > 0:
pf, pv, ease = keys[i - 1][0], keys[i - 1][1], keys[i][2]
if ease == "out":
s += f", LH = {{ {pf + (f - pf) * 0.6:.3f}, {v:.5f} }}"
elif ease == "in":
s += f", LH = {{ {f - (f - pf) * 0.2:.3f}, {pv + (v - pv) * 0.2:.5f} }}"
else:
s += f", LH = {{ {f - (f - pf) / 3:.3f}, {v - (v - pv) / 3:.5f} }}"
parts.append(s + " }")
return f"{name} = BezierSpline {{ KeyFrames = {{ {', '.join(parts)} }} }},"
# Strictest right rail across the vertical platforms (fraction of frame width).
RIGHT_RAIL = min(z["right rail"][0] for z in ZONES.values())
RAIL_ASPECTS = ("9:16", "1:1") # landscape YouTube has no rail over the frame
RAIL_PAD = 0.25 # keep a sliver of the side margin inside the rail
def esc(t):
return t.replace("\\", "\\\\").replace('"', '\\"')
def build(spec, a):
W, H = ASPECTS[a.aspect][a.resolution]
S = H / 1920.0 if H >= W else W / 1920.0 # design canvas is 1080x1920 (or 1920x1080)
design_w = W / S
exit_f = round(a.exit * FPS)
last = round(a.duration * FPS) - 1
fade_len = 14 # 0.45 s exit, as GSAP
title_px = a.title_size * S
sub_px = a.sub_size * S
pitch = round(title_px * a.line_height)
max_w = (design_w - 2 * a.margin) * S
if a.aspect in RAIL_ASPECTS:
# the block is centred: its right edge must stay left of the strictest right rail
max_w = min(max_w, 2 * (RIGHT_RAIL - 0.5) * W - 2 * a.margin * S * RAIL_PAD)
fr = ImageFont.truetype(find_font(a.font_dir, a.font_regular), round(title_px))
fi = ImageFont.truetype(find_font(a.font_dir, a.font_italic), round(title_px))
fs = ImageFont.truetype(find_font(a.font_dir, a.font_regular), round(sub_px))
words = [(w, w in spec["emph"]) for w in spec["title"].split()]
if not words:
sys.exit("Empty title.")
space = (
fr.getlength(" ") * 1.3
) # a little wider than the font's space: Fusion draws digits/hyphens ~3% wider than Pillow predicts
adv = [(fi if em else fr).getlength(w) + len(w) * a.letter_spacing * S for w, em in words]
lines, cur, cur_w = [], [], 0.0
for i in range(len(words)):
add = adv[i] + (space if cur else 0)
if cur and cur_w + add > max_w:
lines.append(cur)
cur, cur_w = [i], adv[i]
else:
cur.append(i)
cur_w += add
if cur:
lines.append(cur)
if any(adv[i] > max_w for i in range(len(words))):
sys.exit("A single word is wider than the safe area — shorten it or lower --title-size.")
if fs.getlength(spec["sub"]) > max_w:
sys.exit(f"Subtitle too wide for one line: {spec['sub']!r} — shorten it.")
bar_h, bar_gap, sub_gap = 8 * S, 26 * S, 24 * S
title_h = pitch * len(lines)
sub_h = sub_px * 1.25
block_h = bar_h + bar_gap + title_h + sub_gap + sub_h
top = H / 2 - block_h / 2
bar_cy = top + bar_h / 2
line_cy = [top + bar_h + bar_gap + pitch * (k + 0.5) for k in range(len(lines))]
sub_cy = top + bar_h + bar_gap + title_h + sub_gap + sub_h / 2
def fy(py):
return 1.0 - py / H
def fx(px):
return px / W
pos = {}
right_edge = 0.0
for k, line in enumerate(lines):
lw = sum(adv[i] for i in line) + space * (len(line) - 1)
right_edge = max(right_edge, (W + lw) / 2 / W)
x = (W - lw) / 2
for i in line:
pos[i] = (x + adv[i] / 2, line_cy[k])
x += adv[i] + space
accent, fg = hex_rgb(a.accent), hex_rgb(a.fg)
scrim = hex_rgb(a.scrim)
def fade(s, d, hi=1.0):
return [
(0, 0, "lin"),
(s, 0, "lin"),
(s + d, hi, "out"),
(exit_f, hi, "lin"),
(exit_f + fade_len, 0, "in"),
]
def rise(s, d): # 0 -> 1 on entrance, 1 -> 1.6 on exit (keeps drifting up)
return [
(0, 0.0, "lin"),
(s, 0.0, "lin"),
(s + d, 1.0, "out"),
(exit_f, 1.0, "lin"),
(exit_f + fade_len, 1.6, "in"),
]
def textplus(name, text, italic, rgb, size, cx, cy, alpha, ctl, amt, node_pos):
tool, inp = ctl
return f"""{name} = TextPlus {{
Inputs = {{ GlobalOut = Input {{ Value = {last} }}, Width = Input {{ Value = {W} }}, Height = Input {{ Value = {H} }}, UseFrameFormatSettings = Input {{ Value = 0 }},
LayoutType = Input {{ Value = 0 }},
Center = Input {{ Expression = "Point({cx:.5f}, {cy:.5f} + {amt:.4f} * ({tool}.{inp} - 1))" }},
StyledText = Input {{ Value = "{esc(text)}" }},
Font = Input {{ Value = "{esc(a.font_family)}" }}, Style = Input {{ Value = "{"Italic" if italic else "Regular"}" }},
Size = Input {{ Value = {size:.5f} }}, VerticalJustification = Input {{ Value = 3 }}, HorizontalJustification = Input {{ Value = 3 }},
Red1 = Input {{ Value = {rgb[0]:.4f} }}, Green1 = Input {{ Value = {rgb[1]:.4f} }}, Blue1 = Input {{ Value = {rgb[2]:.4f} }},
Opacity1 = Input {{ SourceOp = "{alpha}", Source = "Value" }},
Enabled2 = Input {{ Value = 1 }}, ElementShape2 = Input {{ Value = 0 }}, Level2 = Input {{ Value = 0 }}, Softness2 = Input {{ Value = 3 }},
Red2 = Input {{ Value = 0 }}, Green2 = Input {{ Value = 0 }}, Blue2 = Input {{ Value = 0 }},
Opacity2 = Input {{ SourceOp = "{alpha}S", Source = "Value" }},
Offset2 = Input {{ Value = {{ 0, -0.002 }} }} }},
ViewInfo = OperatorInfo {{ Pos = {{ {node_pos[0]}, {node_pos[1]} }} }},
}},"""
RISE = 42 / 1920.0 # 42 px rise on the design canvas
tools, merges, ctl_splines = [], [], []
prev, n_ch = "MergeBar", 0
def ctl_ref(n):
return f"Ctl{n // 16}", CH[n % 16]
stagger = round(a.stagger * FPS * 1000) / 1000
for i, (w, em) in enumerate(words):
s0 = round(a.start * FPS + i * stagger)
ctl = ctl_ref(n_ch)
tools.append(
textplus(
f"W{i}",
w,
em,
accent if em else fg,
title_px / H * SIZE_PER_FRAC,
fx(pos[i][0]),
fy(pos[i][1]),
f"W{i}A",
ctl,
RISE,
(0, 180 + 40 * i),
)
)
tools.append(spline(f"W{i}A", fade(s0, 18)))
tools.append(spline(f"W{i}AS", fade(s0, 18, 0.45)))
ctl_splines.append((ctl[0], ctl[1], spline(f"Rise{i}", rise(s0, 18)), f"Rise{i}"))
n_ch += 1
merges.append(
f'M_W{i} = Merge {{ Inputs = {{ Background = Input {{ SourceOp = "{prev}", Source = "Output" }}, '
f'Foreground = Input {{ SourceOp = "W{i}", Source = "Output" }}, PerformDepthMerge = Input {{ Value = 0 }} }}, '
f"ViewInfo = OperatorInfo {{ Pos = {{ 220, {180 + 40 * i} }} }} }},"
)
prev = f"M_W{i}"
ctl = ctl_ref(n_ch)
sub_start = round((a.start + 0.53) * FPS)
tools.append(
textplus(
"Sub",
spec["sub"],
False,
fg,
sub_px / H * SIZE_PER_FRAC,
0.5,
fy(sub_cy),
"SubA",
ctl,
RISE / 2,
(0, 180 + 40 * len(words)),
)
)
tools.append(spline("SubA", fade(sub_start, 15, 0.88)))
tools.append(spline("SubAS", fade(sub_start, 15, 0.5)))
ctl_splines.append((ctl[0], ctl[1], spline("RiseSub", rise(sub_start, 15)), "RiseSub"))
n_ch += 1
merges.append(
f'MergeSub = Merge {{ Inputs = {{ Background = Input {{ SourceOp = "{prev}", Source = "Output" }}, '
f'Foreground = Input {{ SourceOp = "Sub", Source = "Output" }}, PerformDepthMerge = Input {{ Value = 0 }} }}, '
f"ViewInfo = OperatorInfo {{ Pos = {{ 220, {180 + 40 * len(words)} }} }} }},"
)
ctl_tools = []
for c in range((n_ch + 15) // 16):
ins = ", ".join(
f'{inp} = Input {{ SourceOp = "{sp}", Source = "Value" }}'
for (t, inp, _, sp) in ctl_splines
if t == f"Ctl{c}"
)
ctl_tools.append(
f"Ctl{c} = Background {{ Inputs = {{ Width = Input {{ Value = 16 }}, Height = Input {{ Value = 16 }}, {ins} }}, "
f"ViewInfo = OperatorInfo {{ Pos = {{ -220, {300 + 60 * c} }} }} }},"
)
ctl_tools += [s for (t, _, s, _) in ctl_splines if t == f"Ctl{c}"]
bar_w = 120 * S
band_h = max(700 * S, block_h + 260 * S) / H
bar_start = round(a.start * FPS) - 3
return (
f"""{{
Tools = ordered() {{
Clear = Background {{
Inputs = {{ GlobalOut = Input {{ Value = {last} }}, Width = Input {{ Value = {W} }}, Height = Input {{ Value = {H} }}, Depth = Input {{ Value = 1 }},
["Gamut.SLogVersion"] = Input {{ Value = FuID {{ "SLog2" }} }},
TopLeftRed = Input {{ Value = 0 }}, TopLeftGreen = Input {{ Value = 0 }}, TopLeftBlue = Input {{ Value = 0 }}, TopLeftAlpha = Input {{ Value = 0 }} }},
ViewInfo = OperatorInfo {{ Pos = {{ 0, 0 }} }},
}},
Scrim = Background {{
Inputs = {{ GlobalOut = Input {{ Value = {last} }}, Width = Input {{ Value = {W} }}, Height = Input {{ Value = {H} }}, Depth = Input {{ Value = 1 }},
["Gamut.SLogVersion"] = Input {{ Value = FuID {{ "SLog2" }} }},
TopLeftRed = Input {{ Value = {scrim[0]:.4f} }}, TopLeftGreen = Input {{ Value = {scrim[1]:.4f} }}, TopLeftBlue = Input {{ Value = {scrim[2]:.4f} }}, TopLeftAlpha = Input {{ Value = {a.scrim_alpha} }},
EffectMask = Input {{ SourceOp = "ScrimMask", Source = "Mask" }} }},
ViewInfo = OperatorInfo {{ Pos = {{ 0, 60 }} }},
}},
ScrimMask = RectangleMask {{
Inputs = {{ OutputSize = Input {{ Value = FuID {{ "Custom" }} }}, MaskWidth = Input {{ Value = {W} }}, MaskHeight = Input {{ Value = {H} }},
PixelAspect = Input {{ Value = {{ 1, 1 }} }}, SoftEdge = Input {{ Value = 0.13 }},
Width = Input {{ Value = 1.2 }}, Height = Input {{ Value = {band_h:.5f} }},
Center = Input {{ Value = {{ 0.5, 0.5 }} }} }},
ViewInfo = OperatorInfo {{ Pos = {{ -110, 60 }} }},
}},
MergeScrim = Merge {{
Inputs = {{ Background = Input {{ SourceOp = "Clear", Source = "Output" }}, Foreground = Input {{ SourceOp = "Scrim", Source = "Output" }},
Blend = Input {{ SourceOp = "ScrimBlend", Source = "Value" }}, PerformDepthMerge = Input {{ Value = 0 }} }},
ViewInfo = OperatorInfo {{ Pos = {{ 220, 60 }} }},
}},
{spline("ScrimBlend", fade(2, 14))}
Bar = Background {{
Inputs = {{ GlobalOut = Input {{ Value = {last} }}, Width = Input {{ Value = {W} }}, Height = Input {{ Value = {H} }}, Depth = Input {{ Value = 1 }},
["Gamut.SLogVersion"] = Input {{ Value = FuID {{ "SLog2" }} }},
TopLeftRed = Input {{ Value = {accent[0]:.4f} }}, TopLeftGreen = Input {{ Value = {accent[1]:.4f} }}, TopLeftBlue = Input {{ Value = {accent[2]:.4f} }}, TopLeftAlpha = Input {{ Value = 1 }},
EffectMask = Input {{ SourceOp = "BarMask", Source = "Mask" }} }},
ViewInfo = OperatorInfo {{ Pos = {{ 0, 120 }} }},
}},
BarMask = RectangleMask {{
Inputs = {{ OutputSize = Input {{ Value = FuID {{ "Custom" }} }}, MaskWidth = Input {{ Value = {W} }}, MaskHeight = Input {{ Value = {H} }},
PixelAspect = Input {{ Value = {{ 1, 1 }} }}, CornerRadius = Input {{ Value = {4 * S / W:.5f} }},
Width = Input {{ SourceOp = "BarWidth", Source = "Value" }}, Height = Input {{ Value = {bar_h / W:.5f} }},
Center = Input {{ Value = {{ 0.5, {fy(bar_cy):.5f} }} }} }},
ViewInfo = OperatorInfo {{ Pos = {{ -110, 120 }} }},
}},
{spline("BarWidth", [(0, 0.0005, "lin"), (bar_start, 0.0005, "lin"), (bar_start + 15, bar_w / W, "out"), (last, bar_w / W, "lin")])}
MergeBar = Merge {{
Inputs = {{ Background = Input {{ SourceOp = "MergeScrim", Source = "Output" }}, Foreground = Input {{ SourceOp = "Bar", Source = "Output" }},
Blend = Input {{ SourceOp = "BarBlend", Source = "Value" }}, PerformDepthMerge = Input {{ Value = 0 }} }},
ViewInfo = OperatorInfo {{ Pos = {{ 220, 120 }} }},
}},
{spline("BarBlend", fade(bar_start, 8))}
{(chr(10) + " ").join(ctl_tools)}
{(chr(10) + " ").join(tools)}
{(chr(10) + " ").join(merges)}
MediaOut1 = MediaOut {{ Inputs = {{ Input = Input {{ SourceOp = "MergeSub", Source = "Output" }} }}, ViewInfo = OperatorInfo {{ Pos = {{ 330, 300 }} }} }}
}}
}}
""",
lines,
words,
right_edge,
)
def main(argv=None):
ap = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
ap.add_argument("--title")
ap.add_argument(
"--emph", default="", help="comma-separated words to emphasise (italic, accent colour)"
)
ap.add_argument("--sub", default="")
ap.add_argument(
"--spec",
help="JSON file: {id: {title, emph: [..], sub}} (same file the Hyperframes title reads)",
)
ap.add_argument("--id", help="entry in --spec")
ap.add_argument("--out", required=True)
ap.add_argument("--aspect", default="9:16", choices=list(ASPECTS))
ap.add_argument("--resolution", default="4k", choices=["1080", "4k"])
ap.add_argument(
"--duration", type=float, default=4.0, help="seconds the host clip lasts (default 4)"
)
ap.add_argument("--start", type=float, default=0.22, help="first word enters at (s)")
ap.add_argument("--stagger", type=float, default=0.055, help="per-word delay (s)")
ap.add_argument("--exit", type=float, default=3.25, help="exit begins at (s)")
ap.add_argument(
"--font-family",
default="Instrument Serif",
help="family name as installed on the Resolve host",
)
ap.add_argument("--font-regular", default="InstrumentSerif-Regular.ttf")
ap.add_argument("--font-italic", default="InstrumentSerif-Italic.ttf")
ap.add_argument(
"--font-dir",
help="directory holding the TTFs for measuring (default: user/system font dirs)",
)
ap.add_argument(
"--title-size", type=float, default=92, help="px on the 1080-wide design canvas"
)
ap.add_argument("--sub-size", type=float, default=40)
ap.add_argument("--line-height", type=float, default=1.0)
ap.add_argument(
"--letter-spacing", type=float, default=-0.5, help="px per character on the design canvas"
)
ap.add_argument(
"--margin", type=float, default=72, help="side margin on the design canvas (px)"
)
ap.add_argument("--accent", default="#F26B21")
ap.add_argument("--fg", default="#FFFFFF")
ap.add_argument("--scrim", default="#080E16")
ap.add_argument("--scrim-alpha", type=float, default=0.88)
a = ap.parse_args(argv)
if a.spec:
if not a.id:
sys.exit("--spec needs --id")
spec = json.loads(Path(a.spec).read_text())[a.id]
spec.setdefault("emph", [])
spec.setdefault("sub", "")
elif a.title:
spec = {"title": a.title, "emph": [w for w in a.emph.split(",") if w], "sub": a.sub}
else:
sys.exit("Give --title (and --emph/--sub) or --spec/--id.")
comp, lines, words, right_edge = build(spec, a)
out = Path(a.out)
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(comp, encoding="utf-8")
print(
json.dumps(
{
"out": str(out),
"lines": [" ".join(words[i][0] for i in ln) for ln in lines],
"words": len(words),
"duration": a.duration,
"right_edge": round(right_edge, 4),
}
)
)
if __name__ == "__main__":
main().tessl-plugin
skills
reel-builder
assets
references
scripts
yap-writer