# CLI

Validate, expand and render scenes from the terminal with motion-sdk.

`motion-sdk` is the native, headless side of Motion SDK. It validates a scene, expands templates for the lean player, and renders stills, GIFs and MP4s on the GPU or on a software adapter.

```bash title="Terminal"
cargo install --locked --path crates/motion-sdk-cli
motion-sdk --version
```

Every command takes a scene file. Each one exits `0` on success and `1` on any error, so you can use it in scripts and CI.

## `validate`

Check a scene. Prints each issue with its JSON Pointer path and a suggested fix.

```bash title="Terminal"
motion-sdk validate scene.json
motion-sdk validate scene.json --final --json
```

| Flag | Description |
| --- | --- |
| `--final` | Treat dangling references as errors. Use it on a finished document. |
| `--json` | Print the machine-readable report, `{"issues": [...]}`. |

The exit code is `1` only when there's an error. Warnings print but still exit `0`. See [Error Codes](/docs/reference/errors) for every code.

## `verify`

Check a scene against what the brief expects, such as "moves right during the first second", "ends at the centre", "appears before the subtitle" or "stays in frame". It samples the evaluated timeline natively, with no GPU. Each failure prints the node, expected versus actual, the time and a fix hint.

```bash title="Terminal"
motion-sdk verify scene.json checks.json
motion-sdk verify scene.json checks.json --json --fps 120
motion-sdk verify scene.json --trace --fps 30 --nodes arm,head
```

| Flag | Description |
| --- | --- |
| `--json` | Print the machine-readable report, `{"ok", "checks", "passed", "failures": [...]}`. |
| `--fps <N>` | Timeline samples per second (1 to 1000). It overrides the document's `fps`, which defaults to 60. |
| `--trace` | Print the sampled timeline as JSON instead of checking: per node and sample, world position, rotation, scale, opacity, color and screen bounds. No checks file is needed. |
| `--nodes <a,b>` | With `--trace`, keep only these node ids. |

The scene is validated in final mode first. Validation errors come back as one `invalid_scene` failure. The exit code is `1` when any check fails. See [Verify Motion](/docs/agents/verify) for every check and failure code, and for custom checks that read the trace.

## `expand`

Expand prefabs, repeats, shatter and SVG drawings into plain nodes. Prefab output is the scene the lean browser player loads without the authoring bundle. Expanded SVG drawings are 2D shapes, which still need the authoring bundle. The authoring and WebGL2 bundles also read SVG drawings directly.

```bash title="Terminal"
motion-sdk expand scene.json -o scene.player.json
```

| Flag | Description |
| --- | --- |
| `-o`, `--output <FILE>` | Write here. The default is stdout. |

Generated nodes keep their ids, such as `lamps.3.bulb` and `painter#arm-right`. The output still passes `validate`, which accepts plain ids joined by `.` or `#` as node and track ids. Treat it as a build artifact and edit the original.

## `render`

Render headless. With no `-t` it renders a whole export: MP4, GIF or a PNG sequence. With `-t` it renders one PNG frame.

```bash title="Terminal"
motion-sdk render scene.json -t 1.5 -o frame.png
motion-sdk render scene.json --export x_square
motion-sdk render scene.json --preset tiktok -o reel.mp4
motion-sdk render scene.json --preset x_gif --width 480 --fps 15 --gif-colors 64
```

The scene is validated in final mode first. Each warning and error prints to stderr once. Errors stop the render.

### Target

| Flag | Description |
| --- | --- |
| `--export <NAME>` | Render this entry of `exports`. Its format decides the output. |
| `--preset <PRESET>` | Use a preset directly, such as `x_16x9`, `x_1x1`, `x_9x16`, `x_gif`, `linkedin`, `instagram_reel`, `tiktok` or `slide_16x9`. Can't be combined with `--export`. |
| `-t`, `--t <SECONDS>` | Render one PNG frame at this time instead of the whole export. |
| `-o`, `--output <PATH>` | The output file, or a directory for `png-sequence`. The default is `<scene>-<export>.<ext>` next to the scene, or `out.png` for one frame. |

With neither `--export` nor `--preset`, the render uses the scene's `canvas` size and the timeline's duration. See [Export](/docs/features/export) for every preset.

### Overrides

| Flag | Description |
| --- | --- |
| `--format <FORMAT>` | `mp4`, `gif`, `png-sequence` or `png`. |
| `--width <PX>` | Width in pixels, up to 8192. |
| `--height <PX>` | Height in pixels, up to 8192. MP4 needs even sizes. |
| `--fps <FPS>` | Frames per second. |
| `--start <SECONDS>` | Start time. |
| `--duration <SECONDS>` | How many seconds to export. |
| `--cover` | Crop to fill the frame instead of keeping the whole design visible. |

Give only `--width` or only `--height` and the other side keeps the shape the target would have had, from the preset, the `exports` entry or the canvas. `--preset x_1x1 --width 90` renders 90x90, and `--preset x_16x9 --width 480` renders 480x270. For MP4 the derived side rounds to an even number. Give both to set any size.

### Quality

| Flag | Default | Description |
| --- | --- | --- |
| `--motion-blur <SAMPLES>` | off | Subframes averaged per frame, 2 to 64. |
| `--shutter <FRACTION>` | `0.5` | Shutter as a fraction of the frame interval. Used with `--motion-blur`. |
| `--encoder <ENCODER>` | `auto` | MP4 encoder. `auto` and `openh264` use the built-in OpenH264. `ffmpeg` uses libx264 from `ffmpeg` on your `PATH`. |
| `--dither <DITHER>` | `ordered` | GIF dithering. `ordered`, `fs` (Floyd-Steinberg) or `none`. |
| `--gif-colors <N>` | from quality | GIF palette size, 2 to 255. |

### Loops

Exports with `seamless_loop` are checked after rendering. The first and last frames are compared and the result prints as `loop: ...`.

| Flag | Description |
| --- | --- |
| `--require-seamless` | Exit `1` if a seamless-loop export doesn't loop cleanly. Use it in CI. |
| `--no-loop-check` | Skip the check. |

A GIF over 15 MB prints a warning, since X rejects it. Lower `--width`, `--fps` or `--gif-colors`.

## `plugins`

List installed plugins: executables named `motion-sdk-<name>` next to `motion-sdk` or on `PATH`.

```bash title="Terminal"
motion-sdk plugins
motion-sdk plugins --json
```

| Flag | Description |
| --- | --- |
| `--json` | Print `[{"name", "path"}]`. |

Any other first word runs a plugin. `motion-sdk img2scene compare scene.json ref.png` runs `motion-sdk-img2scene compare scene.json ref.png` with the same stdio and exit code, and with `MOTION_SDK_BIN` set to this binary. An unknown name exits `2`, like other usage errors, and lists the commands and installed plugins. See [Plugins](/docs/guides/plugins).

## Headless GPUs

The CLI uses wgpu. On a machine without a GPU it runs on a software Vulkan adapter such as llvmpipe.

```bash title="Terminal"
WGPU_BACKEND=vulkan motion-sdk render scene.json -t 0 -o frame.png
```

Renders are deterministic for a given adapter. See [Determinism](/docs/concepts/determinism).
