Video by Code Skill
A runnable toolkit and production workflow for human–agent teams making deterministic videos in code. All scene code stays inside the repository or project workspace; all generated media, audio takes, stills, and verification receipts live in an explicit external $PROD directory.
Order of work: brief → audio & timing → style & prompt → 3 design stills → scene code → determinism & text-bounds gate → full render → verify & contact sheet → delivery receipt
1. Environment & Smoke Check
Before building a new film, ensure the starter dependencies are installed and the 4-second smoke test passes from the repository root:
cd starter && npm ci && cd ..
node tests/runtime-contract.mjs
2. Production Directory & Intent (RUNBOOK.md §1–2)
- Choose an absolute production directory outside the code checkout:
PROD="/absolute/path/to/video-outputs/<project-slug>" mkdir -p "$PROD"/{audio,analysis,stills,renders,checks} - Copy
templates/brief.mdto"$PROD/brief.md"and fill in the audience, core takeaway, aspect ratio (1920x1080landscape or1080x1920vertical), duration, voice/music source, and safe-area margins.
3. Audio Identity & Timing (docs/04-music-audio-and-timing.md, docs/05-narration-and-captions.md)
Never animate to guessed timestamps. Measure the actual audio file first and record its SHA-256 hash:
uv run tools/timing/audio-identity.py "$PROD/audio/source.wav" \
--out "$PROD/analysis/identity.json" --copy-wav "$PROD/analysis/analysis.wav"
- Spoken narration:
- Synthesize via local Kokoro ONNX TTS (with
< 4word fragment merge and--say say.jsonphonetic dictionary):uv run tools/timing/kokoro-narrate.py script.txt --out-dir "$PROD/audio" --voice af_heart --say say.json - Verify spoken audio round-trip via local
whisper-cli:uv run tools/verify/verify-narration.py "$PROD/audio/narration.wav" "$PROD/audio/timing.json" - Check scripts/lyrics for verbatim n-gram lift against reference text:
python3 tools/verify/check-lift.py candidate.txt reference.txt
- Synthesize via local Kokoro ONNX TTS (with
- Music / lyric / stem-reactive tracks:
- Separate 6 stems via Demucs (
vocals, drums, bass, guitar, piano, other) and normalize 44.1 kHz WAV:uv run --python 3.12 tools/timing/separate-stems.py "$PROD/audio/song.mp3" --out-dir "$PROD/analysis" - Extract 120 Hz stem envelopes, monotone musical time
tau, beat/bar phase, silences,features.f32, and 100 fps guitar pitch/vibrato:uv run --python 3.12 tools/timing/analyze-stems.py "$PROD/analysis" --fps 120 --stem-pitch - Align word-level lyrics (
whisper-cli,mlx-whisper,faster-whisper, oracousticvocal-band energy warping):uv run tools/timing/align-words.py "$PROD/analysis/stems/vocals.wav" --script lyrics.txt --backend whisper-cli --out "$PROD/analysis/words.json" - Lightweight single-file cues / beat grid / visualizer envelope:
uv run tools/timing/cue-extract.py "$PROD/audio/song.mp3" --out "$PROD/analysis/cues.json"uv run --python 3.12 tools/timing/beat-grid.py "$PROD/analysis/analysis.wav" --out "$PROD/analysis/beats.json"python3 tools/build-visualizer.py "$PROD/analysis/analysis.wav" --out "$PROD/analysis/features.js"
- Separate 6 stems via Demucs (
4. Style Selection & Prompt Assembly (prompts/README.md)
Browse prompts/styles/INDEX.md (86 authored visual style cards across 13 families) and prompts/briefs/ (5 format briefs: explainer-voiceover, vertical-short, lyric-video, instrumental-visualizer, data-story).
Assemble the combined specification for your chosen style and brief:
python3 tools/build-prompt.py <style-id> --brief <brief-id> --out "$PROD/style-prompt.md"
5. Scene Authoring Contract (lib/API.md, docs/06-building-scenes.md, docs/12-advanced-engines-and-benchmarks.md)
Every scene HTML page loads lib/harness.js (window.H) and optionally:
lib/sound.js(window.SOUND) — procedural Web Audio synthesislib/features.js(window.FEATURES) — 120 Hz binaryfeatures.f32stem cursor, refractory onset pulse, monotonetau(t), andwords.jsonlyric lookuplib/ink-doodle.js(window.INK) — 8 fps deterministic line-boil, wobbled doodle primitives, left-anchored ALL-CAPS write-onmarker, and Ken Burnsplatecameralib/webgl-post.js(createPost) — 4-stage Three.js post-processing (FxOverShader,UnrealBloomPass,FinalGradeShaderwith ACES /paperMode, luma-only impact inversion, glitch, shake, grain, and crisp UI overlay)
Every page exposes:
<canvas id="c" width="1920" height="1080"></canvas>(or1080×1920for vertical)window.DURATION(seconds) andwindow.FPS(default30)window.__ready(Promise resolving after fonts and cached offscreen plates are ready)window.__renderFrame = (t) => { ... }— pure function oftin seconds.- Start every frame with
ctx.reset()(or balancedsave()/restore()). - Use
H.rng(seed)andH.noise(seed)outside the frame loop; never advance mutable state across frames. - Cache paper/surface textures once via
H.paperTexture(...)orH.offscreen(key, w, h, fn). - Expose
window.__textBounds = () => [...]for story-critical text ({text, critical: true, left, right, top, bottom}) so automated safe-area checks can verify every frame.
- Start every frame with
window.scoreSound = (k) => { ... }— schedules procedural sound events at fixed timeline timestamps (automatically suppresses beds/music when--voiceis supplied).
Key Production Rules from Testing
- Safe-area margins & font weights: On macOS Chrome,
Arialonly provides weights400and700(600snaps to700Bold and widens lines by ~9%). Always auditmeasureText(s).actualBoundingBox*across all frames (x: 80..960, y: 190..1640for1080x1920vertical shorts). - Continuous-camera styles (
transit-map, pan-and-zoom): Start camera interpolation atbeat[i].start(neverbeat[i].start - preRollwheniswitches atbeat[i].start, which causes a 1-frame jump), fade beat-local overlays over0.20 s, and guard world-space labels so they only draw when inside the clipped map viewport.
6. Render Stills, Check Determinism & Render Master (docs/07-rendering.md)
- Seek Determinism Gate:
node starter/determinism.mjs path/to/film.html - Design Stills Gate (inspect opening, dense middle, and ending frames before full render):
node starter/render.mjs path/to/film.html --stills 1.5,12.0,24.0 --outdir "$PROD/stills" - Full MP4 Render:
- Reference single-worker Playwright renderer (default 30 fps Canvas2D + procedural audio):
node starter/render.mjs path/to/film.html \ --out "$PROD/renders/master.mp4" --fps 30 --audio page \ --voice "$PROD/audio/narration.wav" - Multi-worker GPU WebSocket renderer (60 fps Three.js / WebGL / kinetic typography):
node tools/render/parallel-ws-render.mjs \ --url "http://127.0.0.1:5173/?capture=1" --duration <DURATION> --fps 60 --workers 4 \ --audio "$PROD/analysis/analysis.wav" --out "$PROD/renders/master.mp4" - Browserless Python + Pillow
rawvideorenderer (captioned workbooks & tutorials):uv run tools/render/workbook-render.py \ --spec workbook.json --audio "$PROD/audio/narration.wav" --out-dir "$PROD/renders"
- Reference single-worker Playwright renderer (default 30 fps Canvas2D + procedural audio):
7. Mandatory Verification Gates (docs/08-verification.md)
Every production must run and record these checks in "$PROD/checks/" before handoff:
- Stream, Decode, Sync & Loudness Gate:
uv run tools/verify/verify-video.py "$PROD/renders/master.mp4" \ --expect-seconds <DURATION> --fps 30 --width <W> --height <H> \ --json "$PROD/checks/verify-video.json" - Contact Sheet Visual Inspection:
Visually inspectuv run tools/verify/contact-sheet.py "$PROD/renders/master.mp4" \ "$PROD/checks/contact-sheet.jpg" --n 16 --cols 4 --tile-width 270contact-sheet.jpgand the scene stills for text clipping, label collisions, or unintended blank/frozen frames. - Transition & Cut Harshness Audit:
uv run tools/verify/cut-harshness.py "$PROD/renders/master.mp4" \ --top 15 --json "$PROD/checks/cut-harshness.json" - Look & Palette Diagnostics:
uv run tools/verify/measure-look.py "$PROD/renders/master.mp4" \ --samples 16 --json "$PROD/checks/measure-look.json" - All-Frame Text Bounds Audit:
Follow the pattern in
tests/layout.mjsto verifyfillTextink bounds andwindow.__textBounds()across every frame0 .. frames-1.
8. Packaging & Delivery (RUNBOOK.md §12)
Complete "$PROD/qa.md" (from templates/qa.md) and "$PROD/delivery.md" (from templates/delivery.md). Report machine verification (PASS/WARN dispositions) separately from human creative viewing and listening approval.
Key References
README.md— Quickstart and chapter indexRUNBOOK.md— 12-step human–agent production checklistlib/API.md— ExactHgraphics andSOUNDprocedural audio contractexamples/README.md— Worked landscape, vertical, and style-study examplesdocs/10-pitfalls.md— Symptom → cause → repair table