> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vidjutsu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Motion graphics

> Write title cards, lower thirds and animated scenes as HTML, and VidJutsu draws them into a video, frame by frame, on locked-down cloud machines.

A motion graphic here is a web page that can draw any moment you ask for. You (or your agent) write a scene in HTML, CSS and JavaScript with one function, `window.render(t)`, that draws time `t`. VidJutsu opens the page on cloud machines, calls `render(t)` for every frame, and joins the frames into a video in your library. Then you place that video on a timeline like any other clip.

Nothing is generated: the picture is exactly what your page draws. Any web library that can draw a moment on request works, including GSAP, HyperFrames, Three.js and Lottie.

## How it works

1. **Send the files.** `POST /graphics/files` lists every file of your scenes by hash. Small text files go inline; anything else gets an upload link. Files you sent before are never sent again.
2. **Render.** `POST /graphics` with a `film`: the frame size, frame rate, finishing effects and the scenes in order. It answers with a job right away.
3. **Wait.** Poll `GET /graphics/{job_id}` until `state` is `succeeded`. `output.media` is the new video, `output.watch_url` plays it in a browser.
4. **Place it.** Add `output.media` to a project with an `add_media` edit and put it on a track with `insert_clip`. Nothing is placed for you.

A scene that didn't change since an earlier job is reused, not drawn again, so change one title card and only that card is drawn.

## The scene contract

A scene is a folder with an entry page (default `index.html`). The page must define a global function, `window.render(t)` by default, where `t` is seconds from the scene's start. It can return a promise; the frame is taken once it settles.

`render(t)` must draw time `t` from `t` alone:

* **Same `t`, same picture.** Frames are drawn in pieces on many machines and in any order, so `render(t)` can't depend on the frame drawn before it. Set every animated property from `t` on every call, and keep no state between frames.
* **No network.** The page can load its own files and nothing else. Ship libraries, images and fonts in the scene folder; links to a CDN or any other site fail.
* **Clocks are frozen to `t`.** `Date`, `performance.now()` and `requestAnimationFrame` callbacks all see time `t` (callbacks run once a frame, after `render(t)`), and `Math.random()` is seeded, so it returns the same numbers on every machine. CSS animations and transitions don't follow `t`: drive motion from `render(t)` instead.

To check repeatability, each machine draws the first frame of its piece again after its last one. If the two differ, the job stops with `the scene is not repeatable` and names the time, because two pieces that disagree would flicker where they meet.

The usual causes: a value that adds to itself each frame (`x += 2`), a CSS animation or transition, or an image that hasn't loaded when the frame is taken (make `render(t)` async and wait for it). A subtler one: once an element is fully in, set the property to its plain resting value, such as `clip-path: none` rather than an inset of `0%`. Some effects at their end value draw their edge a shade differently depending on the frame before.

## Starter scene: a title card and a lower third

Two scenes, played one after the other. Copy the folder, change the words at the top of each page, and render it.

```text theme={null}
starter/
  film.json
  title/index.html
  lower-third/index.html
```

```json film.json theme={null}
{
  "width": 1920,
  "height": 1080,
  "fps": 30,
  "subframes": 2,
  "effects": [{ "type": "grain", "amount": 0.1 }],
  "scenes": [
    { "dir": "title", "seconds": 5 },
    { "dir": "lower-third", "seconds": 6 }
  ]
}
```

```html title/index.html theme={null}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
  /* The page is the film's frame: 1920x1080. Inter ships with the renderer;
     any other font goes in this folder and loads with @font-face. */
  html, body { margin: 0; width: 1920px; height: 1080px; overflow: hidden; background: #0b0b0b; }
  body { font-family: "Inter", "Helvetica Neue", Arial, sans-serif; color: #f5f5f5; }
  #glow { position: absolute; inset: 0;
          background: radial-gradient(1000px 760px at 28% 50%, #161616 0%, #0b0b0b 72%); }
  #card { position: absolute; left: 160px; right: 160px; top: 0; bottom: 0;
          display: flex; flex-direction: column; justify-content: center; transform-origin: left center; }
  #kicker { font-size: 24px; font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase;
            color: #8a8a8a; margin-bottom: 28px; }
  #title { font-size: 136px; font-weight: 700; line-height: 1.02; letter-spacing: -0.03em; margin: 0; }
  /* Each line is a mask: words rise into it and leave through its top.
     The padding keeps ascenders and descenders inside the mask. */
  .line { display: block; overflow: hidden; padding: 0.06em 0 0.1em; margin: -0.06em 0 -0.1em; }
  .word { display: inline-block; margin-right: 0.22em; }
  #subtitle { font-size: 38px; font-weight: 400; color: #a3a3a3; margin-top: 36px; max-width: 1100px;
              line-height: 1.35; letter-spacing: -0.005em; }
</style>
</head>
<body>
<div id="glow"></div>
<div id="card">
  <div id="kicker"></div>
  <h1 id="title"></h1>
  <div id="subtitle"></div>
</div>
<script>
  // ---- Change these. One scene = one title card; copy the folder for more.
  const CONTENT = {
    kicker: "Episode 4",
    title: ["The week agents", "learned to edit"],   // one string per line
    subtitle: "What changed, what broke, and what to try first.",
  };
  const SECONDS = 5;                 // match "seconds" for this scene in film.json
  const OUT = SECONDS - 0.6;         // the exit starts here

  // ---- Easing: pure functions of a 0..1 progress.
  const clamp = (v) => Math.min(1, Math.max(0, v));
  const span = (t, from, to) => clamp((t - from) / (to - from));   // 0 before, 1 after
  const outQuint = (p) => 1 - Math.pow(1 - p, 5);                   // for things arriving
  const inCubic = (p) => p * p * p;                                 // for things leaving

  // ---- Build the elements once. Drawing never adds or removes them.
  const card = document.getElementById("card");
  const kicker = document.getElementById("kicker");
  const title = document.getElementById("title");
  const subtitle = document.getElementById("subtitle");
  kicker.textContent = CONTENT.kicker;
  subtitle.textContent = CONTENT.subtitle;
  const words = [];
  for (const text of CONTENT.title) {
    const line = document.createElement("span");
    line.className = "line";
    for (const w of text.split(" ")) {
      const word = document.createElement("span");
      word.className = "word";
      word.textContent = w;
      line.appendChild(word);
      words.push(word);
    }
    title.appendChild(line);
  }

  // ---- Draw time t (seconds). Every property is set from t alone, every
  // frame, so any frame can be drawn first, last or twice.
  // In: kicker, words, subtitle. Out: subtitle and kicker fade, then the words
  // leave up through the mask, the last one gone by SECONDS - 0.05.
  window.render = (t) => {
    const fade = inCubic(span(t, OUT - 0.1, OUT + 0.2));

    const k = outQuint(span(t, 0.1, 0.8));
    kicker.style.opacity = k * (1 - fade);
    kicker.style.transform = `translateY(${(1 - k) * 16}px)`;

    words.forEach((word, i) => {
      const inP = outQuint(span(t, 0.3 + i * 0.06, 1.2 + i * 0.06));
      const outP = inCubic(span(t, OUT + 0.1 + i * 0.03, OUT + 0.35 + i * 0.03));
      word.style.transform = `translateY(${(1 - inP) * 120 - outP * 120}%)`;
    });

    const s = outQuint(span(t, 0.9, 1.6));
    subtitle.style.opacity = s * (1 - fade);
    subtitle.style.transform = `translateY(${(1 - s) * 14}px)`;

    // A slow 1.5% push across the whole card, so the hold never freezes.
    card.style.transform = `scale(${1 + 0.015 * span(t, 0.3, SECONDS)})`;
  };
  window.render(0);
</script>
</body>
</html>
```

```html lower-third/index.html theme={null}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
  html, body { margin: 0; width: 1920px; height: 1080px; overflow: hidden; background: #404040; }
  body { font-family: "Inter", "Helvetica Neue", Arial, sans-serif; }
  /* The picture behind the lower third: your footage when FOOTAGE_FPS is
     set (see below), otherwise a plain backdrop. */
  #plate { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
  #backdrop { position: absolute; inset: 0; background: linear-gradient(160deg, #525252 0%, #262626 100%); }
  /* A near-solid panel with a hairline edge: it reads over dark, light and
     busy footage alike. (Frosted glass needs backdrop-filter blur, the
     slowest thing a page can draw, so it is left out.) Over footage that has
     its own captions, move it with left and bottom. */
  #box { position: absolute; left: 160px; bottom: 128px; border-radius: 12px; overflow: hidden;
         padding: 20px 32px 24px; background: rgba(14,14,14,0.94);
         box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08); }
  #who { font-size: 56px; font-weight: 700; letter-spacing: -0.022em; color: #fafafa; line-height: 1.1; white-space: nowrap; }
  #role { font-size: 28px; font-weight: 500; color: #a3a3a3; margin-top: 6px; white-space: nowrap; }
</style>
</head>
<body>
<img id="plate" alt="">
<div id="backdrop"></div>
<div id="box"><div id="who"></div><div id="role"></div></div>
<script>
  // ---- Change these.
  const CONTENT = { name: "Max Jean", role: "Host, The Max Jean Show" };
  const SECONDS = 6;        // match "seconds" for this scene in film.json
  // Footage behind the lower third. 0 draws a plain backdrop. To draw over a
  // take, put take.mp4 in this folder, add to this scene in film.json
  //   "extract": [{"video": "take.mp4", "frames": "f/%04d.jpg", "fps": 30}]
  // and set FOOTAGE_FPS to that fps.
  const FOOTAGE_FPS = 0;

  const clamp = (v) => Math.min(1, Math.max(0, v));
  const span = (t, from, to) => clamp((t - from) / (to - from));
  const outQuint = (p) => 1 - Math.pow(1 - p, 5);
  const inCubic = (p) => p * p * p;

  // ---- Build once.
  const plate = document.getElementById("plate");
  const box = document.getElementById("box");
  const who = document.getElementById("who");
  const role = document.getElementById("role");
  who.textContent = CONTENT.name;
  role.textContent = CONTENT.role;
  if (FOOTAGE_FPS > 0) {
    plate.style.display = "block";
    document.getElementById("backdrop").style.display = "none";
  }

  // ---- Draw time t. render(t) may be async: the frame is taken once it
  // settles, so a still can finish loading first.
  // In: the panel wipes open over the name, then the role rises.
  // Out: the panel wipes shut, taking the text with it, by SECONDS - 0.1.
  window.render = async (t) => {
    if (FOOTAGE_FPS > 0) {
      const n = Math.floor(t * FOOTAGE_FPS + 1e-6) + 1;
      const src = `f/${String(n).padStart(4, "0")}.jpg`;
      if (plate.getAttribute("src") !== src) {
        await new Promise((loaded, failed) => {
          plate.onload = loaded;
          plate.onerror = () => failed(new Error("missing still " + src));
          plate.setAttribute("src", src);
        });
      }
    }
    const inBox = outQuint(span(t, 0.2, 0.9));
    const inRole = outQuint(span(t, 0.45, 1.05));
    const outBox = inCubic(span(t, SECONDS - 0.45, SECONDS - 0.1));

    // Fully open, drop the clip: an inset of 0% can draw its edge a shade
    // differently depending on the frame before, and frames must repeat exactly.
    const open = inBox - outBox;
    box.style.clipPath = open >= 1 ? "none" : `inset(0 ${(1 - open) * 100}% 0 0 round 12px)`;
    role.style.opacity = inRole;
    role.style.transform = `translateY(${(1 - inRole) * 10}px)`;
  };
  window.render(0);
</script>
</body>
</html>
```

Make one scene per title card or segment. A change to one card then draws only that card again, and every other scene comes from the cache.

## The film

| Field | Default | |
| - | - | - |
| `width`, `height` | | Even numbers, at most 3840 each and 3840 x 2160 together. The page is laid out at this size. |
| `fps` | `30` | Output frame rate, 1 to 60. |
| `subframes` | `1` | Frames drawn per output frame and blended together, 1 to 4: `2` gives fast moves a natural motion blur. Each one is drawn, so `2` costs about twice as much. |
| `quality` | `93` | JPEG quality of each drawn frame, 50 to 100. |
| `effects` | none | Up to 4 finishing effects, in order (below). |
| `scenes` | | 1 to 200 scenes, played one after another. At most 600 seconds in all. |

Each scene:

| Field | Default | |
| - | - | - |
| `dir` | top folder | The scene's folder among the files you sent. The scene sees only its own folder. |
| `entry` | `index.html` | The page to open. |
| `render` | `render` | The global function to call: `window[render](t)`. |
| `start` | `0` | The page time of the scene's first frame, to start partway into a page. |
| `seconds` | | How long the scene plays. |
| `extract` | none | Videos in the folder to turn into stills before drawing ([footage in a scene](#footage-in-a-scene)). |

### Effects

Effects run on every frame after it is drawn. Pick them by name:

| Effect | Fields | |
| - | - | - |
| `grain` | `amount`, 0 to 1 | Moving film grain. `0.1` is subtle. |
| `vignette` | `amount`, 0 to 1 | Darker corners. |
| `blur` | `radius`, 0 to 20 pixels | Blurs the whole frame. |

```json theme={null}
"effects": [{ "type": "vignette", "amount": 0.3 }, { "type": "grain", "amount": 0.08 }]
```

## Libraries

Put the library's file in the scene folder and load it with a relative path. A frozen `window.vidjutsu` helper is defined before your scripts run; each adapter sets `render(t)` for you.

| Library | Adapter | What it does |
| - | - | - |
| GSAP | `vidjutsu.gsap(timeline)` | Pauses the timeline and seeks it to `t` for each frame. |
| HyperFrames | `vidjutsu.gsap(timeline)` | HyperFrames animates with a GSAP timeline: ship GSAP and pass that timeline the same way. |
| Three.js | `vidjutsu.three({renderer, scene, camera, update})` | Calls `update(t)` (may be async), then draws the scene with the camera. WebGL is drawn on the CPU. |
| Lottie | `vidjutsu.lottie(animation)` | Goes to `t` in the animation and stops there. |
| Anything else | `vidjutsu.frames(fn)` | Uses `fn(t)` as `render(t)`. |

**GSAP** (and HyperFrames):

```html theme={null}
<script src="gsap.min.js"></script>
<div class="title">Launch day</div>
<script>
  const tl = gsap.timeline();
  tl.from(".title", { y: 80, opacity: 0, duration: 0.8, ease: "expo.out" })
    .to(".title", { opacity: 0, duration: 0.4 }, 4.4);
  vidjutsu.gsap(tl);
</script>
```

Keep everything on the one timeline you pass in. A tween started outside it (or with `repeat: -1` on its own) doesn't follow `t`.

**Three.js:**

```html theme={null}
<script src="three.min.js"></script>
<script>
  const renderer = new THREE.WebGLRenderer({ antialias: true, preserveDrawingBuffer: true });
  renderer.setSize(1920, 1080);
  document.body.appendChild(renderer.domElement);
  const scene = new THREE.Scene();
  const camera = new THREE.PerspectiveCamera(40, 1920 / 1080, 0.1, 100);
  camera.position.z = 6;
  const cube = new THREE.Mesh(new THREE.BoxGeometry(2, 2, 2), new THREE.MeshNormalMaterial());
  scene.add(cube);
  vidjutsu.three({ renderer, scene, camera, update: (t) => { cube.rotation.set(t * 0.6, t * 0.9, 0); } });
</script>
```

Set positions from `t` (`t * 0.9`), never by adding to them each frame (`rotation.y += 0.01`). Physics or particles that step forward need to be stepped from zero up to `t` on every call, or baked ahead of time.

**Lottie:**

```html theme={null}
<div id="anim" style="width: 1920px; height: 1080px"></div>
<script src="lottie.min.js"></script>
<script src="logo.js"></script>  <!-- window.LOGO = { ...the Lottie JSON... }; -->
<script>
  const animation = lottie.loadAnimation({ container: document.getElementById("anim"), renderer: "svg",
    loop: false, autoplay: false, animationData: window.LOGO });
  vidjutsu.lottie(animation);
</script>
```

Pass the animation as `animationData` from a script file rather than `path`: a `path` loads after the page does, so the first frames can be drawn before the animation is there, and the job stops as not repeatable.

## Fonts

Inter, Inter Display, DejaVu Sans and Sans Mono, Liberation (as Arial), JetBrains Mono, Satoshi and Noto Color Emoji are installed. Any other font goes in the scene folder and loads with `@font-face`:

```css theme={null}
@font-face { font-family: "Brand"; src: url("fonts/Brand-Bold.woff2") format("woff2"); font-weight: 700; }
```

Wait for it before the first frame, so frame 0 isn't drawn in a fallback font. `render(t)` can be async: `await document.fonts.ready` at the top works.

## Footage in a scene

To draw over a take, put the video in the scene folder and let the scene turn it into numbered stills before drawing:

```json theme={null}
{ "dir": "lower-third", "seconds": 6,
  "extract": [{ "video": "take.mp4", "frames": "f/%04d.jpg", "fps": 30 }] }
```

The page then shows still `n = floor(t * 30) + 1` at time `t` (the starter lower third does this when `FOOTAGE_FPS` is set). `frames` must be a subfolder with no other scene files. Up to 8 extracts a scene; `start_number` (default 1) and `jpeg_q` (2 best to 31, default 2) are optional.

## Run it

```sh theme={null}
# 1. List every file by hash, with small text files inline.
curl -s -X POST https://api.vidjutsu.ai/graphics/files \
  -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
  -d '{"files": [
        {"path": "title/index.html", "bytes": 3480, "sha256": "4be1...", "text": "<!doctype html>..."},
        {"path": "lower-third/index.html", "bytes": 3971, "sha256": "9c0a...", "text": "<!doctype html>..."}
      ]}'
```

The answer is a `bundle` id and `missing`: a `put_url` for each file that isn't stored yet and wasn't sent inline (images, fonts, footage, large scripts). PUT each file's bytes to its link. Then render:

```sh theme={null}
curl -s -X POST https://api.vidjutsu.ai/graphics \
  -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
  -d '{"bundle": "gb_...", "name": "episode-4-titles", "idempotency_key": "ep4-titles-1",
       "film": {"width": 1920, "height": 1080, "fps": 30, "subframes": 2,
                "effects": [{"type": "grain", "amount": 0.1}],
                "scenes": [{"dir": "title", "seconds": 5}, {"dir": "lower-third", "seconds": 6}]}}'

curl -s https://api.vidjutsu.ai/graphics/job_... -H "Authorization: Bearer $KEY"
```

```json theme={null}
{
  "job_id": "job_...", "kind": "graphics", "state": "succeeded",
  "output": {
    "media": {"id": "...", "asset_hash": "...", "duration": {"ticks": 330, "rate": 30}, "kind": "video", "lineage": []},
    "watch_url": "https://files.vidjutsu.ai/...", "download_url": "https://...", "url": "https://...",
    "source": {"type": "graphics", "bundle": "gb_...", "film": {"width": 1920, "height": 1080, "...": "..."}}
  },
  "usage": {"final": true, "vcpu_seconds": 212.4, "output_seconds": 11}
}
```

The CLI does all of this from a folder with a `film.json`: `vidjutsu graphics render ./starter`. MCP: `graphics_files`, `make_graphics`, `graphics_status` and `cancel_graphics`.

## Place it on a timeline

`output.media` is ready for an `add_media` edit (give it any `id` you like in the project). Graphics videos are opaque and silent, so put full-frame cards where they should cover the picture: on the main track between takes, or on a track above it for the stretch they play.

```json theme={null}
[
  {"op": "add_media", "media": {"id": "titles", "asset_hash": "...", "duration": {"ticks": 330, "rate": 30}, "kind": "video", "lineage": []}},
  {"op": "insert_clip", "track_id": "v1", "ripple": true, "occurrence": {"id": "title-card", "media_id": "titles",
    "source": {"start": 0, "end": 5}, "timeline_start": 0,
    "layout": {"x": 0, "y": 0, "width": 1000, "height": 1000}}}
]
```

With `ripple`, the takes after it move later so sound stays in sync. A lower third over a take can go two ways:

* **Draw the take in the scene** ([footage in a scene](#footage-in-a-scene)), and place the result on a track above the take for the same stretch. Exact, and the panel can be any shape.
* **Render just the panel**: make the film the panel's size (say 720 x 200) and length, and place it in a `layout` box above the take. Cheaper, but the panel is a rectangle: rounded corners show the page's background.

## Edit scenes in a workspace

A workspace is a named folder of scene files with versions, so an agent can change scenes like code instead of resending them:

* `GET /graphics/workspaces/{workspace}` (`graphics_list`): the current `bundle`, its `version`, every file, and earlier bundles.
* `GET /graphics/workspaces/{workspace}/file?path=title/index.html` (`graphics_read`): one file's text.
* `POST /graphics/workspaces/{workspace}` (`graphics_write`): one new version made of `write` (whole text files), `patch` (`{path, find, replace}`, where `find` must occur exactly once), `files` (other files by hash; missing ones get a PUT link), `delete`, or `restore` (an earlier bundle). Send `expected_bundle` from your last read: if someone changed the workspace since, it answers 409 and nothing changes.

Then render with `"workspace": "episode-4"` in place of `bundle`. The job is pinned to the workspace's bundle at that moment, so later writes don't change a running job. To change scenes from an earlier job that didn't use a workspace, `GET /graphics/bundles/{bundle}` (`graphics_source`) gives every file of the bundle in `output.source`.

Files in a workspace are stored, never run: the only thing that runs them is the renderer, inside a job.

## Upright video

For Shorts, Reels and TikTok, render at `1080 x 1920`. Keep text out of the zones each app covers with its own buttons and captions: the top 328 pixels, the bottom 672 and 120 at each side.

## Speed and cost

Graphics are billed by the box time they use, at $0.03 per vCPU-minute by the second, like a render ([pricing](https://docs.vidjutsu.ai/pricing.md)). A 1080p, 30 fps film takes about 16 vCPU-seconds per second of film for each subframe, about $0.48 a minute, plus about 120 vCPU-seconds to start; a re-render after a one-scene change costs far less. There is no price up front.

While a job runs, your wallet holds a small amount at a time and gives back what the job didn't use. `usage.vcpu_seconds` on the job is what you paid for.

Almost all of that time is the browser painting your page on the CPU (there is no GPU), so a lighter page is a cheaper one:

* Large CSS `filter: blur()` and `backdrop-filter` layers are the slowest thing to draw. Use a pre-blurred image instead.
* `subframes` multiplies the work: use `2` for fast motion, `1` for slow fades and text.
* Big WebGL scenes draw on the CPU too: keep polygon counts and resolution in check.
* Scenes that didn't change are free to reuse, so split long films into scenes.

## Limits

| | |
| - | - |
| Length | 600 seconds a film, 200 scenes |
| Frame | 3840 x 2160, 60 fps, 4 subframes |
| Files | 4,000 a bundle, 512 MB a file, 2 GB a bundle |
| Inline text | 256 KB a file, 2 MB a call |
| Workspace write | 200 changes a call |
| Drawing | a page must load within 60 seconds, and each frame draw within 30 |

## Security

Your scenes are code, and they run only inside the renderer, never anywhere else. Each job gets fresh machines that are thrown away afterwards. They hold no keys (only short-lived links to your files) and can reach nothing but storage. The browser runs with its sandbox on, as a user that can read nothing of the job, and every request a page makes outside its own folder is refused. There is no tool or route that runs your code any other way.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.