Skip to content

Latest commit

 

History

History
168 lines (143 loc) · 10.2 KB

AGENTS.md

File metadata and controls

168 lines (143 loc) · 10.2 KB

FrameScript2, for AI agents

FrameScript2 makes videos and motion graphics from TSX. A project is a directory with framescript.json (size, frame rate, entry module) and the entry module, whose default export is the video. It is laid out with CSS and drawn by AntiWebUI (wgpu, no browser); the script runs in V8. A frame is a function of its number.

Paths below are from the root of the repository. From outside it, the same files are at https://raw.githubusercontent.com/frame-script/FrameScript/main/<path>, and in an installed FrameScript at <home>/versions/<tag>/<path> (create-framescript doctor says where the home is).

Making a video for someone

  1. Install. cargo install --git https://github.com/frame-script/FrameScript create-framescript (Rust has to be there: https://rustup.rs). Then create-framescript doctor --json says what is missing and how it is put in; tell the person what will be installed.
  2. Make the project. create-framescript <dir> --yes --no-path puts in what is missing, builds FrameScript (10–30 minutes the first time) and makes the project. Exit code 2 means something is still missing: what to do is in its output. Packages need sudo, which can't ask for a password without a terminal; give the person the command it shows, and go on once they have run it. framescript is <home>/bin/framescript until a new terminal has it on the PATH. A project that came from another computer (its paths to FrameScript aren't there) is pointed at the FrameScript here with create-framescript sync <dir>.
  3. Learn it. Read docs/project.md, docs/reactivity.md and docs/timeline.md, then the pages for what the video needs (below). The project's own AGENTS.md says where its version's documentation and types are.
  4. Write it, in the entry module and the files it imports. Pictures, videos and sounds go in the project (assets/), and paths to them are from the project's directory.
  5. Check it yourself after every change, by rendering frames and looking at them (below). Don't say the video is done until you have.
  6. Export with framescript export <dir> (<dir>/out/<name>.mp4) when the person wants the file, and check the file too. framescript <dir> opens the studio, a window for the person to watch it in.

Checking the video

You can't watch the studio, and code that looks right often draws something else: text off the frame, a box over another, an animation that ends in the wrong place, an empty clip. So look at the video yourself. The whole procedure is docs/checking.md; in short, with renders in check/:

# It loads (an error says its file and line, exit code 1), and how many frames it has.
framescript render . --frame 0 --out check/f-0.png
# The frames where things happen, small: the start and end of each clip and animation.
framescript render . --width 640 --frame 0 --frame 45 --frame 90 --out check/f-{}.png
# One a second (60 fps, up to frame 600).
framescript render . --width 480 $(for f in $(seq 0 60 600); do printf -- '--frame %s ' $f; done) --out check/f-{}.png
# Motion: frames close together across a move.
framescript render . --width 480 --frame 30 --frame 34 --frame 38 --frame 42 --out check/m-{}.png
# After exporting: length, size, sound, and the whole video in one picture.
ffprobe -v error -show_entries format=duration:stream=codec_type,width,height -of compact out/video.mp4
ffmpeg -v error -i out/video.mp4 -vf "fps=1,scale=320:-1,tile=4x4" -frames:v 1 -y check/sheet.png

Then look at every picture: text cut off or too small to read, things off the frame or covered, empty frames, animations that end in the wrong place or at the wrong time, and the picture against the sound. Tell the person what you checked and what you saw.

What is easy to get wrong

  • Components run once, as in SolidJS, not React. What changes over time is a function or a variable, handed over as it is: style={{ opacity: () => frame() / 30 }}. {frame()} in JSX is read once and never changes. <Show when> and <For each> for conditions and lists.
  • Times are frames. seconds(n) is n seconds in frames.
  • useAnimation(async (ctx) => …) runs once; awaiting a move advances the script's own clock to its end. ctx.parallel([...]) for moves at the same time.
  • A frame must not depend on the frames drawn before it: the studio seeks, and an export draws stretches of frames on several workers at once.
  • Text is in <text> (one run of text). Elements are <div>, <text>, <img>, <svg>, and the components of the library. Styles are CSS in camelCase; numbers are pixels.
  • Videos, sounds and exporting need FFmpeg 9 (create-framescript doctor).

The documentation

docs/README.md the index, and the repository's layout
docs/installing.md create-framescript: options, where things go, FFmpeg
docs/project.md a project's files, framescript.json, render / export options, the studio
docs/reactivity.md the one rule: what is followed and what is read once
docs/timeline.md clips, sequences, frames, useVariable, useAnimation, easings
docs/styles.md elements, CSS properties, stacking, text shadows and strokes
docs/media.md pictures, <Video>, <Audio>, <LipSync>, useVoiceLevel
docs/svg.md <svg> shapes, gradients, trim paths
docs/shaders.md <Shader> and WGSL
docs/3d.md framescript/3d: scenes, cameras, lights, shadows, materials, models, panels, effects
docs/export.md codecs, quality, size, workers
docs/checking.md checking a video by rendering frames and looking at them
docs/design/ how it works inside, and why (in Japanese)

The most exact reference is the library's types: packages/framescript/index.ts (and 3d.ts). examples/ has a project for each part: hello, media, lipsync, 3d, model, showcase, motion.

Reading the Rust source

When the documentation doesn't say why something is drawn as it is, the source does. FrameScript's is this repository; in an installed FrameScript it is <home>/versions/<tag>/, Rust and all. AntiWebUI's is another repository, at the commit that Cargo.lock names (source = "git+https://github.com/bea4dev/AntiWebUI?branch=main#<commit>"): cargo's copy of it from the build is in ~/.cargo/git/checkouts/antiwebui-*/<the start of the commit>/ (cargo cleans these up once they go unused), and it is at https://github.com/bea4dev/AntiWebUI/tree/<commit>. For an installed FrameScript, create-framescript doctor --json says all of it (source, and antiwebui: revision, url, checkout).

How a frame is made, and where:

  1. The TSX runs in V8: packages/framescript (reactivity, JSX, clips, animations), loaded by crates/framescript-engine/src/loader.rs into a composition.rs.
  2. What changes is sent to Rust as ops: ext.rs (the ops), commands.rs (what they ask of the node tree), props.rs (style properties by number).
  3. AntiWebUI holds the nodes and lays them out: anti-webui-core's tree.rs, layout.rs (styles and the integer flex layout) and text/ (shaping, on parley).
  4. It paints them into a scene, a display list: anti-webui-core's paint.rs and scene.rs.
  5. The scene is drawn by anti-webui-wgpu's renderer (renderer.rs) at the project's size, and made the size it is shown or written at by FrameScript's resample.rs: in the window by crates/framescript-studio/src/preview.rs, and offscreen by render.rs for PNGs and exports.
  6. A PNG is written by the studio's main.rs; a video by the engine's export.rs, which runs ffmpeg.
FrameScript (crates/framescript-engine/src/)
composition.rs a loaded project: its scripts in V8, and the document they build
loader.rs the modules of a project, TS and TSX transpiled
ext.rs, commands.rs, props.rs the ops, what they ask of the node tree, style properties
render.rs, resample.rs drawing offscreen; a picture at another size
worker.rs, playback.rs the preview's thread, and its sound
media.rs, sound.rs pictures and videos; what sound plays when, and its samples
shader.rs, flat.rs, gpu.rs WGSL of compositions, <Shader>, what the GPU painters share
space/ 3D: <Scene3D>, meshes, glTF models, effects
export.rs the video file, with its sound

crates/framescript-studio/src/ is the framescript binary: main.rs (the command line), studio.rs, preview.rs, timeline.rs, export.rs (the export window), settings.rs, system.rs.

AntiWebUI (src/ of its repository)
anti-webui-core reactivity, the node tree, styles and layout, text, painting into a scene, shaders, SVG, the video element
anti-webui-style the style types
anti-webui-wgpu the wgpu renderer of scenes
anti-webui-video FFmpeg found at run time: decoding, and sound out (ALSA, WASAPI, Audio Queue)
anti-webui-app a platform backend, the renderer and the core wired together
anti-webui-wayland, -x11, -windows, -macos the platforms

Both have docs/design/ (in Japanese), which says how each part works and why: AntiWebUI's 01-pixel-model.md, 03-layout.md and 04-text.md explain where things land, and FrameScript's 00-overview.md the threads, the ops, sound and export.

Working on FrameScript itself

packages/framescript the TypeScript library
crates/framescript-engine V8 + AntiWebUI: ops, compositions, the preview worker, export
crates/framescript-studio the framescript binary
installer create-framescript, a workspace of its own
cargo test --workspace
cargo clippy --workspace --tests --examples
cargo run --release -- render examples/hello -f 120 -o a.png
(cd installer && cargo test)

AntiWebUI is another repository (https://github.com/bea4dev/AntiWebUI); Cargo.toml says how to build with a checkout of it. Why things are as they are is in docs/design/ (in Japanese).