# Series and transitions

> Play scenes back to back with a `series` group, and overlap them with `fade`, `slide`, `wipe`, `zoom` and `blur` transitions. vidmake computes every start time and the total length.

A group with `"series": true` plays its children one after another, like Remotion's `<Series>` and
`<TransitionSeries>`. You give each scene a duration; vidmake works out when each one starts, overlaps
neighbors that have a transition, and sums up the total. Reorder, lengthen or remove a scene and
everything after it moves.

**Demo: A series of five scenes: each scene's transition plays as it hands over to the next** (rendered video: https://vidmake.app/media/series-transitions.mp4)

```json
{
  "fonts": [
    { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" },
    { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk-Italic.ttf" },
    { "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }
  ],
  "compositions": [{
    "id": "transitions", "description": "A series of five scenes: each scene's transition plays as it hands over to the next",
    "width": 1280, "height": 720, "fps": 30, "background": "#f4f1ea",
    "layers": [
      { "id": "show", "type": "group", "series": true, "children": [
        { "id": "s1", "type": "group", "duration": "1.4s", "transition": "fade", "children": [
          { "id": "bg1", "type": "rect", "fill": "#f4f1ea" },
          { "id": "t1", "type": "text", "text": "fade", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 140, "letterSpacing": -6, "fill": "#161412" },
          { "id": "c1", "type": "text", "text": "\"transition\": \"fade\"", "font": "JetBrains Mono", "fontSize": 22, "fill": "#8a857a", "y": "68%" } ] },
        { "id": "s2", "type": "group", "duration": "1.4s", "transition": "slideLeft", "children": [
          { "id": "bg2", "type": "rect", "fill": "#161412" },
          { "id": "t2", "type": "text", "text": "slideLeft", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 140, "letterSpacing": -6, "fill": "#f4f1ea" },
          { "id": "c2", "type": "text", "text": "\"transition\": \"slideLeft\"", "font": "JetBrains Mono", "fontSize": 22, "fill": "#8f8a7f", "y": "68%" } ] },
        { "id": "s3", "type": "group", "duration": "1.4s", "transition": { "type": "wipeRight", "duration": "0.6s" }, "children": [
          { "id": "bg3", "type": "rect", "fill": "#e9e4d8" },
          { "id": "t3", "type": "text", "text": "wipeRight", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 140, "letterSpacing": -6, "fill": "#161412" },
          { "id": "c3", "type": "text", "text": "\"transition\": \"wipeRight\"", "font": "JetBrains Mono", "fontSize": 22, "fill": "#4a4640", "y": "68%" } ] },
        { "id": "s4", "type": "group", "duration": "1.4s", "transition": "zoom", "children": [
          { "id": "bg4", "type": "rect", "fill": "#161412" },
          { "id": "t4", "type": "text", "text": "zoom", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 140, "letterSpacing": -6, "fill": "#f4f1ea" },
          { "id": "c4", "type": "text", "text": "\"transition\": \"zoom\"", "font": "JetBrains Mono", "fontSize": 22, "fill": "#8f8a7f", "y": "68%" } ] },
        { "id": "s5", "type": "group", "duration": "1.4s", "children": [
          { "id": "bg5", "type": "rect", "fill": "#f4f1ea" },
          { "id": "t5", "type": "text", "text": "the end", "font": "Schibsted Grotesk", "italic": true, "fontSize": 140, "letterSpacing": -5, "fill": "#c92a26" } ] }
      ] }
    ]
  }]
}
```

## A basic series

```json
{ "id": "show", "type": "group", "series": true, "children": [
  { "id": "intro", "type": "group", "duration": "3s", "children": [] },
  { "id": "demo", "type": "video", "src": "assets/clip.mp4", "muted": true },
  { "id": "outro", "type": "group", "duration": "2s", "children": [] }
] }
```

`intro` plays from 0 to 3 s, the 6-second `demo` clip from 3 to 9 s, and `outro` from 9 to 11 s. The
series group lasts 11 seconds, and with the default `"duration": "auto"` so does the composition.

Each child is usually a **group** holding one scene's layers. Inside it, everything is timed relative to
the scene's start ([local time](https://vidmake.app/docs/time.md#local-time)), so a scene can be written, checked and moved
on its own.

### Every child needs a fixed length

A series can't place a child without knowing how long it is. Each child needs one of:

- an explicit `duration` (or `end`),
- media: a `video` or `audio` layer's own length, unless it loops,
- a `use` layer: the referenced composition's length,
- a nested series group: its own total,
- a `captions` layer: the end of its last caption.

A child without one is an error that names it:

```output
✗ main: layer `show` (main > layers[0]): layer `b` is inside a series group and needs a `duration`
```

## Transitions

Add `transition` to a child to overlap it with the **next** child. The transition plays during the
overlap: the outgoing scene animates out while the incoming one animates in.

```json
{ "id": "a", "type": "group", "duration": "3s", "transition": "fade", "children": [] }
{ "id": "a", "type": "group", "duration": "3s", "transition": { "type": "slideLeft", "duration": "0.8s" }, "children": [] }
```

A transition is a name, or an object with `type`, `duration` (default `0.5s`) and `ease` (default
`easeInOutCubic`, any [easing](https://vidmake.app/docs/easing.md)). `motion` sets both at once from a [motion](https://vidmake.app/docs/easing.md#motion),
built in or from your [theme](https://vidmake.app/docs/theme.md): `{ "type": "slideLeft", "motion": "gentle" }` is a 1.2 s spring with
no bounce. `duration` and `ease` override the motion's. Wipes also take `feather` and `edge`, below.

| transition | outgoing scene | incoming scene |
|---|---|---|
| `fade` (alias `crossfade`) | fades out | fades in |
| `slideLeft`, `slideRight`, `slideUp`, `slideDown` | pushed out in that direction by the full width or height | pushed in from the opposite side |
| `wipeLeft`, `wipeRight`, `wipeUp`, `wipeDown` | stays in place underneath | revealed by an edge moving in that direction |
| `zoom` | fades out | scales down from 1.2× to 1× while fading in |
| `blur` | blurs and fades out | un-blurs and fades in |
| `none` (alias `cut`) | | no overlap: a hard cut, the same as no transition |

Later children are drawn above earlier ones, so the incoming scene is on top during the overlap.

### Wipe edges and feathering

A plain wipe is a hard, moving line. Two options dress it up:

- `edge` draws a band of color riding the edge of the incoming scene: `"edge": "#c92a26"` or
  `{ "color": "#c92a26", "width": 16 }` (px, default 12). A brand color here makes a scene change feel designed.
- `feather` softens the edge into a ramp that many px wide, so the incoming scene fades in along the line.

**Demo: Wipe transitions: an edge band of color, then a feathered edge** (rendered video: https://vidmake.app/media/series-wipe-edge.mp4)

```json
{
  "fonts": [{ "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" }],
  "compositions": [{
    "id": "edges", "description": "Wipe transitions: an edge band of color, then a feathered edge",
    "width": 1280, "height": 720, "fps": 30, "duration": "auto",
    "layers": [
      { "id": "show", "type": "group", "series": true, "children": [
        { "id": "one", "type": "group", "duration": "1.4s",
          "transition": { "type": "wipeUp", "duration": "0.6s", "edge": { "color": "#c92a26", "width": 16 } },
          "children": [
            { "id": "one-bg", "type": "rect", "fill": "#f4f1ea" },
            { "id": "one-t", "type": "text", "text": "wipe transitions", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 80, "letterSpacing": -3.5, "fill": "#161412" } ] },
        { "id": "two", "type": "group", "duration": "1.6s",
          "transition": { "type": "wipeLeft", "duration": "0.8s", "feather": 260, "ease": "easeInOutQuart", "edge": { "color": "#c92a26", "width": 6 } },
          "children": [
            { "id": "two-bg", "type": "rect", "fill": "#161412" },
            { "id": "two-t", "type": "text", "text": "edge: a band of color", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 80, "letterSpacing": -3.5, "fill": "#f4f1ea" } ] },
        { "id": "three", "type": "group", "duration": "1.4s", "children": [
          { "id": "three-bg", "type": "rect", "fill": "#e9e4d8" },
          { "id": "three-t", "type": "text", "text": "feather: a soft edge", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 80, "letterSpacing": -3.5, "fill": "#161412" } ] }
      ] }
    ]
  }]
}
```

```json
"transition": { "type": "wipeUp", "duration": "0.6s", "edge": { "color": "#c92a26", "width": 16 } }
"transition": { "type": "wipeLeft", "duration": "0.8s", "ease": "easeInOutQuart", "feather": 260, "edge": { "color": "#c92a26", "width": 6 } }
```

Both also work on a `wipe*` [preset](https://vidmake.app/docs/presets.md#options) of any layer.

> [!NOTE]
> With `fade`, both scenes are partly transparent at the midpoint, so whatever is behind the series (the
> composition background) shows through briefly. Give the composition a background close to your scenes'
> colors, or use `wipe` or `slide` for a transition with no dip.

### Transitions and presets

A transition works by giving the outgoing child an `exit` and the incoming child an `enter` for the
length of the overlap. It only does so when the child doesn't already have its own: an explicit `exit` on
the outgoing child or `enter` on the incoming one wins. `timeline` and `inspect` show the generated
presets as `exit:transition` and `enter:transition`.

A `transition` on the **last** child has nothing to hand over to and is ignored.

## How start times are computed

vidmake walks the children in order with a cursor that starts at 0:

1. A child starts at `cursor + start` (its own `start`, default 0, is an offset).
2. The cursor moves to that child's end.
3. If the child has a transition, the cursor steps back by the overlap, which is the transition's
   duration, capped at the child's own duration.

So the series length is **the sum of the durations, plus any gaps, minus the overlaps**. For the demo
at the top of the page, five 1.4-second scenes with transitions of 0.5, 0.5, 0.6 and 0.5 seconds:

```output
5 × 1.4s − (0.5s + 0.5s + 0.6s + 0.5s) = 7.0s − 2.1s = 4.9s
```

```console
$ vidmake timeline series-transitions.json
Composition `transitions` — 1280x720 @ 30fps, 147 frames (4.90s)

ID       TYPE         START      END      DUR  DETAILS
show     group        0.00s    4.90s    4.90s  "5 children"
  s1     group        0.00s    1.40s    1.40s  exit:transition "3 children"
    bg1  rect         0.00s    1.40s    1.40s  
    t1   text         0.00s    1.40s    1.40s  "fade"
    c1   text         0.00s    1.40s    1.40s  ""transition": "fade""
  s2     group        0.90s    2.30s    1.40s  enter:transition exit:transition "3 children"
    bg2  rect         0.90s    2.30s    1.40s  
    t2   text         0.90s    2.30s    1.40s  "slideLeft"
    c2   text         0.90s    2.30s    1.40s  ""transition": "slideLeft""
  s3     group        1.80s    3.20s    1.40s  enter:transition "3 children"
    bg3  rect         1.80s    3.20s    1.40s  
    t3   text         1.80s    3.20s    1.40s  "wipeRight"
    c3   text         1.80s    3.20s    1.40s  ""transition": "wipeRight""
  s4     group        2.60s    4.00s    1.40s  enter:transition exit:transition "3 children"
    bg4  rect         2.60s    4.00s    1.40s  
    t4   text         2.60s    4.00s    1.40s  "zoom"
    c4   text         2.60s    4.00s    1.40s  ""transition": "zoom""
  s5     group        3.50s    4.90s    1.40s  enter:transition "2 children"
    bg5  rect         3.50s    4.90s    1.40s  
    t5   text         3.50s    4.90s    1.40s  "the end"

         |0s          1s          2s          3s          4s          |
show     |████████████████████████████████████████████████████████████|
  s1     |██████████████████··········································|
    bg1  |██████████████████··········································|
    t1   |██████████████████··········································|
    c1   |██████████████████··········································|
  s2     |···········██████████████████·······························|
    bg2  |···········██████████████████·······························|
    t2   |···········██████████████████·······························|
    c2   |···········██████████████████·······························|
  s3     |······················██████████████████····················|
    bg3  |······················██████████████████····················|
    t3   |······················██████████████████····················|
    c3   |······················██████████████████····················|
  s4     |·······························██████████████████···········|
    bg4  |·······························██████████████████···········|
    t4   |·······························██████████████████···········|
    c4   |·······························██████████████████···········|
  s5     |··········································██████████████████|
    bg5  |··········································██████████████████|
    t5   |··········································██████████████████|
```

The bars show each scene starting before the previous one ends. Scrub through the overlaps here:

*(An interactive timeline widget is shown here on the HTML page.)*

> [!TIP]
> Use `vidmake storyboard project.json --at` with times inside each overlap (for example the midpoint of
> each transition) to see the transitions themselves; evenly spaced frames tend to land between them.

## Gaps

A child's `start` adds a gap before it. The composition background, or whatever is behind the series,
shows during the gap. Here each chapter title fades out, and the next one comes in after half a second
of empty paper:

**Demo: A child's start in a series is a gap after the previous child: a beat of empty paper between chapters** (rendered video: https://vidmake.app/media/series-gap.mp4)

```json
{
  "fonts": [{ "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" }],
  "compositions": [{
    "id": "chapters", "description": "A child's start in a series is a gap after the previous child: a beat of empty paper between chapters",
    "width": 1280, "height": 720, "fps": 30, "background": "#f4f1ea",
    "layers": [
      { "id": "chapters", "type": "group", "series": true, "children": [
        { "id": "one", "type": "text", "text": "Chapter one", "duration": "1.5s", "font": "Schibsted Grotesk", "fontWeight": 860,
          "fontSize": 110, "letterSpacing": -5, "fill": "#161412", "enter": "fadeUp", "exit": "fade" },
        { "id": "two", "type": "text", "text": "Chapter two", "start": "0.5s", "duration": "1.5s", "font": "Schibsted Grotesk",
          "fontWeight": 860, "fontSize": 110, "letterSpacing": -5, "fill": "#161412", "enter": "fadeUp", "exit": "fade" },
        { "id": "three", "type": "text", "text": "Chapter three", "start": "0.5s", "duration": "1.5s", "font": "Schibsted Grotesk",
          "fontWeight": 860, "fontSize": 110, "letterSpacing": -5, "fill": "#161412", "enter": "fadeUp", "exit": "fade" }
      ] },
      { "id": "progress", "type": "rect", "anchor": "left", "x": 0, "y": 716, "height": 8, "fill": "#c92a26",
        "width": "=pw * p" }
    ]
  }]
}
```

```json
{ "id": "two", "type": "text", "text": "Chapter two", "start": "0.5s", "duration": "1.5s", "enter": "fadeUp", "exit": "fade" }
```

```console
$ vidmake timeline series-gap.json
Composition `chapters` — 1280x720 @ 30fps, 165 frames (5.50s)

ID        TYPE         START      END      DUR  DETAILS
chapters  group        0.00s    5.50s    5.50s  "3 children"
  one     text         0.00s    1.50s    1.50s  enter:fadeUp exit:fade "Chapter one"
  two     text         2.00s    3.50s    1.50s  enter:fadeUp exit:fade "Chapter two"
  three   text         4.00s    5.50s    1.50s  enter:fadeUp exit:fade "Chapter three"
progress  rect         0.00s    5.50s    5.50s  

          |0s        1s         2s         3s         4s         5s    |
chapters  |████████████████████████████████████████████████████████████|
  one     |█████████████████···········································|
  two     |·····················██████████████████·····················|
  three   |···········································█████████████████|
progress  |████████████████████████████████████████████████████████████|
```

Three 1.5-second chapters and two 0.5-second gaps make 5.5 seconds.

> [!WARNING]
> A gap after a transition cancels the overlap. If scene A has `"transition": "fade"` and scene B has
> `"start": "1s"`, B starts 0.5 s *after* A ends: A fades out, the screen is empty, then B fades in. Use
> either a transition or a gap between two scenes, not both.

A negative `start` overlaps a child with the previous one without any transition: `"start": "-0.5s"`
makes it begin half a second before the previous child ends, drawn on top.

## The series group itself

A series group is an ordinary [group](https://vidmake.app/docs/groups.md) in every other way:

- `start` on the series group offsets the whole sequence; a series can begin at 2 s, after an intro.
- Its `duration` defaults to the computed total. Setting a shorter `duration` cuts the end off.
- `x`, `y`, `width`, `height`, `scale`, `opacity`, effects, `enter` and `exit` apply to the whole sequence.
  A series inside a 960×540 group plays as a picture-in-picture.
- Only its direct children are sequenced. A child can itself be a series group, which counts as one scene.

Layers *next to* the series group in the composition (a logo, music, a progress bar) run on the
composition's clock as usual, so they stay on screen across scene changes. The progress bar in the gap
demo above is such a layer.

## A complete example

```json title="scenes.json"
{
  "id": "main", "width": 1280, "height": 720, "background": "#f4f1ea",
  "layers": [
    { "id": "scenes", "type": "group", "series": true, "children": [
      { "id": "title", "type": "group", "duration": "2.5s", "transition": { "type": "wipeLeft", "duration": "0.6s" },
        "children": [
          { "id": "titleBg", "type": "rect", "fill": "#e9e4d8" },
          { "id": "titleText", "type": "text", "text": "Q3 in review", "fontSize": 96, "fill": "#161412", "enter": "fadeUp" }
        ] },
      { "id": "clip", "type": "video", "src": "assets/clip.mp4", "trimStart": "1s", "duration": "3s",
        "width": "100%", "height": "100%", "muted": true, "transition": "fade" },
      { "id": "end", "type": "group", "duration": "2s", "children": [
          { "id": "endBg", "type": "rect", "fill": "#e9e4d8" },
          { "id": "endText", "type": "text", "text": "Thanks", "fontSize": 96, "fill": "#c92a26" }
        ] }
    ] },
    { "id": "music", "type": "audio", "src": "assets/music.mp3", "fadeOut": "1s" }
  ]
}
```

The scenes last 2.5 + 3 + 2 − 0.6 − 0.5 = 6.4 seconds. The music is 12 seconds long and also has a fixed
length, so set `"duration": "6.4s"` on the composition (or `"duration"` on the audio layer) if the video
should end with the last scene.

## Next steps

- [Groups](https://vidmake.app/docs/groups.md) Clipping, layout and everything else groups can do.
- [Presets](https://vidmake.app/docs/presets.md) The `enter` and `exit` animations transitions are built from.
- [Components](https://vidmake.app/docs/components.md) Reuse a scene as its own composition with `use`.
- [Time](https://vidmake.app/docs/time.md) Time formats and local time.
