Files
OrbitTv/design/channels/build-dark-blocks.py
T
pauljdandClaude Opus 5.5 12500d0751
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m57s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m34s
After Dark and Horror block ident previews (Batch 2) for review
Five previews from the channels' own Blender scenes; channel assets unchanged. Not in the app.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-03 18:50:08 +00:00

475 lines
25 KiB
Python

#!/usr/bin/env python3
"""After Dark and Horror block idents, Batch 2 previews for Paul's review (3 November 2026 brief).
The 3D comes from blender/build_block_ident.py (the channels' own scenes, with each block's additions); this lays
the sharp 2D on top, as compose_ident.sh does for the channel idents: the channel logo, the After Dark Presents
frame, each event's title, the eye in the moon, the ticket, the film weave, and an original quiet sting.
The channel logos and scenes are read only. Writes orbit-after-dark-blocks/ and orbit-horror-blocks/.
build-dark-blocks.py <blender-blocks folder> [presents|bmovie|drivein|cult|slasher] ...
"""
from pathlib import Path
import importlib.util, json, math, random, shutil, subprocess, sys
from PIL import Image, ImageChops, ImageDraw, ImageFilter, ImageFont
HERE = Path(__file__).resolve().parent
ROOT = HERE.parent.parent
spec = importlib.util.spec_from_file_location('riot', HERE / 'build-riot-blocks.py')
riot = importlib.util.module_from_spec(spec)
spec.loader.exec_module(riot)
kf, ease_out, ease_in, ease_io, glow, fade, tint = riot.kf, riot.ease_out, riot.ease_in, riot.ease_io, riot.glow, riot.fade, riot.tint
DESIGNS = Path('/home/pauljd/Documents/Codex/2026-10-31/referenced-chatgpt-conversation-this-is-an/Orbit-Channel-Designs')
FONTS = ROOT / '.tooling/font-data/fonts'
W, H, FPS, LENGTH, MOVE = 1280, 720, 30, 4.0, 96
SILVER, PINK, GREEN, RED, CREAM, INK = (226, 230, 245), (232, 76, 203), (156, 255, 58), (242, 78, 87), (246, 236, 212), (12, 10, 18)
BLOCKS = {
'presents': dict(title='After Dark Presents', folder='orbit-after-dark-blocks/after-dark-presents', channel='orbit-after-dark'),
'bmovie': dict(title='B-Movie Throwbacks', folder='orbit-after-dark-blocks/b-movie-throwbacks', channel='orbit-after-dark'),
'drivein': dict(title='After Dark Presents: The Midnight Drive-In', folder='orbit-after-dark-blocks/the-midnight-drive-in', channel='orbit-after-dark'),
'cult': dict(title='Cult Classics', folder='orbit-after-dark-blocks/cult-classics', channel='orbit-after-dark'),
'slasher': dict(title='Slasher Saturday', folder='orbit-horror-blocks/slasher-saturday', channel='orbit-horror'),
}
def font(name, size):
return ImageFont.truetype(str(FONTS / name), size)
def text_layer(words, face, fill, spacing=0, stroke=0, stroke_fill=None):
"""Words on their own transparent layer, tight to the letters, with optional letter spacing."""
widths = [face.getbbox(c)[2] for c in words]
width = sum(widths) + spacing * (len(words) - 1) + 2 * stroke + 8
asc, desc = face.getmetrics()
layer = Image.new('RGBA', (int(width), asc + desc + 2 * stroke + 8))
d, x = ImageDraw.Draw(layer), stroke + 4
for c, w in zip(words, widths):
d.text((x, stroke + 4), c, font=face, fill=fill, stroke_width=stroke, stroke_fill=stroke_fill)
x += w + spacing
return layer.crop(layer.getbbox())
def place(canvas, layer, x, y, alpha=1.0, anchor='lt'):
if layer is None or alpha <= 0:
return
if anchor == 'mt':
x -= layer.width / 2
if alpha < 1:
layer = fade(layer, alpha)
canvas.alpha_composite(layer, (round(x), round(y)))
def scaled(layer, sx, sy=None, rot=0):
sy = sx if sy is None else sy
out = layer.resize((max(1, round(layer.width * sx)), max(1, round(layer.height * sy))), Image.LANCZOS)
return out.rotate(rot, Image.BICUBIC, expand=True) if rot else out
class Block:
def __init__(self, key, frames):
self.key, self.cfg, self.frames = key, BLOCKS[key], Path(frames) / key
self.points = json.loads((self.frames / 'points.json').read_text())
logo = Image.open(DESIGNS / self.cfg['channel'] / 'exports' / f"{self.cfg['channel'].replace('-', '_')}_primary.png").convert('RGBA')
self.logo = logo.crop(logo.getbbox())
self.cache = {}
def scene(self, t):
n = min(MOVE, max(1, int(t * FPS) + 1))
if n not in self.cache:
self.cache = {n: Image.open(self.frames / f'frame_{n:04d}.png').convert('RGBA')}
return self.cache[n].copy(), self.points[str(n)]
def logo_at(self, width):
key = ('logo', width)
if key not in self.cache:
self.cache[key] = scaled(self.logo, width / self.logo.width)
return self.cache[key]
def shadowed(self, layer, amount=.8, blur=14):
"""A soft dark shadow under a layer, as the channel ident does over a busy city."""
shade = Image.new('RGBA', layer.size, (0, 0, 0, 0))
shade.putalpha(layer.getchannel('A').point(lambda v: round(v * amount)))
pad = blur * 3
out = Image.new('RGBA', (layer.width + 2 * pad, layer.height + 2 * pad))
out.alpha_composite(shade, (pad, pad))
out = out.filter(ImageFilter.GaussianBlur(blur))
out.alpha_composite(layer, (pad, pad))
return out, pad
def frame(self, t):
canvas, pts = self.scene(t)
getattr(self, f'draw_{self.key}')(canvas, pts, t)
out = Image.new('RGBA', (W, H), (0, 0, 0, 255))
out.alpha_composite(canvas)
return fade_in(out, t)
# ---- After Dark Presents: the shared frame ------------------------------------------------------------------
def after_dark_frame(self, canvas, t, start=1.0, presents=True):
"""The logo, then PRESENTS in thin, wide silver capitals that draw together, then a fine rule."""
logo = self.logo_at(720)
shadowed, pad = self.cache.setdefault('logo_shadow', self.shadowed(logo))
place(canvas, shadowed, 70 - pad, 54 - pad, kf(t, [(start, 0), (start + .5, 1)], ease_io))
if presents:
spacing = round(kf(t, [(start + .5, 34), (start + 1.1, 18)], ease_out))
word = text_layer('PRESENTS', font('barlow-regular.ttf', 34), SILVER + (255,), spacing)
shade, p2 = self.shadowed(word, .9, 8)
place(canvas, shade, 300 - p2, 330 - p2, kf(t, [(start + .5, 0), (start + .9, 1)], ease_io))
rule = kf(t, [(start + .8, 0), (start + 1.3, 1)], ease_io)
if rule > 0:
d = ImageDraw.Draw(canvas)
d.line((300, 378, 300 + 420 * rule, 378), fill=PINK + (230,), width=2)
return 392 # where an event's own title can start
def draw_presents(self, canvas, pts, t):
self.after_dark_frame(canvas, t)
# ---- B-Movie Throwbacks ------------------------------------------------------------------------------------
def draw_bmovie(self, canvas, pts, t):
top = self.after_dark_frame(canvas, t)
title = self.cache.get('bmovie_title')
if title is None:
face = font('anton-regular.ttf', 74)
green = text_layer('B-MOVIE THROWBACKS', face, GREEN + (255,), 3)
deep = text_layer('B-MOVIE THROWBACKS', face, (20, 40, 12, 255), 3)
title = Image.new('RGBA', (green.width + 12, green.height + 12))
title.alpha_composite(deep, (10, 10))
halo = Image.new('RGBA', title.size); halo.alpha_composite(green, (0, 0))
title.alpha_composite(glow(halo, 12, 1.4))
title.alpha_composite(green, (0, 0))
self.cache['bmovie_title'] = title
# The title rises in with a cheap wobble, like a hand-cut title card.
a = kf(t, [(1.9, 0), (2.2, 1)], ease_io)
rise = kf(t, [(1.9, 26), (2.35, 0)], ease_out)
wob = 2.2 * math.sin((t - 1.9) * 14) * kf(t, [(1.9, 1), (2.8, 0)], ease_io) if t > 1.9 else 0
place(canvas, scaled(title, 1, rot=wob) if abs(wob) > .05 else title, 292, top + 6 + rise, a)
# ---- The Midnight Drive-In ---------------------------------------------------------------------------------
def draw_drivein(self, canvas, pts, t):
s, m = pts['screen'], pts['marquee']
# The picture on the screen follows the screen's own light: dark, one flicker, then on.
n = min(MOVE, int(t * FPS) + 1)
level = kf(n, [(30, 0), (34, .85), (37, .35), (41, 1)], lambda u: u)
if level > 0:
w, h = round(s['right'] - s['left']), round(s['bottom'] - s['top'])
picture = self.cache.get('screen_picture')
if picture is None or picture.size != (w, h):
picture = Image.new('RGBA', (w, h))
d = ImageDraw.Draw(picture)
for y in range(h):
u = y / h
d.line((0, y, w, y), fill=(round(16 + 30 * u), round(18 + 10 * u), round(52 + 50 * u), 255))
logo = scaled(self.logo, w * .74 / self.logo.width)
picture.alpha_composite(logo, (round((w - logo.width) / 2), round(h * .1)))
word = text_layer('PRESENTS', font('barlow-regular.ttf', max(12, round(h * .1))), SILVER + (255,), round(h * .05))
picture.alpha_composite(word, (round((w - word.width) / 2), round(h * .1 + logo.height + h * .05)))
self.cache['screen_picture'] = picture
inset = 3
place(canvas, picture.resize((w - 2 * inset, h - 2 * inset)), s['left'] + inset, s['top'] + inset, level)
# The marquee's lettering, set on the lit panel as its bulbs come on.
mw, mh = m['right'] - m['left'], m['bottom'] - m['top']
title = self.cache.get('marquee_title')
if title is None or title.width > mw * .92:
title = text_layer('THE MIDNIGHT DRIVE-IN', font('anton-regular.ttf', round(mh * .66)), INK + (255,), round(mh * .1))
title = scaled(title, min(1, mw * .9 / title.width))
self.cache['marquee_title'] = title
place(canvas, title, (m['left'] + m['right']) / 2, m['top'] + (mh - title.height) / 2, kf(t, [(1.6, 0), (1.9, 1)], ease_io), 'mt')
# Above it all, the After Dark Presents line in small silver capitals, so the frame stays the shared one.
top = text_layer('AFTER DARK PRESENTS', font('barlow-regular.ttf', 28), SILVER + (255,), 14)
shade, p2 = self.shadowed(top, .9, 8)
place(canvas, shade, W / 2 - p2, 72 - p2, kf(t, [(2.0, 0), (2.5, 1)], ease_io), 'mt')
# ---- Cult Classics -----------------------------------------------------------------------------------------
def draw_cult(self, canvas, pts, t):
moon = pts['moon']
self.eye(canvas, moon, t)
top = self.after_dark_frame(canvas, t, start=1.0)
# The ticket flips in like a card turned over, then settles at a slight angle.
flip = kf(t, [(2.3, .02), (2.62, 1)], ease_out)
if t > 2.3:
ticket = self.cache.get('ticket') or self.cache.setdefault('ticket', make_ticket())
card = scaled(ticket, flip, 1, rot=kf(t, [(2.3, 10), (2.75, -4)], ease_out))
place(canvas, card, 300 + (ticket.width - card.width) / 2, top + 4, kf(t, [(2.3, 0), (2.45, 1)]))
def eye(self, canvas, moon, t):
"""The moon opens like an eye, looks aside, then straight at us, blinks once, and stays open."""
x, y, r = moon['x'], moon['y'], moon['r'] * 1.02
opening = kf(t, [(.5, 0), (1.3, 1)], ease_io)
if t > 1.9:
opening = kf(t, [(1.9, 1), (2.0, .05), (2.08, .05), (2.22, 1)], ease_io)
if opening <= 0:
return
size = round(r * 2 + 6)
eye = Image.new('RGBA', (size * 4, size * 4))
d = ImageDraw.Draw(eye)
c, R = size * 2, r * 4
look = kf(t, [(.5, -.42), (1.25, -.42), (1.55, 0)], ease_io)
ix, iy = c + look * R * .5, c + R * .04
d.ellipse((ix - R * .5, iy - R * .5, ix + R * .5, iy + R * .5), fill=(150, 60, 190, 255))
d.ellipse((ix - R * .38, iy - R * .38, ix + R * .38, iy + R * .38), fill=(214, 92, 200, 255))
d.ellipse((ix - R * .2, iy - R * .2, ix + R * .2, iy + R * .2), fill=(10, 6, 16, 255))
d.ellipse((ix - R * .3, iy - R * .33, ix - R * .14, iy - R * .17), fill=(255, 255, 255, 230))
# Only what the lids let through, inside the moon's disc.
mask = Image.new('L', eye.size, 0)
md = ImageDraw.Draw(mask)
half = R * opening
md.ellipse((c - R, c - half, c + R, c + half), fill=255)
disc = Image.new('L', eye.size, 0)
ImageDraw.Draw(disc).ellipse((c - R, c - R, c + R, c + R), fill=255)
mask = ImageChops.multiply(mask, disc)
eye.putalpha(ImageChops.multiply(eye.getchannel('A'), mask))
lids = Image.new('RGBA', eye.size)
ld = ImageDraw.Draw(lids)
ld.arc((c - R, c - half, c + R, c + half), 180, 360, fill=(70, 50, 100, 220), width=round(R * .05))
ld.arc((c - R, c - half, c + R, c + half), 0, 180, fill=(70, 50, 100, 160), width=round(R * .035))
lids.putalpha(ImageChops.multiply(lids.getchannel('A'), disc))
eye.alpha_composite(lids)
small = eye.resize((size, size), Image.LANCZOS)
canvas.alpha_composite(small, (round(x - size / 2), round(y - size / 2)))
# ---- Slasher Saturday --------------------------------------------------------------------------------------
def draw_slasher(self, canvas, pts, t):
logo = self.logo_at(640)
place(canvas, logo, 40, 40, kf(t, [(2.4, 0), (2.9, 1)], ease_io))
title = self.cache.get('slasher_title')
if title is None:
title = text_layer('SLASHER SATURDAY', font('barlow-condensed-medium.ttf', 64), RED + (255,), 10)
self.cache['slasher_title'] = title
# One clean blade glint sweeps left to right, cutting the title out of the black.
u = kf(t, [(2.95, 0), (3.35, 1)], ease_io)
if u > 0:
x0, y0 = 196, 292
edge = round(title.width * u)
cut = title.copy()
mask = Image.new('L', cut.size, 0)
ImageDraw.Draw(mask).polygon([(0, 0), (edge + 20, 0), (edge - 20, cut.height), (0, cut.height)], fill=255)
cut.putalpha(ImageChops.multiply(cut.getchannel('A'), mask))
place(canvas, cut, x0, y0)
if u < 1:
g = Image.new('RGBA', (60, cut.height + 30))
ImageDraw.Draw(g).line((40, 0, 20, cut.height + 30), fill=(255, 226, 226, 230), width=3)
place(canvas, glow(g, 4, 1.6), x0 + edge - 30, y0 - 15)
place(canvas, g, x0 + edge - 30, y0 - 15)
def make_ticket():
"""ADMIT ONE, stamped CULT CLASSICS: cream card, punched edge, pink ink slightly off register."""
w, h = 340, 118
card = Image.new('RGBA', (w, h))
d = ImageDraw.Draw(card)
d.rounded_rectangle((0, 0, w - 1, h - 1), 8, fill=CREAM + (255,))
for y in range(10, h - 6, 16):
d.ellipse((-6, y, 6, y + 10), fill=(0, 0, 0, 0)); d.ellipse((w - 7, y, w + 5, y + 10), fill=(0, 0, 0, 0))
d.line((70, 10, 70, h - 10), fill=(200, 180, 160, 255), width=2)
small = text_layer('ADMIT ONE', font('barlow-semibold.ttf', 18), (90, 60, 80, 255), 4)
card.alpha_composite(small.rotate(90, expand=True), (30, round((h - small.width) / 2)))
word = text_layer('CULT', font('anton-regular.ttf', 40), PINK + (255,), 6)
word2 = text_layer('CLASSICS', font('anton-regular.ttf', 40), PINK + (255,), 6)
under = (150, 40, 150, 140)
for layer, y in ((word, 12), (word2, 60)):
ghost = Image.new('RGBA', layer.size, under); ghost.putalpha(layer.getchannel('A').point(lambda v: v * 140 // 255))
card.alpha_composite(ghost, (90, y + 3))
card.alpha_composite(layer, (88, y))
return card
def fade_in(frame, t):
a = kf(t, [(0, 0), (.3, 1)], ease_io)
if a >= 1:
return frame
black = Image.new('RGBA', frame.size, (0, 0, 0, 255))
return Image.blend(black, frame, a)
# ---- Sound ----------------------------------------------------------------------------------------------------
RATE = riot.RATE
def whirr(n_sec, seed=21):
"""A projector: soft motor hum, and noise fluttering at the shutter's 24 a second."""
rng, n = random.Random(seed), int(n_sec * RATE)
noise = riot.onepole([rng.uniform(-1, 1) for _ in range(n)], .05)
return [(.5 * math.sin(2 * math.pi * 50 * i / RATE) * .4 + noise[i] * 3 * (.6 + .4 * math.sin(2 * math.pi * 24 * i / RATE))) * riot.env(i, n, .5, .7) for i in range(n)]
def warble(n_sec=1.7):
"""A cheap sci-fi warble: a sine sliding up and down with a wide, slow vibrato."""
n, ph, out = int(n_sec * RATE), 0.0, []
for i in range(n):
t = i / RATE
f = (520 + 260 * math.sin(math.pi * t / n_sec)) * (1 + .035 * math.sin(2 * math.pi * 6.5 * t))
ph += 2 * math.pi * f / RATE
out.append((math.sin(ph) + .15 * math.sin(2 * ph)) * riot.env(i, n, .15, .4))
return out
def ambience(n_sec, seed=22):
rng, n = random.Random(seed), int(n_sec * RATE)
return [s * 6 * riot.env(i, n, .4, .5) for i, s in enumerate(riot.onepole([rng.uniform(-1, 1) for _ in range(n)], .01))]
def organ(n_sec=2.6):
"""A low, slightly detuned diminished chord: not quite right, on purpose."""
n, out = int(n_sec * RATE), []
notes = [146.8, 174.6, 207.7]
for i in range(n):
t = i / RATE
s = sum(math.sin(2 * math.pi * f * t) + math.sin(2 * math.pi * (f + .7) * t) + .3 * math.sin(4 * math.pi * f * t) for f in notes)
out.append(s * riot.env(i, n, .5, .9))
return out
def phone(n_sec=.9, seed=23):
"""An old bell telephone, heard through walls: two bells struck twenty times a second, muffled, a little room."""
n, out = int(n_sec * RATE), []
for i in range(n):
t = i / RATE
strike = .55 + .45 * math.sin(2 * math.pi * 20 * t)
s = (math.sin(2 * math.pi * 900 * t) + .7 * math.sin(2 * math.pi * 1180 * t)) * strike
out.append(s * riot.env(i, n, .01, .12))
muffled = riot.onepole(riot.onepole(out, .06), .1)
room = list(muffled) + [0.0] * int(.3 * RATE)
for delay, gain in ((.037, .45), (.061, .32), (.089, .22), (.131, .14)):
k = int(delay * RATE)
for i in range(len(muffled)):
room[i + k] += muffled[i] * gain
return room
def drone(n_sec):
n = int(n_sec * RATE)
return [(math.sin(2 * math.pi * 55 * i / RATE) + .4 * math.sin(2 * math.pi * 82.5 * i / RATE)) * riot.env(i, n, 1, 1) for i in range(n)]
SOUNDS = {
'presents': lambda: riot.mix(LENGTH, [(.6, whirr(3.2), 1)]),
'bmovie': lambda: riot.mix(LENGTH, [(.3, whirr(3.5), .4), (.5, warble(), .5)]),
'drivein': lambda: riot.mix(LENGTH, [(0, ambience(3.9), 1), (1.12, riot.thump(.2, 120, 60, .3, 9), .5), (1.55, riot.tick(9), .15)]),
'cult': lambda: riot.mix(LENGTH, [(.4, organ(3.3), .5), (1.92, riot.thump(.12, 160, 90, .1, 10), .25)]),
'slasher': lambda: riot.mix(LENGTH, [(0, drone(3.9), .25), (.35, phone(), 1), (1.6, phone(), 1)]),
}
# ---- Build ----------------------------------------------------------------------------------------------------
GUIDE = {
'presents': lambda: [(text_layer('PRESENTS', font('barlow-regular.ttf', 30), SILVER + (255,), 6), None)],
'bmovie': lambda: [(text_layer('B-MOVIE', font('anton-regular.ttf', 38), GREEN + (255,), 3), 'glow'), (text_layer('THROWBACKS', font('anton-regular.ttf', 30), GREEN + (255,), 2), 'glow')],
'drivein': lambda: [(text_layer('MIDNIGHT', font('anton-regular.ttf', 30), INK + (255,), 3), 'panel'), (text_layer('DRIVE-IN', font('anton-regular.ttf', 30), INK + (255,), 3), 'panel')],
'cult': lambda: [(scaled(make_ticket(), .52), None)],
'slasher': lambda: [(text_layer('SLASHER', font('barlow-condensed-medium.ttf', 38), RED + (255,), 4), None), (text_layer('SATURDAY', font('barlow-condensed-medium.ttf', 38), RED + (255,), 4), None)],
}
def guide_card(key, d, stem):
channel = BLOCKS[key]['channel']
epg = Image.open(DESIGNS / channel / 'exports' / f"{channel.replace('-', '_')}_epg.png").convert('RGBA')
epg = scaled(epg.crop(epg.getbbox()), .78)
card = Image.new('RGBA', (512, 160))
card.alpha_composite(epg, (10, round((160 - epg.height) / 2)))
lines = GUIDE[key]()
x0, total = 330, sum(l.height for l, _ in lines) + 8 * (len(lines) - 1)
if lines[0][1] == 'panel':
width = max(l.width for l, _ in lines) + 28
d2 = ImageDraw.Draw(card)
d2.rectangle((x0 - 6, (160 - total) / 2 - 12, x0 - 6 + width, (160 + total) / 2 + 12), fill=CREAM + (255,))
for i in range(0, width, 14):
for y in ((160 - total) / 2 - 12, (160 + total) / 2 + 12):
d2.ellipse((x0 - 6 + i - 3, y - 3, x0 - 6 + i + 3, y + 3), fill=(255, 200, 106, 255))
y = (160 - total) / 2
for layer, style in lines:
x = x0 + 8 if style == 'panel' else x0
if style == 'glow':
halo = Image.new('RGBA', card.size); halo.alpha_composite(layer, (x, round(y))); card.alpha_composite(glow(halo, 5, 1.5))
card.alpha_composite(layer, (x, round(y)))
y += layer.height + 8
card.save(d / 'exports' / f'{stem}_guide.png')
card.resize((256, 80), Image.LANCZOS).save(d / 'exports' / f'{stem}_guide_app.webp', quality=90)
def build(key, frames):
cfg = BLOCKS[key]
d = HERE / cfg['folder']
for sub in ('exports', 'review'):
(d / sub).mkdir(parents=True, exist_ok=True)
stem = Path(cfg['folder']).name.replace('-', '_')
block = Block(key, frames)
rendered = []
tmp = d / 'review' / '.frames'
if tmp.exists():
shutil.rmtree(tmp)
tmp.mkdir()
rng = random.Random(5)
for i in range(int(LENGTH * FPS)):
t = i / FPS
f = block.frame(t)
if key == 'bmovie':
f = film(f, t, rng)
f = f.convert('RGB')
f.save(tmp / f'{i:04d}.png')
rendered.append(f)
rendered[-1].save(d / 'review' / f'{stem}_final_still.png')
silent = d / 'exports' / f'{stem}_ident.mp4'
encode = ['-an', '-vf', 'fps=30', '-c:v', 'libx264', '-profile:v', 'main', '-pix_fmt', 'yuv420p', '-preset', 'veryslow', '-tune', 'animation', '-crf', riot.CRF, '-maxrate', '1400k', '-bufsize', '2800k', '-movflags', '+faststart']
subprocess.run(['ffmpeg', '-y', '-v', 'error', '-framerate', str(FPS), '-i', str(tmp / '%04d.png'), *encode, str(silent)], check=True)
sting = d / 'exports' / f'{stem}_sting.wav'
samples = SOUNDS[key]()
riot.write_wav(sting, samples)
measured = riot.loudness(sting)
riot.write_wav(sting, samples, -14.0 + min(riot.STING_LUFS - measured['integratedLufs'], riot.STING_PEAK - measured['truePeakDbfs']))
with_sound = d / 'review' / f'{stem}_preview_with_sound.mp4'
subprocess.run(['ffmpeg', '-y', '-v', 'error', '-i', str(silent), '-i', str(sting), '-map', '0:v', '-map', '1:a', '-c:v', 'copy', '-c:a', 'aac', '-b:a', '96k', '-shortest', '-movflags', '+faststart', str(with_sound)], check=True)
shutil.copy(silent, d / 'review' / f'{stem}_preview_silent.mp4')
guide_card(key, d, stem)
picks = [0, .5, 1.0, 1.4, 1.8, 2.2, 2.6, 3.0, LENGTH - 1 / FPS]
sheet = Image.new('RGB', (1920, 1080 + 70), (7, 22, 50))
ImageDraw.Draw(sheet).text((20, 16), f"{cfg['title']} / block ident preview, {LENGTH:.0f} s", font=font('barlow-semibold.ttf', 32), fill='white')
for n, t in enumerate(picks):
tile = rendered[min(len(rendered) - 1, round(t * FPS))].resize((640, 360), Image.LANCZOS)
riot.label(tile, f'{t:.1f} s' if n < 8 else 'final hold', 22)
sheet.paste(tile, ((n % 3) * 640, 70 + (n // 3) * 360))
sheet.save(d / 'review' / f'{stem}_contact_sheet.png')
report = dict(status='preview-not-integrated', block=cfg['title'], seconds=LENGTH, fps=FPS, size=[W, H], crf=riot.CRF,
identBytes=silent.stat().st_size, ssim=riot.ssim(silent, tmp), guideAppBytes=(d / 'exports' / f'{stem}_guide_app.webp').stat().st_size,
finalHoldStillForHalfSecond=riot.hold_check(rendered), flash=riot.flash_check(silent), sting=riot.loudness(sting))
(d / 'review' / 'checks.json').write_text(json.dumps(report, indent=1))
shutil.rmtree(tmp)
print(json.dumps(report))
def film(frame, t, rng):
"""B-movie print: a gentle gate weave and fine grain, both easing away before the hold so the last frame is clean."""
amount = kf(t, [(0, 1), (2.9, 1), (3.4, 0)], ease_io)
if amount <= 0:
return frame
dx, dy = 1.6 * amount * math.sin(t * 9.1), 1.2 * amount * math.sin(t * 6.3 + 1)
moved = frame.transform(frame.size, Image.AFFINE, (1, 0, -dx, 0, 1, -dy), resample=Image.BICUBIC, fillcolor=(0, 0, 0, 255))
grain = Image.effect_noise(frame.size, 40).convert('RGBA')
return Image.blend(moved, ImageChops.overlay(moved, grain), .18 * amount)
def review_board():
"""One page for Paul: each block's final hold frame and its guide card at app size and at 2x."""
small, big = font('barlow-semibold.ttf', 22), font('barlow-semibold.ttf', 30)
board = Image.new('RGB', (1920, 100 + len(BLOCKS) * 400), (7, 22, 50))
d = ImageDraw.Draw(board)
d.text((40, 30), 'After Dark and Horror block idents, Batch 2 previews: final hold frames and guide cards', font=font('barlow-semibold.ttf', 36), fill='white')
for i, (key, cfg) in enumerate(BLOCKS.items()):
folder, stem, y = HERE / cfg['folder'], Path(cfg['folder']).name.replace('-', '_'), 100 + i * 400
board.paste(Image.open(folder / 'review' / f'{stem}_final_still.png').resize((640, 360), Image.LANCZOS), (40, y))
d.text((720, y), cfg['title'], font=big, fill='white')
d.text((720, y + 46), 'Guide card at app size (256x80) on the guide panel, then at 2x', font=small, fill=(183, 203, 232))
card = Image.open(folder / 'exports' / f'{stem}_guide_app.webp').convert('RGBA')
for (x, w, h, size, at) in [(720, 300, 110, (256, 80), (22, 15)), (1060, 560, 200, (512, 160), (24, 20))]:
panel = Image.new('RGBA', (w, h), (18, 53, 107, 255))
panel.alpha_composite(card.resize(size, Image.LANCZOS), at)
board.paste(panel.convert('RGB'), (x, y + 96))
board.save(HERE / 'orbit-after-dark-blocks' / 'batch2_review.png')
if __name__ == '__main__':
frames = sys.argv[1]
for key in sys.argv[2:] or list(BLOCKS):
build(key, frames)
review_board()