# Make demo videos with code: the step-by-step guide

You don't need a screen recorder or a video editor. You need three things: an HTML page that animates itself, a script that films it, and a soundtrack that knows where the cuts are. This kit gives you all three.

## What you need

- Node 18 or newer
- `npm i playwright` and then `npx playwright install chromium`
- ffmpeg on your PATH (`brew install ffmpeg` on a Mac, `sudo apt install ffmpeg` on Linux)
- An AI coding tool: Claude Code, Cursor, Codex or v0

## Step 1: Pick the right kind of demo

| You want to show | Build this | Starting point |
|---|---|---|
| A product flow (click, type, result) | A fake UI plus a scripted cursor | `16-scripted-product-demo` |
| An abstract idea | A small interactive machine | `17-ai-explainer-machines` |
| Motion on a real screen | A sandbox with sliders and an autoplay tour | `19-motion-sandbox` |
| A launch or announcement | A canvas trailer with music | `20-launch-trailer-kit` |

## Step 2: Ask for the demo, not the video

Describe the outcome and the feeling, and let the model design the screens and the shot list. A prompt that works:

```text
Create a polished demo under 20 seconds that shows what [product] does.
Make [the key transformation] obvious within the first 5 seconds.
Use a large, easy-to-follow cursor, smooth pacing and minimal, elegant motion.
Invent realistic UI examples and the demo flow that best showcase it.
Build it as one self-contained index.html on a 1600x900 stage.
Support ?record=1 (hide controls) and set window.DEMO_DURATION in seconds.
```

## Step 3: Make it recordable

Every page in this kit follows two contracts. Ask your AI tool to follow one of them:

- **Live contract** (DOM pages): `?autoplay=1` runs the whole tour on its own, and `window.DEMO_DURATION` says how long it takes.
- **Frame contract** (canvas pages): `window.renderAt(t)` draws the exact frame for time `t`, and `window.TRAILER = { length, fps }`. Frame-perfect, even on a slow machine.

## Step 4: Score it

Open `18-cue-composer/index.html`, type your cut times (copy them from your script's caption or scene changes), pick a mood and export the WAV. Or let the pipeline do it with `--music`.

## Step 5: Render

```bash
cd 21-render-pipeline
node render.mjs live ../16-scripted-product-demo/index.html --query "?record=1" \
  --music ../18-cue-composer/index.html --style house --cues "1,3.5,6.5,10,14,18" --drop 3.5 --out headline-lab
node render.mjs frames ../20-launch-trailer-kit/index.html --out launch-trailer
```

You get `name.mp4` (H.264, with music) and `name.gif` (12 fps, 720px, two-pass palette).

## Prompting tips for code-made videos

1. **Name the one moment that matters.** "The mobile screen becomes a desktop screen" beats "show the plugin." The model builds the pacing around it.
2. **Ask for the shot list first.** "Before writing code, list each beat with its timestamp and what the cursor does." Fix the list, then build. It is much cheaper than fixing the video.
3. **Specify the cursor.** Size, color, arc or straight, click feedback. Big and slow reads better on a phone than realistic.
4. **Use a fixed stage.** 1600x900 or 1920x1080, scaled to fit. Pixel positions stay stable across machines, so recordings never shift.
5. **Keep the camera honest.** Zoom in on the action, back out to show context, never more than 1.5x. Ease every move.
6. **Captions are your voice-over.** Three to six words each, one idea per caption, numbered.
7. **Make the music follow the edit, not the reverse.** Write the cuts first, then generate the track from those times.
8. **Render, watch, give timestamped notes.** "At 6s the cards appear before the click lands, delay them 300ms." Specific timestamps get specific fixes.
9. **Loop GIFs, end MP4s.** GIFs should loop seamlessly (`?machine=N&autoplay=1` pattern). MP4s get an end card.
10. **Check reduced motion.** A recordable page can ignore it during autoplay, but the interactive version should respect it.

## Troubleshooting

- **Black or blank frames in WebGL pages:** add the swiftshader flags already in `render.mjs`, or render on a machine with a GPU.
- **GIF too large:** lower `--gif-width` or `--gif-fps`, and avoid animated full-screen grain (static grain compresses far better).
- **Video starts with a white flash:** live mode trims page-load time automatically; increase it with a longer intro beat in your script if needed.
