majiayu000/spellbook / skills/code-film
code-film
Verified用纯代码(three.js 离线渲染 + 合成音频)做有故事、有电影质感的动画短片并导出 MP4。当用户想做短片、动画片、宣传片、角色动画、循环视频、片头、产品故事片,或者说“用代码做个视频”“做一个有趣的短片”“帮我设计个小动画”“make a short film / animated video / motion piece with code”时使用,即使没提 three.js。也用于继续修改这类片子。写实真人、实拍感、AI 视频生成、普通视频剪辑不适用。
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.9 KB |
| assets/character-sheet.tpl.html | other | 27.8 KB |
| assets/characters/clawd-sheets/expressions.jpg | binary | 257.4 KB |
| assets/characters/clawd-sheets/turnaround.jpg | binary | 107.4 KB |
| assets/characters/clawd.js | script | 4.4 KB |
| assets/characters/sprout.js | script | 9.8 KB |
| assets/film-template.html | other | 34.5 KB |
| examples/last-bug/last-bug-demo.js | script | 991 B |
| examples/last-bug/last-bug.html | other | 71.0 KB |
| references/character.md | markdown | 3.4 KB |
| references/craft.md | markdown | 4.6 KB |
| references/story.md | markdown | 2.5 KB |
| scripts/character_sheet.py | script | 1.9 KB |
| scripts/check.pyexecutable | script | 3.2 KB |
| scripts/render.pyexecutable | script | 2.8 KB |
| scripts/stills.pyexecutable | script | 2.7 KB |
| scripts/use_character.pyexecutable | script | 479 B |
scripts/render.py
View on GitHub"""Render every frame, mux the synthesized mix, keep the WAV beside the MP4.
Usage: uv run --with playwright --python 3.12 python -I render.py <film.html> <out.mp4> [--fps 60] [--samples 16] [--crf 17]
Long films: run this in the background. 1080p60 at 16 samples took 0.17 to 0.25 s per frame on an M2 Max.
"""
import argparse
import base64
import subprocess
import sys
import tempfile
import time
import wave
from pathlib import Path
from playwright.sync_api import sync_playwright
SKILL = Path(__file__).resolve().parent.parent
ARGS = ["--ignore-gpu-blocklist"] + (["--use-angle=metal"] if sys.platform == "darwin" else [])
ap = argparse.ArgumentParser()
ap.add_argument("html")
ap.add_argument("out")
ap.add_argument("--fps", type=int, default=60)
ap.add_argument("--samples", type=int, default=16)
ap.add_argument("--crf", type=int, default=17)
a = ap.parse_args()
html, out = Path(a.html).resolve(), Path(a.out).resolve()
wav = out.with_suffix(".wav")
silent = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
ff = subprocess.Popen(["ffmpeg", "-y", "-loglevel", "error", "-f", "image2pipe", "-c:v", "mjpeg", "-r", str(a.fps), "-i", "-",
"-c:v", "libx264", "-profile:v", "high", "-preset", "medium", "-crf", str(a.crf), "-pix_fmt", "yuv420p", silent], stdin=subprocess.PIPE)
with sync_playwright() as p:
browser = p.chromium.launch(channel="chrome", headless=True, args=ARGS)
page = browser.new_page(viewport={"width": 1320, "height": 800})
page.route("**/three.min.js", lambda r: r.fulfill(path=str(SKILL / "assets/vendor/three.min.js"), content_type="application/javascript"))
page.goto(f"file://{html}?render=1")
page.wait_for_function("window.__ready===true", timeout=60000)
dur = page.evaluate("window.__film.dur")
audio = page.evaluate("() => window.getAudio()")
with wave.open(str(wav), "wb") as w:
w.setnchannels(2)
w.setsampwidth(2)
w.setframerate(audio["sr"])
w.writeframes(base64.b64decode(audio["b64"]))
frames, start = round(dur * a.fps), time.time()
for f in range(frames):
data = page.evaluate("([f, n, fps]) => { window.renderFrame(f, n, fps); return document.querySelector('canvas').toDataURL('image/jpeg', .97); }", [f, a.samples, a.fps])
ff.stdin.write(base64.b64decode(data.split(",")[1]))
if f % 300 == 0:
print(f, "/", frames, round(time.time() - start), "s", flush=True)
browser.close()
ff.stdin.close()
if ff.wait():
sys.exit("ffmpeg failed while encoding")
subprocess.run(["ffmpeg", "-y", "-loglevel", "error", "-i", silent, "-i", str(wav), "-c:v", "copy", "-c:a", "aac", "-b:a", "192k", "-ar", "48000", "-shortest", "-movflags", "+faststart", str(out)], check=True)
Path(silent).unlink()
print("done", out, round(time.time() - start), "s")
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |