How the player draws
This page follows one frame through @uberscene/player, from the resolved file to the pixels on screen. The export draws the same way (How the export works). To use the player, read Player.
Layers in one box
The player stacks its layers in a box the size of the composition. Most files need three:
┌───────────────────────────────────────────┐
│ DOM overlays: titles, shapes, SVG, │ React, absolutely positioned, one group per track
│ stickers, layers, captions, <Three>, │
│ <Motion> │
├───────────────────────────────────────────┤
│ canvas: footage, images, nested │ one 2D canvas, painted from a frame plan
│ sequences, adjustments, transitions │
├───────────────────────────────────────────┤
│ backdrop: overlays on tracks beneath │ DOM again, under a transparent canvas
│ every footage track, and the background │
└───────────────────────────────────────────┘Tracks draw in the order the file writes them, so the first track is at the bottom. Footage goes on the canvas because it has to be decoded and composited by the pixel. Everything else is DOM, because free code is any React and CSS and only the browser can lay it out.
A file may write an overlay track between two footage tracks: a card over the interview and under a cut-out speaker. One canvas cannot be both under and over that card, so each run of footage tracks is a band with a canvas of its own (trackBands), and the overlays between two bands sit between their canvases:
overlays above the last footage DOM
canvas 1: the footage above clear ground
overlays between DOM
canvas 0: the footage beneath the background, or a clear ground over a backdropOne frame plan still lists every op; each carries its band, and bandPlan gives a canvas its part. An adjustment is in the plan of every band beneath it, so it changes all the footage under it. A file whose footage is in one run has one band and one canvas. A host that attaches a single canvas (attachCanvas) gets all the footage on it.
One tick
The Compositor draws the canvas. Each tick, for a time t, runs four steps:
- Plan.
buildFramePlan(state, t)lists what shows att(visiblePlacements) and turns each clip, nested sequence and adjustment into aDrawOp: its source time, rect, transform matrix, crop, fit, opacity, blend, CSS filter, mask, wipe clip, and its shader effects and transition. The plan is plain data and runs without a DOM. - Sync decoders. The
DecoderPoolkeeps aClipDecoderfor every media placement near the play head and drops the rest. Assets are opened once and shared, nested sequences included. - Gather frames. Each op asks its decoder for the picture at its source time. A nested sequence ticks its own compositor at its own time and is drawn as a picture.
- Paint. The
CanvasPainterruns the plan on a 2D context, once per band: each op under its own transform, alpha, blend and filter. One hard mask clips; several masks, or one that is soft, faded, inverted or notadd, are drawn into an alpha on a scratch canvas (each joined by itsmode) that the element is kept through. An adjustment re-filters everything drawn so far through a scratch canvas.
A tick that arrives while another is running is merged into one re-run. A tick on the frame already painted only keeps the decoders reading ahead.
Decoding
Footage is decoded with WebCodecs through mediabunny. A ClipDecoder has three modes:
| Mode | When | How |
|---|---|---|
| Stream | playing forward | reads from the source into a short queue |
| Reverse | playing backward | decodes windows behind the cursor ahead of time |
| Seek | scrubbing, high speeds | fetches single frames |
While playing, the decoder never blocks a tick. If the frame for t isn't ready, it returns the last frame it had, so the preview stays smooth. A seek or an export asks for an exact frame (wait: true), and the tick waits for it.
Decoders sit behind the FrameSource interface. The export's native decoder plugs in there.
Effects and transitions
There are two ways an effect gets drawn:
- CSS filters (blur, brightness, saturation…) go on the op's
filterand are applied by the 2D context. - Shader passes run in WebGL 2. Each pass is a GLSL function (the kit's own or the file's, from
effect()andtransition()). The runner wraps it in a fragment shader with its params as uniforms. Passes in the middle draw into textures, and the last one draws to the canvas.
Where there is no WebGL 2, the painter falls back to fallbackFilter and fallbackOpacity: a CSS approximation, or a crossfade for a transition.
Vignette and grain are drawn on the element's own pixels before its other effects. On an adjustment they cover everything beneath it.
Overlays
DomLayer renders the overlays as React, one positioned group per track, in compositing order. Positions and keyframes use the same transform maths as the canvas ops, so an overlay lines up with the footage under it.
The overlay plane is its own stacking context, so a CSS blend there never reaches the footage, and the canvas has the masks, vignette and grain. An overlay with a blend other than normal, a <Mask>, a vignette or grain is drawn into the canvas instead. ShaderBox draws its DOM into a picture of the frame (HTML-in-Canvas), and the plan holds an op of kind overlay for it, in the band of its track, with the overlay's own box and matrix. The painter gives that picture what footage gets: its blend, its masks and its vignette or grain. Its track counts as canvas content (trackBands), so overlays above it stay above it. The DOM is kept, laid out but not shown, for hit testing, the layout check and the editor's handles. In a browser without HTML-in-Canvas it stays a plain overlay, unblended and unmasked, with one warning.
An overlay with shader effects is drawn by ShaderBox. Its DOM lives inside a canvas (HTML-in-Canvas, drawElementImage in Chrome), and the shaders run over that picture. In a browser without HTML-in-Canvas, the overlay shows without its effects.
<Three> and <Motion> follow the player's clock instead of their own. A layer that hasn't drawn the current frame yet holds it (holdLayerFrame), and the export waits for those holds before it captures.
Sound and the clock
The sound is mixed with Web Audio, and the same AudioContext keeps the time.
- Clock.
AudioClockreadsAudioContext.currentTimewhile audio runs and the performance clock when it doesn't. It records an offset at every switch, so time never jumps. - Transport. Composition time is worked out from the clock each time:
anchorTime + (now − anchorClock) × rate. Play, pause, seek and rate changes set a new anchor, so time never drifts. - Mixing.
buildAudioPlanturns the resolved file into chunks with gain envelopes, speed ramps and reversal. TheAudioEngineschedules each chunk a little ahead of the transport. A seek or rate change starts a new session.
The export mixes the same audio plan offline with mixPlan instead of playing it.
Next
- How the export works: this player, run headless, one frame at a time.
- What renders: the few values the player accepts but does not draw.
- Player: embedding it, seeking and capture.