Scene from clip
The user gives you a clip and about ten seconds of it. You rebuild those seconds as a three.js scene made of blocks, shot for shot, until it matches the clip frame by frame. That scene then tells an image model and a video model exactly what a prompt cannot: where the camera is, what is in frame, how big, and when.
The idea everything else follows from:
The scene pins down only what a prompt can't: camera, framing, cuts, timing, and who is where in the frame, how big, and when. Pose, which way someone turns, face and texture go in the prompt.
| The scene carries (hard to prompt) | The prompt carries (easy to prompt) |
|---|---|
| camera position, height, lens, moves | body pose: standing, crouched, lunging |
| cuts and shot lengths | expression, mouth, where the eyes go |
| each character's screen position and size | look and texture: real skin, snow spray |
| paths and timing: enters at, leaves at | speed words: whips, freezes, stalks |
So do not polish poses and faces in three.js. Match placement, framing and timing; stop there.
Where things are
Everything lives in the folder this file is in (the skill folder). Run every command from there.
scene.js scene.html player.html render.mjs the scene, one frame of it, the side-by-side player, the renderer
tools/ fetch, cuts, measure, compare (one line each in README.md)
examples/template.json start a new scene from this
examples/blocks/blocks.json a colour-coded block scene with one moving camera
examples/ski/ the worked example: 5 shots, a skier, a raptor, a T-rex; and the robot swap
prompts/ the example's still and video prompts, word for word
work/<name>/ everything about the user's clip goes here (gitignored)
First run in a fresh copy: npm install. It needs Node 18+, ffmpeg, uv (it installs each Python tool's packages
on first use) and, for a video page URL, yt-dlp. Rendering uses the installed Chrome; without Chrome run
npx playwright install chromium once. If one is missing, say which and how to install it; do not work around it.
The scene format (objects, keys, cameras, shots) is documented at the top of scene.js. Read that header before
writing a spec.
What you need from the user
- The clip: a URL (YouTube or anything
yt-dlpreads), a direct video link, or a local file. - The range: start and end, about ten seconds. Longer works but every step is per frame, so cost grows with it.
- A short name for the work folder (pick one yourself if they gave none).
If the clip or the range is missing, ask for it. Nothing else needs asking before step 5.
The clip is the user's reference for measuring. It stays in work/, which git ignores. Never commit it, never send a
frame of it to an image or video model (step 8 says what to send instead), and tell the user that publishing someone
else's footage is their call and their risk, not something this skill does.
The steps
Steps 1 to 5 are the start and need no decision from the user: do them in one go, then show the player.
1. Fetch the clip
python3 tools/fetch-clip.py "<URL or file>" <start> <end> <name>
Start and end are seconds or m:ss. It writes work/<name>/ref.mp4, every frame as work/<name>/ref/0000.png …
(frame 0 = the start), and work/<name>/clip.json with fps, frame count and size. Use those numbers from here on:
the scene's fps is the clip's, rounded (23.976 → 24, 29.97 → 30), duration is frames / fps, size is the clip's.
2. Find the cuts
uv run tools/cuts.py work/<name>/ref --sheet work/<name>/cuts.jpg --json work/<name>/cuts.json
It prints cuts: 0,14,89,150,198,240: the first frame of every shot, then the frame count. Every later tool takes
that list. Open the sheet and check each cut and each near miss: a whip pan or a flash reads as a cut, a dissolve
reads as none. Correct the list by hand. Cuts must be exact to the frame; a cut two frames off fails validation. No cuts at all
(0,<frames>) is a single shot: confirm it on the reference sheets of step 3.
3. Read the clip before you stage anything
Look at every frame, not stills every half second: a sample hides whether the subject moves or the camera does. (In the example the builder assumed the skier skis. She stands still for eight of the ten seconds.)
uv run tools/pair-sheets.py work/<name>/ref - work/<name>/sheets-ref --cuts <cuts>
With - in place of a render folder this gives sheets of the reference alone, 20 frames each. Read all of them. Then get the camera's
motion as numbers. Write work/<name>/track-init.json with the cuts and an empty track list
({"cuts": [...], "fps": 24, "tracks": []}) and run:
uv run tools/motion-track.py work/<name>/ref work/<name>/track-init.json work/<name>/motion.json
Per shot it prints pan, tilt, zoom and roll from the background's flow: the average per second, the total over the
shot, and every fast move inside a shot with its frames (a held shot with one quick tilt in it is a different shot
from a slow steady tilt, and the average hides that). (A character that fills the frame is read as
background here; the numbers get better in step 7, when tracked characters are masked out.) Now write down, per shot, in
work/<name>/shots.md: frames from–to; the camera (height, angle, lens: long, normal or wide; what it does); who or
what is in frame, where (fractions of the frame) and how big; what moves, from which frame to which; who enters or
leaves and when. This is the plan the scene is built from. Titles and captions laid over the picture are not part of
the scene: note them and leave them out.
4. Build the scene as blocks
Copy examples/template.json to work/<name>/scene.json and replace everything in it.
- One block per character or object that matters, at real size in metres (a standing adult is about
0.5 × 1.75 × 0.3). Blocks first. A model (
human,robot,raptor,trex,skierinscene.js, or one you add toMODELSthere) comes later and only where a block's outline is not enough to judge the framing. - One camera shot per shot of the clip,
startandendon the cut frames, written as frame / fps (a rounded value is fine: shots are matched by frame number), each withposandlookkeys and its ownfov. Guess the lens from the picture: a flat, compressed background is a long lens (fov 10 to 25), a normal view 35 to 50, a stretched one 60 and up. - Stage each shot like a film set. Objects jump to new marks at a cut: two keys 0.001 s apart, the second one
half a frame BEFORE the cut, at (cut frame - 0.5) / fps, so the first frame of the new shot is fully on the new
mark. Continuity between shots is a cheat in real films too. Hide an object by keying its
yto -200. - A clip with several places (a street, then a room) gets one set per place, far apart on the floor (x = -100,
0, +100, with
"floor": 300), so no set shows up in another's background. - A block can lean or slant:
rot_keys [[t, pitch, yaw, roll]]in radians. - The guide needs screen size, not true size. If a character has to be bigger or smaller in one shot to fill the
frame as in the clip, give it
scale_keysfor that shot. The models never see the world, only the frame. - Keep cameras out of scenery (a camera inside a tree renders as a wall).
- Place by solving, not by eye, as soon as you have a screen position:
python3 tools/place.py ground …gives the floor point seen at a screen spot,pointthe spot at a distance you choose (for what hangs, or stands with its foot out of frame),aimthe look point that puts a world point on a screen spot,projectchecks where a point lands. Always pass--clip work/<name>/clip.json: the maths depends on the frame's shape, and a film clip is rarely 16:9. Read screen spots offuv run tools/grid.py work/<name>/ref/0000.png work/<name>/grid-0000.jpg.
Worlds: no world gives a white floor with a 1 m grid, which is the right start. For a wide landscape raise floor,
add fog for haze, and keep far masses within the draw distance (see the header of scene.js). "world": "snow" and "park"
exist for the examples; a new setting is a new function in scene.js, and it only has to get the big masses right
(where is ground, where is sky, where is a wall of trees or houses).
5. Render it and open the player
node render.mjs "scene.html?spec=work/<name>/scene.json" work/<name>/render all --mp4 work/<name>/render.mp4
node tools/serve.mjs
Run the server in the background. The player is at
http://127.0.0.1:8770/player.html?spec=work/<name>/scene.json&ref=work/<name>/ref.mp4: the clip on the left, the
scene on the right, on one clock. Space plays, the arrow keys step one frame, shift + arrow one second, yellow ticks
mark the cuts, and it reloads itself whenever the spec or scene.js changes. The player shows natural colours
(look=real); render.mjs shows the spec's block colours unless the page has &look=real. Same geometry either way. Give the user this link now. They watch
the scene come together while you work, and they catch what you cannot.
Then make the paired sheets, reference above render, for every frame:
uv run tools/pair-sheets.py work/<name>/ref work/<name>/render work/<name>/pairs --cuts <cuts>
6. A second, fresh agent checks every frame
Never validate your own scene. The builder sees what it meant to build. Start a fresh subagent with the Agent tool. Give it the paths of the reference frames, the render frames, the paired sheets and the cut list, and the split from the top of this file. Do not give it your notes, your plan or what you think is wrong.
Its brief, in your words: compare every frame pair in work/<name>/pairs/ (all sheets, all frames, no sampling).
Per shot report: do the cuts match to the frame; for each character, screen position and size at the first, middle
and last frame of the shot as fractions of the frame, in the reference and in the render; the camera (height, angle,
lens, move) in both; who enters or leaves and at which frame, in both; a verdict per shot (match, partial, fail,
broken) and the three biggest gaps, each with frame numbers. Judge placement, framing and timing. Do not judge
faces, poses or texture: the prompt carries those.
Fix what it found, render, make new sheets, and send a new fresh agent. Repeat until placement and timing hold.
7. Measure what the validator cannot settle by eye
Eyes are good at "wrong" and bad at "by how much". Measure, in this order.
Position and size. One start box per character per shot goes into track-init.json
({"name": "skier", "shot": 1, "frame": 0, "box": [x0, y0, x1, y1]}, read off tools/grid.py, on a frame where the
character is sharp and whole; examples/ski/track-init.json is a full one). Then:
uv run tools/motion-track.py work/<name>/ref work/<name>/track-init.json work/<name>/motion.json
uv run tools/track-overlay.py work/<name>/ref work/<name>/motion.json work/<name>/overlay
node tools/render-boxes.mjs "scene.html?spec=work/<name>/scene.json" work/<name>/boxes.json
uv run tools/motion-diff.py work/<name>/motion.json work/<name>/boxes.json work/<name>/diff.png --map skier@1=skier raptor@1=raptor
Look at the overlay sheets before you believe a number: the tracker's mistakes are not the scene's.
motion-diff prints the gap per pair in centre, top and bottom as fractions of the frame, and plots both curves.
Aim for centres within about 0.03. Then re-place with tools/place.py and render again.
What the tracker can and cannot do:
- A tracked box keeps roughly the size it started with. Compare centres. For size, use a tight box (a head), not a body box that gets cut off by the frame.
- On a fast, blurred subject the tracker slides onto the background. Use
--untilto stop that pair there. - A scene box is clamped at the frame edge, so something that left the frame can read as "fits". Look at the frame.
- Solve with the lens of that frame. On a zooming shot the fov changes every frame.
- A head that drops in frame may be the pose or a zoom, not distance. Solve one start position, then move it a short step; do not solve a path from the head alone.
Camera. The per-shot table from motion-track.py (pan, tilt, zoom, roll) is the reference camera's move. Give the
scene's camera the same drift: a pan is a moving look, a zoom is fov_keys, a roll is roll.
Rotation (people only): which way the body and the head point, in degrees relative to the camera.
uv run tools/pose-yaw.py ref work/<name>/ref work/<name>/motion.json work/<name>/yaw-ref.json --track skier@1 head@2
uv run tools/pose-yaw.py render work/<name>/scene.json work/<name>/yaw-render.json --object skier
uv run tools/pose-yaw.py diff work/<name>/yaw-ref.json work/<name>/yaw-render.json work/<name>/yaw.png --cuts <cuts>
The body direction belongs in the scene only when it changes the outline in frame (profile or frontal). The exact head turn usually goes into the prompt as a number of words ("head turned a little to the left").
Where the scene stops. When cuts are exact, centres are within about 3 % of the frame and each shot's big masses are in the right place, stop. What is still off (a slope the flat floor cannot make, a pose that leaves the frame) is written down per shot and handed to the still and the prompt. Tell the user where you stopped and why.
8. Speed: the blur map
A blurred patch in a sharp film frame means fast motion there. That finds the beats:
uv run tools/blur-map.py work/<name>/ref.mp4 --cuts <cuts> --sheet work/<name>/blur.jpg
It lists, per shot, the frame runs where part of the picture suddenly loses sharpness, and where. From that and the
frames, write a beat sheet in work/<name>/beats.md, one row per beat: shot, frames, what happens, fast, slow or
held, the measured blur, and whether the scene or the prompt carries it. Film scenes are built from speed contrast:
in nearly every shot one thing is fast and one is slow, and a reveal comes before an attack. A scene that moves
everything at one even speed is why a copy looks flat. The scene stages when and where a beat happens. The prompt
names the beat and its speed.
9. Stills: first and last frame of every shot
Ask the user before the first generation: stills and video cost money or quota, and they choose the tools.
Render each shot's first and last frame in natural colours (add &look=real to the page):
node render.mjs "scene.html?spec=work/<name>/scene.json&look=real" work/<name>/guide frames 0 13 14 88
Each frame becomes a film still in an image model (Gemini in the example). The rules that held:
- The geometry goes in as a picture, the text only says what to change. Image 1 is the three.js frame. The prompt says: use image 1 only for the camera angle, the framing, and where everything is and how big, never for its look. Then one or two sentences on who is there and what they do. Do not describe positions in words; the picture already has them.
- Only your own renders go to the model. No frame of the reference clip.
- Same opening line for every still, then the frame's own line. A new chat per still, except: the shot's last still gets the shot's first still as image 2 ("the same woman as image 2"), so the cast matches.
- A still can carry what the scene could not: a slope, a background, a pose that would leave the frame in 3D. Say it in the frame's line.
- Name what must not vanish. "A dark shape in the trees" was dropped; "the head of a T-rex at the top right" was not.
- Check each still against its three.js frame for position and size (side by side, or
tools/grid.pyon both). One framing follow-up in the same chat usually fixes a still that came back too wide.
prompts/ski-stills.prompt.txt is the full set for the example. If the user makes the stills by hand in a chat,
tools/grab.sh work/<name>/stills/f0000.png picks each download up under the right name.
10. Video: two tools, two kinds of input
| Kling (Omni) | Google Vids | |
|---|---|---|
| Takes | a guide video (the three.js render of the shot) + the first still + prompt | the first and the last still + prompt |
| The timing comes from | the guide video | the prompt, between the two stills |
| Good for | face close-ups; shots whose move the scene already plays right | shots that must end in a pose; beats named in the prompt |
| Fails at | it invents the ending (no last frame); words cannot speed up what the guide plays slowly | may refuse a photoreal face close-up; two nearly equal stills give a frozen shot |
One clip per shot, then cut them together on the reference's cut frames. Kling's guide video per shot:
node render.mjs "scene.html?spec=work/<name>/scene.json&look=real" work/<name>/guide-s2 range 14 88 --mp4 work/<name>/guide-s2.mp4
The Kling prompt opens: "@image_1 is the first frame. Continue it as photorealistic live-action footage. @video_1 is
a rough 3D preview of this shot: follow only its camera and the timing of the motion, never its look." The Vids
prompt opens: "@Image1 is the first frame and @Image2 is the last frame of one continuous shot." Both are in
prompts/, per shot. tools/kling.py sends a shot to Kling's API if the user has a key (tools/kling-key.py);
everything also works by hand in the web apps.
11. Prompts in beats
Write the action as numbered beats, each with its speed and order, taken from the beat sheet:
Beat 1, very fast, within the first half second: she shoots past the camera in a motion blur. Beat 2: behind her the T-rex steps out of the trees. Beat 3, slow and heavy: two steps, then it rears up and roars.
- Give it something else to do, not a "don't". "It does not run at the camera" was ignored twice. "It steps out, takes two steps, rears up and roars" worked.
- Name the blur where you measured one ("her head whips round in a motion blur"), and name stillness too ("she freezes, not blinking").
- Beats work where the model is free to time the move (first + last still). Where a guide video sets the timing, a beat has to be staged in the scene, not written.
- A slow reveal needs a hint of the thing in the first still, or the model makes it pop out of nothing.
- A short shot's beats spread over the whole generated clip (3 s minimum in most tools). Cut the clip to the shot's length afterwards, or let the last shot run long.
- Run
tools/blur-map.pyon the generated clip: the fast beat should show as a blur run, the held one as sharp.
12. Make it your own: swap a character
Change the object in the spec (another model, or a new one in scene.js), keep camera, cuts and timing. Fit the
new character to the old one's screen size with scale and a lift in y. Then two new stills for the shot:
image 1 = the new three.js frame, image 2 = the new character's design, image 3 = the finished still of the same
shot with the old character, so the world stays identical and the new clip drops into the same cut.
examples/ski/ski-bolt.json and prompts/ski-bolt-stills.prompt.txt are that swap.
What to tell the user, and when
- After step 5: the player link, the shot list with cut frames, and what you are unsure about.
- After each validator round: its verdict per shot, in a table, unedited.
- Before step 9: what the scene matches, what it leaves to the stills and prompts, and what the next step costs.
- Always: numbers where you measured, "by eye" where you did not.
Known limits
- The tools were written while copying one clip (the ski example) and proven on that clip. On other footage expect
to adjust thresholds (
cuts.py --thr,blur-map.py --ratio,--texture) and say so when you do. pose-yaw.pymeasures people only.frame-match.pymeasures colour-coded block scenes only, not photoreal stills.cuts.pyfinds hard cuts. Dissolves, fades and whip pans need your eyes on the sheet.- The scene has a flat floor (or one even slope). Real terrain goes into the still.