# Rendering

> Turn a project into MP4, WebM, MOV, GIF, a PNG sequence or an audio file with `vidmake render`, including every flag, the codecs and their alpha support, and the JSON progress events.

`vidmake render` compiles one composition, draws every frame in parallel and pipes the frames to
`ffmpeg`. The output format follows the file extension; flags change the range, resolution, quality and audio.

```bash
vidmake render project.json -o out/video.mp4
```

```output
rendering 120/120 frames (76.3 fps, 0s left)
{"event":"done","output":"out/video.mp4","codec":"h264","frames":120,"width":1280,"height":720,"fps":30.0,"duration":4.0,"elapsed":1.687,"renderFps":71.1,"draft":false}
```

The progress line goes to stderr and the final `done` line, a JSON object, always goes to stdout, so a script
can read the result without `--json`. The output folder is created when it doesn't exist. Before a long
render, look at the project first with a [storyboard](https://vidmake.app/docs/inspecting.md#storyboard) or a [`--draft`](https://vidmake.app/docs/rendering.md#draft-previews) render.

> [!AGENT]
> Render with `--json` and read the last line: the `done` event tells you the file, codec, size, frame count and
> duration that were actually written. Report those values rather than the ones you asked for.

## Output formats

The extension of `-o` picks the codec. `--codec` overrides it.

| `-o` | codec | encoder and defaults | audio | alpha |
|---|---|---|---|---|
| `.mp4` (and any other extension) | `h264` | libx264, `yuv420p`, preset `medium`, CRF 18, `+faststart` | AAC 192k | no |
| `.mp4` with `--codec h265` | `h265` | libx265, `yuv420p`, preset `medium`, CRF 22, tagged `hvc1` for Apple players | AAC 192k | no |
| `.webm` | `vp9` | libvpx-vp9, constant quality CRF 30 (`-b:v 0`), `-row-mt 1`, deadline `good` | Opus 160k | yes, `yuva420p` |
| `.mov` | `prores` | prores_ks, profile 3 (HQ) `yuv422p10le`; 4444 `yuva444p10le` with alpha | PCM 16-bit | yes, ProRes 4444 |
| `.gif` | `gif` | two-pass palette (`palettegen` + `paletteuse`, sierra2_4a dither), loops forever | none | 1-bit |
| no extension, e.g. `out/frames` | `png` | a folder of `frame_00000.png`, `frame_00001.png`, ... (straight RGBA) | none | yes |
| `.mp3` | `mp3` | libmp3lame 192k, audio only | yes | n/a |
| `.wav` | `wav` | PCM 16-bit, audio only | yes | n/a |
| `.m4a`, `.aac` | `aac` | AAC 192k, audio only | yes | n/a |

`--codec` accepts `h264` (also `mp4`, `avc`), `h265` (`hevc`), `vp9` (`webm`), `prores` (`mov`), `gif`,
`png` (`png-sequence`, `frames`), `mp3`, `wav` and `aac` (`m4a`). Any other value fails:

```output
error: unknown codec `mkv` (h264, h265, vp9, prores, gif, png, mp3, wav, aac)
```

The codec decides the encoder, not the container: `-o clip.mkv` is H.264 in a Matroska file, and
`-o x.webm --codec h264` fails because ffmpeg's WebM muxer only takes VP8/VP9/AV1. Keep the extension and codec matched.

```bash
vidmake render project.json -o out/video.mp4                   # H.264 + AAC
vidmake render project.json -o out/video.mp4 --codec h265      # H.265 + AAC
vidmake render project.json -o out/video.webm                  # VP9 + Opus (alpha if no background)
vidmake render project.json -o out/video.mov                   # ProRes (4444 with alpha if no background)
vidmake render project.json -o out/anim.gif --scale 0.5        # GIF
vidmake render project.json -o out/frames                      # PNG sequence (a directory)
vidmake render project.json -o out/audio.mp3                   # audio only (.mp3 .wav .m4a)
```

### Transparency

A render keeps alpha when **both** are true:

1. the composition has no `background` (see [compositions](https://vidmake.app/docs/compositions.md)), and
2. the codec supports alpha: `vp9` (`.webm`), `prores` (`.mov`), `png` (sequence) or `gif`.

Nothing else is needed. A full-size `rect` at the bottom of the layer list is still an opaque background, so
leave it out for overlays. H.264 and H.265 have no alpha channel: transparent areas come out black. GIF
transparency is one bit per pixel (each pixel is either fully transparent or opaque), so soft edges and shadows get a hard fringe;
use WebM or ProRes 4444 for overlays that will be composited in an editor.

```json title="overlay.json"
{ "id": "overlay", "width": 1920, "height": 1080, "duration": "5s",
  "layers": [ { "id": "tag", "type": "text", "text": "LIVE", "fontSize": 80, "fill": "#c92a26", "x": 160, "y": 100 } ] }
```

```bash
vidmake render overlay.json -o out/overlay.webm     # VP9 with an alpha channel
vidmake render overlay.json -o out/overlay.mov      # ProRes 4444 with alpha
```

> [!NOTE]
> VP9 alpha is stored as a side channel (`alpha_mode=1`). Chrome, Firefox and most editors read it; some players
> show the WebM on black. `ffprobe` reports the stream as `yuv420p` even when alpha is present.

### Audio

Every [audio](https://vidmake.app/docs/audio.md) layer and the sound of every [video](https://vidmake.app/docs/video.md) layer that isn't `muted` is mixed
into the output at 48 kHz stereo, after its `volume`, `fadeIn`/`fadeOut`, `trimStart`, `playbackRate` and `loop`.
The audio track is exactly as long as the rendered range. A project without any sound produces a video file
with no audio stream at all.

- `--muted` drops all audio from a video output.
- GIF and PNG sequences never carry audio.
- `.mp3`, `.wav` and `.m4a` render only the audio mix (no frames are drawn, so it's fast). With no sound in the
  project, or with `--muted`, they contain silence of the composition's length.

`vidmake timeline` lists the audio clips that will be mixed, with their start, end, trim and rate (see
[inspecting](https://vidmake.app/docs/inspecting.md#timeline)).

## Flags

```console
$ vidmake render --help
Render the composition to a video, GIF, audio file or PNG sequence

Usage: vidmake render [OPTIONS] <PROJECT>

Arguments:
  <PROJECT>  Project file (JSON)

Options:
  -c, --comp <COMP>                Composition id (default: first)
  -p, --props <PROPS>              Input props: JSON object or key=value (repeatable)
      --props-file <PROPS_FILE>    Input props from a JSON file
      --theme <THEME>              Theme mode to apply (one of the theme's `modes`, e.g. dark)
      --theme-file <THEME_FILE>    Extra theme file laid over the project's theme (a brand, a client)
  -o, --out <OUT>                  Output file (.mp4 .webm .mov .gif .mp3 .wav .m4a) or a directory for PNG frames [default: out/video.mp4]
      --codec <CODEC>              h264 | h265 | vp9 | prores | gif | png | mp3 | wav | aac (default: from extension)
      --crf <CRF>                  Quality (codec CRF; lower = better and bigger). Default: h264 23, h265 26, vp9 30
      --frames <FRAMES>            Frame range "start-end" (end exclusive), frames, times or markers: "0-90", "1s-3s", "@intro..@outro"
      --encoder <ENCODER>          auto | hardware | software. auto uses the GPU/media engine for h264, h265 and prores when `vidmake hardware` finds one [default: auto]
      --scale <SCALE>              Resolution scale (default 1, or 0.5 with --draft)
      --concurrency <CONCURRENCY>  Worker threads (default: all cores)
      --muted                      Drop audio
      --json                       Emit progress as JSON lines on stdout
      --ffmpeg-arg <FFMPEG_ARGS>   Extra ffmpeg output args (e.g. --ffmpeg-arg=-b:v --ffmpeg-arg=4M)
      --draft                      Quick preview: no motion blur, half scale (unless --scale is given), fastest encoder preset
  -h, --help                       Print help
```

| flag | default | what it does |
|---|---|---|
| `-o, --out <path>` | `out/video.mp4` | output file, or a directory for PNG frames |
| `--codec <name>` | from the extension | see [output formats](https://vidmake.app/docs/rendering.md#output-formats) |
| `--crf <n>` | 18 (h264), 22 (h265), 30 (vp9) | constant-quality factor, lower = better and bigger. Ignored by ProRes, GIF, PNG and audio |
| `--frames <a-b>` | whole composition | render a range, end exclusive |
| `--scale <x>` | 1 (0.5 with `--draft`) | render at a fraction or multiple of the composition size |
| `--concurrency <n>` | all cores | worker threads for drawing frames |
| `--muted` | off | drop audio |
| `--json` | off | progress as JSON lines on stdout |
| `--ffmpeg-arg=<arg>` | none | append one argument to the ffmpeg command (repeatable) |
| `--draft` | off | quick preview: no motion blur, half size, fastest encoder preset |
| `-c, --comp <id>` | first composition | which composition to render |
| `-p, --props <json or k=v>` | | input props (repeatable) |
| `--props-file <file>` | | input props from a JSON file |

### Frame ranges

`--frames start-end` renders part of the composition. Both ends take any [time value](https://vidmake.app/docs/time.md): frames
(`0-90`), seconds (`1s-3s`), milliseconds, `45f` or `m:ss` (`0:01-0:02.5`). The end is **exclusive**, so
`--frames 0-90` renders frames 0 to 89 and `--frames 1s-3s` renders 60 frames at 30 fps.

```bash
vidmake render project.json -o out/intro.mp4 --frames 0-3s
vidmake render project.json -o out/section.mp4 --frames 1:30-1:45
```

- The start is clamped to 0 and the end to the composition length.
- An empty or reversed range fails with `error: empty frame range`; a value without a `-` fails with
  `error: --frames must look like 0-90 or 1s-3s`. Negative times are not supported.
- The audio is cut to the same range, so the clip stays in sync.
- PNG sequences keep the absolute frame number in the file name: `--frames 30-32 -o out/f` writes
  `frame_00030.png` and `frame_00031.png`.

### Scale

`--scale 0.5` renders a 1920×1080 composition at 960×540. Layers are drawn at the target resolution (text, shapes
and SVGs stay sharp; they are not upscaled from a smaller render), and coordinates in your JSON stay in composition
pixels. When the scale isn't 1, each output dimension is rounded and bumped up to the next even number so H.264
accepts it. `--scale 2` renders at double size.

### Quality

`--crf` sets the constant-quality factor of the H.264, H.265 and VP9 encoders. Sensible ranges: 16-23 for H.264,
20-28 for H.265, 24-36 for VP9. For a size target or other encoder settings, pass them through
[`--ffmpeg-arg`](https://vidmake.app/docs/rendering.md#extra-ffmpeg-arguments).

### Draft previews

`--draft` is a quick full-length preview: no [motion blur](https://vidmake.app/docs/effects.md), half scale unless you also pass
`--scale`, and the fastest encoder preset (`ultrafast` for H.264/H.265, `realtime` for VP9). The `done` event
reports `"draft": true`.

```bash
vidmake render project.json -o out/preview.mp4 --draft --json
```

```output
{"event":"progress","rendered":16,"total":30,"percent":53.3,"elapsed":0.129,"fps":124.1,"eta":0.1}
{"event":"progress","rendered":30,"total":30,"percent":100.0,"elapsed":0.155,"fps":193.3,"eta":0.0}
{"event":"done","output":"out/preview.mp4","codec":"h264","frames":30,"width":640,"height":360,"fps":30.0,"duration":1.0,"elapsed":0.166,"renderFps":180.7,"draft":true}
```

(Output above from `--draft --frames 1s-2s` on a 1280×720 project; long float values shortened.)

### Concurrency

Frames are drawn in parallel, in batches of four frames per thread, then written to ffmpeg in order.
`--concurrency 2` limits the worker threads, which also limits memory: each batch holds full-resolution frames.
Use it on small machines, in CI, or when other work shares the CPU.

### Extra ffmpeg arguments

Each `--ffmpeg-arg` appends one argument to the encoder command, after vidmake's own output options and right
before the output path. Use the `=` form because the values start with `-`:

```bash
vidmake render project.json -o out/web.mp4 --ffmpeg-arg=-b:v --ffmpeg-arg=4M --ffmpeg-arg=-maxrate --ffmpeg-arg=6M
vidmake render project.json -o out/anim.mp4 --ffmpeg-arg=-tune --ffmpeg-arg=animation
vidmake render project.json -o out/tagged.mp4 --ffmpeg-arg=-metadata --ffmpeg-arg=title=Launch
```

Because they come last, they can also override an earlier option (ffmpeg uses the last value it sees for a
stream option). Set `VIDMAKE_DEBUG=1` to see the exact command:

```bash
VIDMAKE_DEBUG=1 vidmake render project.json -o out/video.mp4 --crf 23 --ffmpeg-arg=-tune --ffmpeg-arg=animation
```

```output
"ffmpeg" "-y" "-v" "error" "-nostdin" "-f" "rawvideo" "-pix_fmt" "rgba" "-s" "640x360" "-r" "30" "-i" "pipe:0" "-i" "./assets/music.mp3" "-filter_complex" "[1:a]atrim=0:1.0000,asetpts=PTS-STARTPTS,aformat=sample_rates=48000:channel_layouts=stereo,volume='1.0000':eval=frame[a0];anullsrc=r=48000:cl=stereo:d=1.0000[bed];[bed][a0]amix=inputs=2:duration=first:normalize=0:dropout_transition=0[aout]" "-map" "0:v" "-map" "[aout]" "-c:v" "libx264" "-pix_fmt" "yuv420p" "-preset" "medium" "-crf" "23" "-movflags" "+faststart" "-c:a" "aac" "-b:a" "192k" "-t" "1.0000" "-tune" "animation" "out/video.mp4"
```

### Compositions and props

`--comp <id>` renders a composition other than the first. Props override the composition's `props` defaults
(see [props](https://vidmake.app/docs/props.md)): `-p key=value` (repeatable; the value is parsed as JSON when it can be, so `-p count=3`
is a number), `--props '{"title":"Hi"}'`, or `--props-file props.json`. The file is applied first, then each `-p`/`--props` in order.

```bash
vidmake render project.json --comp lowerThird -p name="Ada Lovelace" -p role=Engineer -o out/ada.mov
```

## JSON progress

With `--json`, progress goes to stdout as one JSON object per line, emitted after each batch of frames, and the
human-readable progress line on stderr is suppressed:

```json
{"event":"progress","rendered":112,"total":120,"percent":93.3,"elapsed":1.508,"fps":74.26,"eta":0.1}
```

| field | meaning |
|---|---|
| `rendered` | frames drawn and sent to the encoder so far |
| `total` | frames in the range |
| `percent` | `rendered / total × 100`, one decimal |
| `elapsed` | seconds since the render started |
| `fps` | average frames per second so far |
| `eta` | estimated seconds left, one decimal |

The last line is always the `done` event, with or without `--json`:

| field | meaning |
|---|---|
| `output` | the path written |
| `codec` | `h264`, `h265`, `vp9`, `prores`, `gif`, `png`, `mp3`, `wav` or `aac` |
| `frames` | frames in the rendered range |
| `width`, `height` | output size in pixels, after `--scale` |
| `fps` | composition frame rate |
| `duration` | seconds of output (`frames / fps`) |
| `elapsed` | wall-clock seconds for the whole render |
| `renderFps` | `frames / elapsed` |
| `draft` | whether `--draft` was set |

Audio-only outputs report the same fields; `width` and `height` are the composition size even though no frames are drawn.

On failure there is no `done` event: vidmake prints `error: ...` to stderr and exits with status 1. When ffmpeg
itself fails, the message ends with the tail of ffmpeg's log, for example for an odd width:

```output
error: ffmpeg stopped accepting frames (Broken pipe (os error 32)): [libx264 @ 0x555e2a733a40] width not divisible by 2 (641x360)
[vost#0:0/libx264 @ 0x555e2a733680] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
```

A small reader for agents and scripts:

```bash
vidmake render project.json -o out/video.mp4 --json | while read -r line; do
  case "$line" in *'"event":"done"'*) echo "$line" > out/render.json ;; esac
done
```

## ffmpeg and environment variables

vidmake runs `ffmpeg` to encode and to decode video and audio sources, and `ffprobe` to read media metadata
(`validate` and the preview commands use them too when a project contains video, audio or waveforms).
Rendering a PNG sequence of a project without media needs neither.

| variable | effect |
|---|---|
| `VIDMAKE_FFMPEG` | path of the ffmpeg binary (default `ffmpeg` on `PATH`) |
| `VIDMAKE_FFPROBE` | path of the ffprobe binary (default `ffprobe` on `PATH`) |
| `VIDMAKE_DEBUG` | when set (any value), print the encoder's ffmpeg command line to stderr |

The encoders used are `libx264`, `libx265`, `libvpx-vp9`, `prores_ks`, `libmp3lame`, `aac` and `libopus`. Most
ffmpeg builds include them; a minimal build may not, and ffmpeg then fails with `Unknown encoder`. See
[troubleshooting](https://vidmake.app/docs/troubleshooting.md#ffmpeg-not-found) and the [CLI page](https://vidmake.app/docs/cli.md#environment-variables)
for the other variables.

## Performance

- **Look before you render.** A [storyboard](https://vidmake.app/docs/inspecting.md#storyboard) or [still](https://vidmake.app/docs/inspecting.md#still)
  costs a few frames; most mistakes show up there.
- **Preview with `--draft`**, and narrow the work with `--frames` while you fix one section.
- **Motion blur multiplies the work.** A composition `motionBlur` with `samples: 8` draws every frame 8 times.
  `--draft` turns it off; layers with `"motionBlur": false` render once.
- **Large blurs and glows are the most expensive effects** (they scale with radius and the layer's area), as are
  `blur`, `shadow` and masks on full-screen groups. Animate them on the smallest layer that does the job.
- **Video sources are decoded by ffmpeg** while rendering. Trimmed, scaled or looping videos restart the decoder
  when you seek with `--frames`; full renders read each source sequentially.
- **GIFs get big fast.** Render them at `--scale 0.5` or lower, keep them short, and prefer flat colors.
- **Reduce `--concurrency`** if the machine runs out of memory on 4K renders.

For reference, the 1280×720 demos on this site render at 50-200 frames per second on a 4-core machine.
