# Compositions

> The project file, font declarations, and every composition field: size, `fps`, `duration` (including `"auto"`), `background`, `motionBlur`, `grain`, `props` and `description`, plus multiple compositions and `--comp`.

A composition is one canvas: a size, a frame rate, a duration and a stack of layers. A project file
holds one or more of them. This page covers the project file and every composition field; layers have
their [own pages](https://vidmake.app/docs/layers.md).

## The project file

```json title="project.json"
{
  "fonts": [
    { "family": "Brand", "path": "fonts/Brand-Regular.ttf" },
    { "family": "Brand", "path": "fonts/Brand-Bold.ttf" }
  ],
  "compositions": [
    { "id": "main", "width": 1920, "height": 1080, "fps": 30, "duration": "10s", "layers": [] }
  ]
}
```

| key | type | notes |
|---|---|---|
| `compositions` | composition[] | required. The first one is the default for every command |
| `fonts` | `{ family, path }[]` | font files to load in addition to the system fonts (see [Fonts](#fonts)) |
| `theme` | object or file path | design tokens every composition reads as `"$color.accent"`: colors, type styles, motion, layer styles and modes; see [theme](https://vidmake.app/docs/theme.md) |
| `$schema` | string | optional, for editors; see [JSON Schema](https://vidmake.app/docs/schema.md) |

All file paths in a project (`fonts[].path`, layer `src`) are **relative to the project file**, not to the
directory you run vidmake from. Absolute paths work too.

### A single composition

For a quick one-off, the file can be a single composition object with `layers` and no `compositions`
wrapper. Its `id` defaults to `main`:

```json title="card.json"
{ "width": 1280, "height": 720, "duration": "3s", "background": "#f4f1ea",
  "layers": [{ "id": "hello", "type": "text", "text": "Hello", "fontSize": 96, "fill": "#161412" }] }
```

> [!WARNING]
> A bare composition can't declare `fonts` (that key belongs to the project wrapper), and editing it with
> `vidmake set`, `add`, `unset` or `rm` saves it back in the full `{ "compositions": [...] }` form. Use the
> full form for anything you plan to keep.

## Fonts

Text layers find fonts by family name. vidmake loads every font installed on the system, plus the files
listed in `fonts`:

```json
"fonts": [
  { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" },
  { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk-Italic.ttf" },
  { "path": "fonts/JetBrainsMono.ttf" }
]
```

- `family` is the name text layers use in `"font"`. It is matched case-insensitively, and it doesn't have
  to match the name inside the file, so you can call a font `"Brand"`.
- List several files under one family to provide weights and italics; a text layer's `fontWeight` and
  `italic` pick the closest face.
- Without `family`, the font is registered under the name stored in the file. Run
  `vidmake fonts --project project.json` to see it.
- `serif`, `sans-serif` and `monospace` always resolve to an installed font.
- `.ttf`, `.otf`, `.ttc`, `.woff` and `.woff2` files all load; web fonts need no conversion.

A missing font file stops every command with `error: font ./fonts/Brand-Bold.ttf: No such file or directory (os error 2)`.
A text layer asking for a family that doesn't exist fails validation with
`` font family `Brand` not found. Add it to the project's `fonts` list or run `vidmake fonts` to see installed families ``.

> [!TIP]
> Ship font files next to the project and declare them. The video then renders identically on every
> machine, instead of depending on what happens to be installed.

## Composition fields

| field | type | default | notes |
|---|---|---|---|
| `id` | string | required (`main` in a bare file) | referenced by `--comp`, `use` layers and edit paths like `main.fps` |
| `width`, `height` | integer | required | pixels, greater than 0. Use even numbers for H.264/H.265 |
| `fps` | number | `30` | frames per second, greater than 0. Fractional rates like `29.97` work |
| `duration` | time or `"auto"` | `"auto"` | see [Duration](#duration) |
| `background` | paint | transparent | a color, gradient or animated color; see [Background](#background) |
| `layers` | layer[] | `[]` | drawn in order: first = bottom, last = top |
| `props` | object | `{}` | default input props for `{{name}}` placeholders; see [Props](https://vidmake.app/docs/props.md) |
| `markers` | object | `{}` | named times like `{"build": "8.5s"}`, used as `"@build"` and `since('build')`; see [Markers](https://vidmake.app/docs/time.md#markers) |
| `motionBlur` | `{ samples, shutter }` | off | camera motion blur; see [Motion blur](#motion-blur) |
| `grain` | 0..1 | `0` | film grain over the finished frame |
| `description` | string | | free text, shown by `vidmake list` |

Unknown fields are errors, with a suggestion: ``composition `main`: unknown field `motionblur` — did you mean `motionBlur`?``.
Validation also warns when the size is odd, because H.264 and H.265 need even dimensions.

### Duration

`duration` takes any [time value](https://vidmake.app/docs/time.md): `300` (frames), `"10s"`, `"1:30"`. The final frame count is
rounded to a whole frame.

`"auto"`, the default, measures the content: the composition lasts until the latest end of any layer
with a fixed length. A layer has a fixed length when it has:

- an explicit `duration` or `end`,
- media: a `video` or `audio` layer's remaining length (after `trimStart`, divided by `playbackRate`),
  unless it has `"loop": true`,
- a series: a `series` group's total length,
- a component: a `use` layer's referenced composition length,
- captions: the end of the last caption,
- or it is a group containing any of the above (offset by the group's `start`).

Layers without a fixed length (a background `rect`, a looping animation) simply fill whatever duration
results. If nothing has a fixed length, validation fails with
`` could not infer a duration (no layer has a fixed length). Set `duration`, e.g. "duration": "5s" ``.

```json
{ "id": "auto", "width": 1280, "height": 720,
  "layers": [
    { "id": "bg", "type": "rect", "fill": "#f4f1ea" },
    { "id": "clip", "type": "video", "src": "assets/clip.mp4", "trimStart": "2s" },
    { "id": "outro", "type": "text", "text": "Thanks", "fill": "#161412", "start": "4s", "duration": "1.5s" }
  ] }
```

Here the clip lasts 4 seconds (6 minus 2) and the outro ends at 5.5 seconds, so the composition is 5.5
seconds long and `bg` fills all of it. Change the outro and the duration follows. `vidmake list` shows
`duration="auto"`; `validate` and `timeline` print the resolved length.

### Background

`background` is a paint drawn under every layer: a [color](https://vidmake.app/docs/colors.md) (`"#f4f1ea"`), a
[gradient](https://vidmake.app/docs/colors.md) or an animated color like `[[0, "#f4f1ea"], ["5s", "#e9e4d8"]]`.

```json
"background": { "type": "radial", "center": [0.5, 0.4], "radius": 0.9, "stops": ["#f4f1ea", "#e9e4d8"] }
```

Without `background` the composition is transparent. Formats with alpha keep the transparency: WebM
(VP9), MOV (ProRes 4444), GIF and PNG sequences. MP4 has no alpha channel, so transparent areas come out
black. A full-size `rect` as the first layer does the same job as `background`, but can be animated,
blurred and masked like any layer.

### Motion blur

```json
"motionBlur": { "samples": 12, "shutter": 1 }
```

Camera motion blur, like Remotion's `<CameraMotionBlur>`. Each output frame is the average of `samples`
renders spread evenly over the `shutter` frames leading up to it, so anything that moves fast leaves a
trail.

| field | default | notes |
|---|---|---|
| `samples` | `6` | sub-frames per frame. 1 means no blur. Render time grows with the number of samples |
| `shutter` | `0.5` | how long the virtual shutter is open, in frames. `1` blurs over a full frame interval |

`"motionBlur": {}` uses both defaults. Set `"motionBlur": false` on a single layer to render it at the
exact frame, which keeps text and UI elements crisp while the rest of the frame blurs. `render --draft`
turns motion blur off for a fast preview; `still` and `storyboard` include it.

**Demo: Composition motionBlur and grain; the lower bar opts out with motionBlur: false** (rendered video: https://vidmake.app/media/comp-motion-blur.mp4)

```json
{
  "fonts": [{ "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }],
  "compositions": [{
    "id": "blur", "description": "Composition motionBlur and grain; the lower bar opts out with motionBlur: false",
    "width": 1280, "height": 720, "fps": 30, "duration": "3s",
    "background": { "type": "linear", "angle": 180, "stops": ["#f4f1ea", "#e9e4d8"] },
    "motionBlur": { "samples": 16, "shutter": 1 },
    "grain": 0.06,
    "layers": [
      { "id": "blurred", "type": "rect", "y": "36%", "width": 160, "height": 110, "cornerRadius": 3, "fill": "#c92a26",
        "x": { "keys": [[0, 200], ["1.5s", 1080, "easeInOutQuart"]], "repeat": "pingpong" } },
      { "id": "sharp", "type": "rect", "y": "66%", "width": 160, "height": 110, "cornerRadius": 3, "fill": "#161412",
        "motionBlur": false,
        "x": { "keys": [[0, 200], ["1.5s", 1080, "easeInOutQuart"]], "repeat": "pingpong" } },
      { "id": "labelBlur", "type": "text", "text": "motionBlur: { samples: 16, shutter: 1 }", "font": "JetBrains Mono",
        "fontSize": 20, "fill": "#4a4640", "y": "22%" },
      { "id": "labelSharp", "type": "text", "text": "layer \"motionBlur\": false", "font": "JetBrains Mono",
        "fontSize": 20, "fill": "#4a4640", "y": "80%" }
    ]
  }]
}
```

### Grain

`"grain": 0.06` adds monochrome film grain over the finished frame. The pattern changes every frame (it
is seeded by the frame number, so renders stay reproducible). Values are clamped to 0..1; 0.03 to 0.1 is a
subtle range. A layer's own `grain` field applies grain to just that layer ([Effects](https://vidmake.app/docs/effects.md)).

### Description

`description` is free text for people and agents reading the project. `vidmake list` prints it under each
composition, which makes it a good place to document a component's props.

## Multiple compositions

A project can hold several compositions. Common reasons:

- **Formats**: a 16:9 and a 9:16 cut of the same video.
- **Components**: a lower third or a title card used by other compositions through
  [`use` layers](https://vidmake.app/docs/components.md).
- **Separate deliverables**: an intro, a teaser and the full video that share fonts and assets.

**Demo: One project, three compositions: a 16:9 cut and a 9:16 cut share a title component** (rendered video: https://vidmake.app/media/comp-formats.mp4)

```json
{
  "fonts": [
    { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" },
    { "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }
  ],
  "compositions": [
    { "id": "landscape", "description": "One project, three compositions: a 16:9 cut and a 9:16 cut share a title component",
      "width": 1280, "height": 720, "fps": 30, "background": "#f4f1ea",
      "layers": [
        { "id": "title", "type": "use", "ref": "title", "props": { "headline": "Autumn release" } },
        { "id": "format", "type": "text", "text": "landscape · 1280×720", "font": "JetBrains Mono", "fontSize": 18,
          "letterSpacing": 2.2, "uppercase": true, "fill": "#8a857a", "y": "88%", "enter": "fade" }
      ] },
    { "id": "vertical", "width": 720, "height": 1280, "fps": 30, "background": "#f4f1ea",
      "layers": [
        { "id": "title", "type": "use", "ref": "title", "scale": 0.72, "y": "42%", "props": { "headline": "Autumn release" } },
        { "id": "format", "type": "text", "text": "vertical · 720×1280", "font": "JetBrains Mono", "fontSize": 22,
          "letterSpacing": 2.6, "uppercase": true, "fill": "#8a857a", "y": "88%", "enter": "fade" }
      ] },
    { "id": "title", "description": "Reusable title: a headline and a red rule", "width": 960, "height": 300, "duration": "3s",
      "props": { "headline": "Headline" },
      "layers": [
        { "id": "headline", "type": "text", "text": "{{headline}}", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 112,
          "letterSpacing": -5, "fill": "#161412", "y": "42%", "stagger": { "by": "char", "type": "fadeUp", "each": "30ms" }, "exit": "fade" },
        { "id": "rule", "type": "line", "points": [[0, 0], [420, 0]], "y": "82%", "stroke": "#c92a26", "strokeWidth": 4,
          "drawEnd": { "from": 0, "to": 1, "start": "0.4s", "duration": "0.8s", "ease": "easeOutCubic" }, "exit": "fade" }
      ] }
  ]
}
```

`vidmake list` shows what a project contains:

```console
$ vidmake list comp-formats.json
landscape  1280x720 @30fps  duration="auto"  layers=2  props={}
    One project, three compositions: a 16:9 cut and a 9:16 cut share a title component
vertical  720x1280 @30fps  duration="auto"  layers=2  props={}
title  960x300 @30fps  duration="3s"  layers=2  props={"headline":"Headline"}
    Reusable title: a headline and a red rule
```

Every command that takes a project works on the **first** composition unless you pass `--comp <id>`
(short `-c`): `validate`, `timeline`, `inspect`, `trace`, `still`, `storyboard` and `render`. Here is the
vertical cut of the demo above:

```bash
vidmake storyboard comp-formats.json --comp vertical --at 0.3s,1.5s,2.9s --cols 3
vidmake render comp-formats.json --comp vertical -o out/vertical.mp4
```

`vidmake storyboard comp-formats.json --comp vertical --at 0.3s,1.5s,2.9s --cols 3` produces:

![vidmake storyboard comp-formats.json --comp vertical --at 0.3s,1.5s,2.9s --cols 3](https://vidmake.app/media/storyboard-fc9e2fa2c3ec.jpg)

`vidmake validate --all` checks every composition, including components that are only used through
`use`:

```console
$ vidmake validate comp-formats.json --all
✓ landscape — 90 frames (3.00s)
✓ vertical — 90 frames (3.00s)
✓ title — 90 frames (3.00s)
```

An unknown id lists the ones that exist: ``error: no composition `square`. Available: landscape, vertical, title``.

> [!TIP]
> Put the composition you render most often first, and components after it. `vidmake add --comp <id>`
> adds layers to a composition other than the first.

## Editing composition fields

Composition fields are addressed by id in `get`, `set` and `unset`:

```bash
vidmake get project.json main.duration
vidmake set project.json main.duration '"8s"'
vidmake set project.json main.background '"#fbf9f4"'
vidmake set project.json main.motionBlur '{"samples": 8, "shutter": 0.5}'
vidmake unset project.json main.grain
```

See [Editing](https://vidmake.app/docs/editing.md) for paths and the other edit commands.

## Next steps

- [Time](https://vidmake.app/docs/time.md) Every way to write a time, and how layer-local time works.
- [Series and transitions](https://vidmake.app/docs/series.md) Play scenes back to back inside a composition.
- [Props](https://vidmake.app/docs/props.md) Template a composition and override values per render.
- [Components](https://vidmake.app/docs/components.md) Use one composition inside another.
