# Captions

> Subtitles from `.srt`, `.vtt` or Whisper-style `.json` files, or inline `items` — line or word-by-word mode, highlighting the spoken word, and styling captions like any text.

A `captions` layer shows timed subtitles: one caption at a time, optionally with the currently spoken
word highlighted (karaoke style) or one word at a time with a pop (the short-form video style). It is a
text layer under the hood, so fonts, outlines, backgrounds and effects all work.

```json
{ "id": "subs", "type": "captions", "src": "talk.srt", "fontSize": 44, "fontWeight": 600,
  "highlight": "#c92a26", "background": "#fbf9f4", "cornerRadius": 4 }
```

**Demo: Line captions from an .srt file with the current word highlighted** (rendered video: https://vidmake.app/media/captions-srt.mp4)

```json
{
  "fonts": [{ "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" }],
  "compositions": [{
    "id": "srt", "description": "Line captions from an .srt file with the current word highlighted",
    "width": 1280, "height": 720, "fps": 30, "duration": "6s",
    "background": { "type": "radial", "center": [0.5, 0.35], "radius": 0.9, "stops": ["#f4f1ea", "#e9e4d8"] },
    "layers": [
      { "id": "avatar", "type": "ellipse", "y": "36%", "width": 180, "fill": { "type": "linear", "angle": 135, "stops": ["#4a4640", "#161412"] },
        "scale": "=1 + 0.03 * sin(t * 9)" },
      { "id": "ring", "type": "arc", "y": "36%", "width": 220, "stroke": "#16141255", "strokeWidth": 2,
        "startAngle": "=t * 60", "endAngle": "=t * 60 + 300" },
      { "id": "subs", "type": "captions", "src": "captions-demo.srt", "font": "Schibsted Grotesk", "fontSize": 42, "fontWeight": 600,
        "letterSpacing": -0.8, "fill": "#161412", "highlight": "#c92a26", "background": "#fbf9f4", "padding": 18, "cornerRadius": 4 }
    ]
  }]
}
```

| field | default | notes |
|---|---|---|
| `src` | | A `.srt`, `.vtt` or `.json` file, relative to the project file. |
| `items` | | Inline captions instead of a file (see below). One of `src`/`items` is required. |
| `mode` | `line` | `line`: the whole caption. `word`: one word at a time, with a pop. |
| `highlight` | none | Paint for the word being spoken (line mode). |
| `y` | `"80%"` | Captions sit in the lower part of the parent by default. |
| `maxWidth` | `"80%"` | Long captions wrap within 80% of the parent width. |
| `duration` | until the last caption ends | |

All [text styling fields](https://vidmake.app/docs/text.md#fields) apply except `text`, `reveal` and `stagger`: `font`,
`fontSize`, `fontWeight`, `italic`, `fill`, `stroke`/`strokeWidth`, `align`, `lineHeight`,
`letterSpacing`, `uppercase`, `background`, `padding`, `cornerRadius`. So do the
[common fields](https://vidmake.app/docs/layers.md): position, anchor, opacity, shadow, presets.

## Caption files

Numbers in caption **files** are seconds, the way transcription tools write them.

**SRT and WebVTT.** Standard cue blocks. Cue numbers, the `WEBVTT` header and cue settings are
ignored, tags like `<b>` or `<v Speaker>` are stripped, and multi-line cues keep their line breaks.

```text title="captions-demo.srt"
1
00:00:00,300 --> 00:00:02,200
Captions come from an SRT file.

2
00:00:02,400 --> 00:00:04,300
The spoken word is highlighted.
```

**JSON.** Either an array of captions, or an object with a `segments` array, which is what
[Whisper](https://openai.com/index/whisper/) and most speech-to-text APIs produce (`captions` and `items`
are accepted as the key too). Each caption needs `text`, `start` and `end`; `words` is optional and its
entries may use `text` or Whisper's `word`:

```json title="whisper.json"
{ "segments": [
  { "start": 0.0, "end": 1.5, "text": " Hello world.",
    "words": [{ "word": " Hello", "start": 0.0, "end": 0.6 }, { "word": " world.", "start": 0.6, "end": 1.5 }] },
  { "start": 1.6, "end": 3.0, "text": " Second line." }
] }
```

Surrounding spaces are trimmed. Time strings such as `"1.5s"` are also accepted in files.

## Inline items

For short videos it is often easier to write the captions into the project. Inline times follow the
usual vidmake rule: **numbers are frames**, strings are times.

```json
"items": [
  { "text": "Stop scrolling", "start": 6, "end": 45,
    "words": [{ "text": "Stop", "start": 6, "end": 24 }, { "text": "scrolling", "start": 24, "end": 45 }] },
  { "text": "and watch this", "start": "1.6s", "end": "3.8s" }
]
```

## Word timing

With `words`, highlighting and word mode follow those exact times. Without them, vidmake spreads the
caption's duration over its words in proportion to their length, which looks natural for most speech.
For real word timings, let vidmake transcribe the speech:

```sh
vidmake transcribe talk.mp4          # writes talk.json, word-timed
vidmake models                       # the transcription models; `vidmake models use <id>` picks one
```

It runs whisper.cpp (`whisper-cli`, shipped beside `vidmake`) with the selected model, which downloads the
first time a transcription needs it. Any other tool's JSON works too: ask it for word timestamps
(Whisper's `word_timestamps=True`) and pass its JSON straight to `src`.

## Line mode and highlight

In `line` mode (the default) the whole caption is shown from its `start` to its `end`, and nothing is
drawn between captions. With `highlight`, the word being spoken is painted with that color or gradient;
between two words, the last word that started stays highlighted.

Long captions wrap at `maxWidth` (80% of the parent by default). With the default `align: "center"`
the caption's box, and therefore its `background`, is always `maxWidth` wide, as the plate in the demo
above is. With `"align": "left"` the box shrinks to the text, so a background hugs short lines.

`inspect` shows the caption that is on screen at a time, with its box:

```console
$ vidmake inspect captions-srt.json -t 1s -l subs
Frame 30 (1.00s) of `srt` (1280x720), 1 visible layer(s), drawn bottom→top:

ID                       TYPE            X        Y       W       H    ROT  SCALE  OPAC  BBOX [x0,y0,x1,y1]          NOTES
subs                     captions    640.0    576.0  1060.0    86.4    0.0   1.00  1.00  [110,533,1170,619]          "Captions come from an SRT file."
```

## Word mode

`"mode": "word"` shows one word at a time, centered, each popping in from 80% scale with a small spring.
Big, bold, uppercase words with a thick outline are the usual style for vertical video:

**Demo: Vertical word-by-word captions from inline items with explicit word timings** (rendered video: https://vidmake.app/media/captions-word.mp4)

```json
{
  "fonts": [
    { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" },
    { "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }
  ],
  "compositions": [{
    "id": "word", "description": "Vertical word-by-word captions from inline items with explicit word timings",
    "width": 720, "height": 1280, "fps": 30, "duration": "4s",
    "background": "#131210",
    "layers": [
      { "id": "bg", "type": "video", "src": "assets/clip.mp4", "width": "100%", "height": "100%", "muted": true,
        "brightness": 0.5, "saturation": 0.5, "blur": 4 },
      { "id": "subs", "type": "captions", "mode": "word", "y": "50%", "font": "Schibsted Grotesk", "fontSize": 104, "fontWeight": 900,
        "letterSpacing": -4, "uppercase": true, "fill": "#efebe2", "stroke": "#131210", "strokeWidth": 14,
        "items": [
          { "text": "Stop scrolling", "start": 6, "end": 45,
            "words": [{ "text": "Stop", "start": 6, "end": 24 }, { "text": "scrolling", "start": 24, "end": 45 }] },
          { "text": "and watch this", "start": "1.6s", "end": "3.8s" }
        ] },
      { "id": "hint", "type": "text", "text": "mode: \"word\"", "y": "88%", "font": "JetBrains Mono", "fontSize": 24, "letterSpacing": 1.5, "fill": "#161412", "background": "#f4f1ea", "padding": 12 }
    ]
  }]
}
```

`highlight` has no effect in word mode (there is only one word on screen). Fill, stroke and every other
style apply to the current word.

## Timing and placement

- Caption times are **relative to the layer's start**. A captions layer with `"start": "2s"` shows a cue
  written as `00:00:01,000` at 3 s. Keep caption layers at `start: 0` unless you mean to shift them.
- There is no `trimStart` for captions; to drop the beginning of a file, edit the file or give the layer a
  negative `start`.
- The default `y` of 80% suits landscape video; for vertical video with UI at the bottom, try `"y":
  "50%"`–`"70%"`.
- Put the captions layer last (on top) so nothing covers it.

> [!TIP]
> Captions over video need contrast: a semi-transparent `background` plate, a `stroke` outline
> (drawn behind the letters, so it never eats into them), or a `shadow`. The examples on this page use
> a plate (line mode) and an outline (word mode).

> [!AGENT]
> To check what reads on screen at a moment, run `vidmake inspect project.json -t <time> -l subs`: the
> NOTES column shows the caption text (in word mode, the current word). Between cues the layer is still
> listed, with no text and a placeholder 100×100 box; nothing is drawn.
