vidmake v0.2.1
Download

Docs/Getting startedPage 06 / 45

Core concepts

How a vidmake project is put together: compositions, the layer tree, coordinates and anchors, layer-local time, draw order, and why every frame is a pure function of time.

View .md Ask Claude Ask ChatGPT

A vidmake project is a description of a video, not a program that draws one. This page explains the handful of ideas everything else builds on. Each section links to the page with the full details.

#Projects, compositions and layers

output
project.json├── fonts                      font files used by text layers└── compositions[]    ├── main (1920×1080, 30 fps, 10s)    │   ├── background         a rect    │   ├── intro              a group    │   │   ├── title          a text    │   │   └── logo           an image    │   ├── music              an audio    │   └── lowerThird         a use layer → renders the "lowerThird" composition    └── lowerThird (1920×1080, 3s)        └── ...
  • A project is one JSON file. Besides compositions, it can list fonts to load. Asset paths (src, font path) are relative to the project file.
  • A composition is a canvas with a size, a frame rate, a duration and a list of layers. The first composition is rendered by default; --comp <id> picks another. Compositions can also be used as reusable components inside other compositions. See Compositions.
  • A layer is one visual or audio element: a shape, text, image, video, audio clip, group and so on. Each has a type, an id, a time window and properties that can be animated. See Layers.

The layer tree comes from three kinds of nesting:

nestinghowchildren are placed and timed relative to
group"type": "group" with childrenthe group's box and the group's start
seriesa group with "series": trueplayed back to back
component"type": "use" with "ref": "<compositionId>"the referenced composition, drawn as a group

Transforms, opacity, effects and presets on a group apply to everything inside it. Moving a group moves its children; fading a group fades them all.

00:00.0 · f 000
A group moves, tilts and scales; its children follow in the group's own coordinatesDownload
start-tree.jsonjson
{  "fonts": [    { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" },    { "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }  ],  "compositions": [{    "id": "tree", "description": "A group moves, tilts and scales; its children follow in the group's own coordinates",    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea",    "layers": [      { "id": "back", "type": "rect", "x": "50%", "y": "52%", "width": 460, "height": 280, "cornerRadius": 3,        "fill": "#e9e4d8", "stroke": "#d8d1c1", "strokeWidth": 2, "rotation": -6, "comment": "drawn first, so it sits at the bottom" },      { "id": "card", "type": "group", "x": "=pw/2 + 150 * sin(t * pi / 2)", "y": "52%", "width": 460, "height": 280,        "rotation": "=6 * sin(t * pi / 2)", "scale": { "from": 0.85, "to": 1, "duration": "1s", "ease": "easeOutBack" },        "children": [          { "id": "panel", "type": "rect", "cornerRadius": 3, "fill": "#fbf9f4", "stroke": "#161412", "strokeWidth": 2 },          { "id": "badge", "type": "ellipse", "x": "100%", "y": 0, "width": 64, "fill": "#c92a26" },          { "id": "name", "type": "text", "text": "card", "font": "Schibsted Grotesk", "fontWeight": 860, "fontSize": 84,            "letterSpacing": -3.5, "fill": "#161412", "y": "44%" },          { "id": "coords", "type": "text", "text": "badge: x \"100%\", y 0", "font": "JetBrains Mono", "fontSize": 20,            "fill": "#4a4640", "y": "72%" }        ] },      { "id": "caption", "type": "text", "text": "children are placed in the group's box, not the canvas", "font": "Schibsted Grotesk",        "fontSize": 22, "fill": "#8a857a", "y": "90%" }    ]  }]}

#Coordinates

The canvas origin is the top-left corner. x grows to the right and y grows down, in pixels. Rotation is in degrees, clockwise.

  • x and y place the layer's anchor point in its parent's coordinates. They default to "50%", so a layer without a position is centered in its parent.
  • The anchor is a point in the layer's own box, given as fractions [ax, ay] (default [0.5, 0.5], the center) or as a name: center, top-left, top, top-right, left, right, bottom-left, bottom, bottom-right. "anchor": "top-left" with "x": 0, "y": 0 puts the layer in the corner.
  • Rotation and scale happen around the anchor. A layer anchored at its top-left corner swings around that corner.
  • Inside a group, coordinates are the group's. (0, 0) is the top-left of the group's box, and the box defaults to the parent's size.
00:00.0 · f 000
Same x and y, three anchors: each square sits on and rotates around its own anchorDownload
start-anchors.jsonjson
{  "fonts": [    { "family": "Schibsted Grotesk", "path": "fonts/SchibstedGrotesk.ttf" },    { "family": "JetBrains Mono", "path": "fonts/JetBrainsMono.ttf" }  ],  "compositions": [{    "id": "anchors", "description": "Same x and y, three anchors: each square sits on and rotates around its own anchor",    "width": 1280, "height": 720, "fps": 30, "duration": "4s", "background": "#f4f1ea",    "layers": [      { "id": "topLeft", "type": "rect", "anchor": "top-left", "x": "25%", "y": "47%", "width": 190, "height": 110,        "cornerRadius": 3, "fill": "#161412", "rotation": "=90 * easeInOutCubic(pingpong(max(t - 0.5, 0) / 1.5, 1))" },      { "id": "center", "type": "rect", "anchor": "center", "x": "50%", "y": "47%", "width": 190, "height": 110,        "cornerRadius": 3, "fill": "#161412", "rotation": "=90 * easeInOutCubic(pingpong(max(t - 0.5, 0) / 1.5, 1))" },      { "id": "bottomRight", "type": "rect", "anchor": "bottom-right", "x": "75%", "y": "47%", "width": 190, "height": 110,        "cornerRadius": 3, "fill": "#161412", "rotation": "=90 * easeInOutCubic(pingpong(max(t - 0.5, 0) / 1.5, 1))" },      { "id": "dot", "type": "ellipse", "repeat": 3, "x": "=pw * (0.25 + 0.25 * i)", "y": "47%", "width": 20,        "fill": "#c92a26", "stroke": "#f4f1ea", "strokeWidth": 4 },      { "id": "label", "type": "text", "repeat": 3, "x": "=pw * (0.25 + 0.25 * i)", "y": "84%", "font": "JetBrains Mono",        "fontSize": 20, "fill": "#4a4640", "text": "\"anchor\": \"${pick(i, ['top-left', 'center', 'bottom-right'])}\"" },      { "id": "title", "type": "text", "text": "x and y place the anchor point", "font": "Schibsted Grotesk", "fontWeight": 860,        "fontSize": 52, "letterSpacing": -2.2, "fill": "#161412", "y": "13%" }    ]  }]}

Try the anchor and position combinations here:

#Percentages

Any numeric field accepts a percentage string, measured against the parent (the composition, or the enclosing group's box):

field"50%" means
x, widthhalf the parent's width
y, heighthalf the parent's height
fontSizehalf the parent's height
text maxWidthhalf the parent's width

In expressions, the same sizes are available as w/h (the composition) and pw/ph (the parent): "x": "=pw * 0.25".

#Layer sizes

When you don't set width and height, a layer takes its natural size:

layerdefault size
rectthe parent's full size, so { "type": "rect", "fill": "#111" } is a background
ellipse, polygon, star, arc100×100; one of width/height alone makes it square
text, captionsmeasured from the content and font
image, videothe media's native size; one of width/height keeps the aspect ratio
groupthe parent's size
usethe referenced composition's size
path, linethe extent of the points, from (0, 0)

#Reading positions back

inspect shows both coordinate systems: X/Y are the anchor position in the parent's coordinates (the numbers you wrote), and BBOX is the layer's box on the canvas after every transform of every parent. In the demo above at 1 second, the card group is shifted right and tilted, the badge child is still at x: 460, y: 0 in the group, and its canvas box follows the group:

vidmake inspect start-tree.json -t 1s
$ vidmake inspect start-tree.json -t 1s
Frame 30 (1.00s) of `tree` (1280x720), 7 visible layer(s), drawn bottom→top:

ID                       TYPE            X        Y       W       H    ROT  SCALE  OPAC  BBOX [x0,y0,x1,y1]          NOTES
back                     rect        640.0    374.4   460.0   280.0   -6.0   1.00  1.00  [397,211,883,538]           
card                     group       790.0    374.4   460.0   280.0    6.0   1.00  1.00  [547,211,1033,538]          
  panel                  rect        230.0    140.0   460.0   280.0    0.0   1.00  1.00  [547,211,1033,538]          
  badge                  ellipse     460.0      0.0    64.0    64.0    0.0   1.00  1.00  [998,224,1069,294]          
  name                   text        230.0    123.2   188.8   100.8    0.0   1.00  1.00  [693,298,891,418]           "card"
  coords                 text        230.0    201.6   240.0    24.0    0.0   1.00  1.00  [663,411,904,460]           "badge: x "100%", y 0"
caption                  text        640.0    648.0   544.4    26.4    0.0   1.00  1.00  [368,635,912,661]           "children are placed in the group's box, "

#Time

Time is measured in frames. A composition at 30 fps has 30 frames per second, numbered from 0. Every time field accepts a number of frames or a string: "1.5s", "500ms", "45f", "1:02.5". Time lists every format.

Each layer has a time window:

  • start (default 0) is when it appears, relative to its parent: the composition, or the group it is in.
  • duration (or end) is how long it stays. The default is the rest of the parent, except for media, which defaults to the media's length.
  • Outside its window, a layer isn't drawn at all, and neither are its children.

Animation time is local. Keyframe times, tween start/duration, presets and the expression variable t all count from the layer's own start. A fade-in written as "opacity": [[0, 0], ["0.5s", 1]] takes the first half second of the layer, whenever the layer starts. Children of a group count from the group's start. This is what makes layers and groups movable: change a start and everything inside moves with it.

expression variablemeaning
t, fseconds and frames since the layer started
pthe layer's progress, 0 at its start to 1 at its end
dur, durfthe layer's duration in seconds and frames
gt, gfseconds and frames since the composition started

#Every frame is a pure function of time

To draw frame 42, vidmake evaluates every property of every layer at frame 42 and rasterizes the result. Nothing depends on the frames before it: there is no simulation state, no "previous frame". Randomness is seeded: noise(), wiggle(), rand(), particles and film grain produce the same values for the same frame every time.

That has practical consequences:

  • Any frame can be checked on its own. still -t 7.5s, inspect -t 7.5s and a storyboard show exactly what the render will contain at that moment.
  • Renders are reproducible. The same project, props and vidmake version give the same frames.
  • Frames render in parallel across all CPU cores, and --frames 1s-3s renders a slice without rendering what comes before it.

The only inputs besides the JSON are the files it references (media, fonts) and the props you pass.

#Draw order

Layers are drawn in array order: the first layer is at the bottom, the last on top. There is no z-index; to bring a layer forward, move it later in the list (vidmake add --index inserts at a position). A group is drawn at its own position in its parent's list, with its children in their order inside it. In a series, later scenes are drawn above earlier ones, so an incoming scene covers the outgoing one during a transition. A layer used as a mask isn't drawn at all.

inspect lists layers in draw order, bottom to top.

#From JSON to pixels

When you run any command, vidmake:

  1. Loads the file, resolves the theme (with the --theme mode, if any), and substitutes props ({{name}}) and theme tokens ($color.accent) with their values.
  2. Parses it strictly: unknown fields and wrong types are errors, with suggestions.
  3. Compiles the chosen composition into a render tree: resolves times, lays out series, loads fonts, images and media metadata, parses expressions, and computes the duration.
  4. Evaluates each requested frame: every animated value at that time.
  5. Rasterizes the frame on the CPU, including text, effects, masks and motion blur.
  6. Encodes with ffmpeg when rendering a video, GIF or audio file.

validate, timeline, inspect and trace stop after steps 3 or 4, which is why they are fast. still and storyboard go through step 5 for a few frames, and only render does all six for every frame.

#Next steps