Animation, audio and effects recipes
Separation of work
The native Swift renderer draws the picture: exact timing, camera, environments, line art, type, diagrams, shaders and layer order, from a scene generated by Ruby (native-workflow.md, recipes in scene-cookbook.md). Python measures audio (stems, music map) and mixes sound. The Swift synth makes the sound effects, and Swift VFX applies final frame-cued camera, light and signal effects. Ruby services own all execution and manifests.
Native Swift scenes and overlays
Use tools/graphics for native macOS drawing and composition. Its MotionGraphics library provides retained paths, Core Text, scene nodes, keyframes, sprite caching, Metal particles/compute effects, 3D, Core Image layers and AVFoundation export. See tools/graphics/README.md in the runtime for the full API and scene-file reference.
Use a scene JSON file with graphics:preview / graphics:render. Final rendering streams layers and audio directly into one movie; preview images are written only on request. --data word, tracking and clip JSON remains available to the native scene loader; wordsData and clipName consume captions/sprites directly, while tracking arrays require custom Swift logic. JavaScript scenes must be ported; no browser runtime remains.
For a complete scene or direct native movie export:
ruby scripts/mv.rb 'graphics:build'
ruby scripts/mv.rb 'graphics:render[tools/graphics/examples/futuristic.json,output/native.mp4,192,1920,1080,24]'Preview first, final last. Every creation or edit iteration renders a draft of only the affected time range with graphics:preview —
1× (no supersampling), 30 fps, roughly 4–6× faster than a final — and the soundtrack cut to that range:
AUDIO=audio/excerpt.wav ruby scripts/mv.rb --project /abs/project 'graphics:preview[scenes/video.json,output/preview.mp4,0,10]' # seconds 0-10Use ONLY= stills of graphics:render for single-frame checks. Render the final (graphics:render with SUPERSAMPLE=2, the delivery frame
rate and BITRATE, then the SFX/VFX finish) only when the user approves the previews or asks for the final; never re-render a delivered final
over itself — use a new output name.
Rendering runs on the GPU by default (neon halos, shader nodes; see the graphics README); GLOW=cg restores the Core Graphics shadows for an A/B check.
PLATE=plate.mp4 composes over a source video and inherits its audio. AUDIO=song.m4a replaces audio. CODEC=prores4444 with a .mov output preserves alpha; H.264/HEVC are opaque. Scene JSON paths are relative to the scene file. Font files register once through the scene's fonts array; text uses the registered PostScript font name. Choose assets, colors and typography to suit the approved direction; the futuristic examples are optional demonstrations.
Project fonts
Just before rendering the video, scan installed macOS fonts and copy only the selected faces into the initialized video workspace:
ruby scripts/mv.rb --project /absolute/video-workspace fonts:listThis recursively lists .ttf and .otf files under /System/Library/Fonts (including /System/Library/Fonts/Supplemental), /Library/Fonts, and ~/Library/Fonts. Choose actual files from the results for the approved typography and required characters. Font collections (.ttc) are excluded; do not rename a collection to .ttf.
Write config/fonts.json in the video workspace, mapping each project filename to its selected absolute source path. For example, only if this file appeared in the scan:
{"title.ttf": "/System/Library/Fonts/Supplemental/Arial Bold.ttf"}ruby scripts/mv.rb --project /absolute/video-workspace 'fonts:copy[config/fonts.json]'The task copies the selected files to that workspace's tools/graphics/fonts/, reports source paths and SHA-256 hashes, and refuses to replace different existing font bytes. JSON preserves source paths containing spaces or commas. Record the selection in docs/PLAN.md, retain applicable license notices, and keep local font files out of the plugin repository. No font installation or download happens during setup.
Register the copied font paths once through the scene JSON fonts array (paths relative to that JSON file), and use their PostScript names in text nodes. Preview representative lyrics, punctuation and non-Latin characters before rendering.
A sprite node uses clipName to read local clip metadata, preserves its audio_at, and keeps only a bounded cache of decoded frames. Place it with x/y/width/height; use metadata box/src to calculate original-source framing. Keyframe tracks animate position, scale, rotation and opacity. Draw background → distant graphics → behind-character text → sprite → foreground captions. See tools/graphics/README.md for the complete schema, node types, filters and Swift extension APIs.
{"version":1,"nodes":[
{"type":"sprite","clipName":"sing","x":1000,"y":150,"width":600,"height":820,
"tracks":{"x":[[0,1000],[2,1100,"outCubic"]]}},
{"type":"karaoke","wordsData":"words","x":200,"y":1000,"size":48}
]}The library includes cached glyph outlines, starbursts, traces, paper shapes, misregistration, deterministic shake, entrance tracks, waveform drawing, captions, reticles, gradients, flares and GPU grain. Keep the lead's mouth large enough to review. Render only selected event frames for diagnostics; do not export every intermediate layer to disk.
Choreography recipes: a mascot runs at the head of a curve leaving a trail; a fall accelerates the camera/world while holding the character in the focal area; a reveal zoom shows the whole diagram; a crowd pose swap ripples outward; a word appears behind hair via layer order. Tie entrances to actual words and beat accents. When text is used, check spacing and readability with the selected font and treatment. Check all important event frames with graphics:preview, then watch the complete section.
Supplied character assets and lipsync
Use supplied local images or clips when the brief includes characters. Draw additional character motion with scene nodes and tracks.
Remove detached captions from an existing alpha sequence with media:keep_component[source_dir,new_out_dir,seed_x,seed_y] through the Ruby CLI. It keeps exact RGBA values of the four-connected nonzero-alpha silhouette containing the seed; no dilation joins text back to hair or props. Choose a torso pixel occupied in every frame. Missing/transparent seeds fail explicitly, and sources remain unchanged. This cannot remove lettering touching the body, instrument or hair: use a deliberate mask or revise the asset. Inspect all motion afterward, including semi-transparent edges and moving limbs.
Use chroma green for cream/white faces/clothes; paper keying can erase them. Inspect the alpha matte, hair, hands, feet and spill over light/dark backgrounds. media:sprite_box helps estimate source-pixel bounds; box is a crop and seed chooses the connected paper-key component.
Use local Demucs vocals aligned to the full song. Keep character placement and mouth motion aligned to the same song clock as the scene.
media:mouth correlates darkness in a mouth crop against vocal energy at 24fps, checking lags from -6 to +6 frames. Supply a mouth ROI in the cutout image's coordinates and the full-song audio start. It is a heuristic for static framing and sufficiently visible dark mouth shapes. Moving faces, low contrast and synthetic silence can make it inconclusive. Verify phonemes/visemes and pauses by watching with audio. Fix timing errors at the source; never stretch the master song or speed-change visible singing.
Sound and assembly
Keep audio/song.wav as the full master. Use integer frame sections; check each section's frame count and contiguity, join picture with media:concat, then replace the audio with one continuous song using media:mux. Do not concatenate independently encoded/faded audio segments. Preserve the original input and derived vocals separately. Keep a clean render before sound effects.
prompts/finish-sfx/sfx.yml:
source: output/clean.mp4
out: output/with-sfx.mp4
rel_db: -6
peak_db: -6
max_gain_db: 18
sounds:
pop: {synth: tick, duration: 0.15, seed: 7}
flatline: {tone: 1000, duration: 1}
swoosh: {synth: whoosh, duration: 0.7, peak: 0.75, from: 300, to: 4200, seed: 2}
boom: {synth: impact, duration: 0.9, freq: 48}
cues:
- {at: 1.25, sound: pop, rel_db: -5, len: 0.25, fade: 0.03}
- {at: 3.475, sound: swoosh, rel_db: -12} # 3.475 = hit 4.0 - peak 0.525 s: the whoosh crests on the hit
- {at: 4.0, sound: boom, rel_db: -8}Use local tone: or synth: settings for the default finish. Stable Audio SFX with prompt: remains available for explicitly requested audio work; see Optional Fal audio. synth: is the Swift SoundSynth (mgraphics --sfx, Synth.swift): whoosh, riser, reverse, impact, subdrop, tick, type, zap, glitch and shimmer, each with duration, seed and its own knobs (frequencies, peak, pan, q). It is deterministic, and the cached sidecar records peak_at, the loudest moment. A cue's at is where the sound starts (leading silence is trimmed), so start a whoosh at hit - peak_at, and a riser or reverse at hit - duration. Keep whooshes subtle (rel_db around -10 to -14) so they sit under the music. SFX are cached by their synthesis settings, duration and seed. Mix trims leading silence, sets cue loudness relative to music in that window, caps gain and peak-limits. Use exact song times, not cut-relative times. Check dialogue intelligibility, silence jokes and audible but subordinate effects. The final mux can add codec peaks, so listen and measure the delivered file if close to full scale.
Swift VFX and native light layers
prompts/finish-vfx/cues.yml:
source: output/with-sfx.mp4
out: output/finished.mp4
cues:
- {fx: punch, f: 24, dur: 8, amt: 0.05, radius: 2}
- {fx: glow, f: 27, dur: 12, amt: 0.4, radius: 12}
- {fx: dark, f: 144, dur: 3, hold: 1, amt: 0.8}Core Image supports punch, zoom, shake, whip, mblur, edgeblur, glow, flash, dark, rgb, glitch, tv, grain, stretch (an area-preserving squash/stretch hit along angle, 0 = wide, 90 = tall; good on word slams) and echo (a span of lighten-blended trails from n earlier frames hold apart; for orbits, tunnels and fast pans on dark grounds), bands (VHS tracking bands rolling down: n strips of height size, shoved sideways with an RGB split; a span) and a sideways rgb split via radius (px; amt stays the radial split). Metal shader cues (tools/vfx/Sources/mvfx/Shaders.swift, run through MetalShader: frame → MTLTexture → MSL compute kernel → CIImage, the offline equivalent of SwiftUI's colorEffect/distortionEffect/layerEffect) add shockwave (a refraction ring from x,y on a landing), streaks (anamorphic flares from thin highlights only — neon lines, dots, small type; big type never smears), lens (barrel + RGB dispersion + vignette; a kick or a span through tunnels) and heat (rising shimmer, optionally a soft disc of radius). Add a kernel there when a look needs per-pixel sampling Core Image filters can't express. Use bands, rgb and grain on a few chosen sections, not everywhere; if the scene already carries grain, do not stack more on top. f/dur are integer frames on a 24 fps cue grid at any video rate: a 60 fps master gets every output frame rendered with cues sampled at its exact time (--from/--to/--only are cue frames too; stills are named by cue frame). bitrate: in cues.yml sets the encode (bits/s, e.g. 15000000). See tools/vfx/Sources/mvfx/Effects.swift for exact knobs. leak, flare, glints are built-in native light cues. Their cached paths/gradients are sampled in memory and screen-blended directly; no light-frame PNGs are produced. Optional lights: path/to/scene.json adds a custom native light scene.
The Swift service builds the package through Ruby, uses AVFoundation decode/encode and streams audio into the same writer. Inspect a short clip and stills before the full render. Use distinct output paths for every finish revision. Effects should follow onsets/cuts/lyrics; start glow after a flash to avoid whiteouts, avoid double grain if Swift graphics already draws it, and preserve deliberate quiet frames. A no-cue VFX render should resemble the clean encode; cued frames should differ measurably, which RSpec checks.