videoskilletdecisions Open the app ↗

0013 — A live take runs on the wall clock, and its frames come off the GPU

Status: accepted, 2026-09-30.

Context#

ui/record.ts stamped every frame by count, i * 1e6 / fps, because MediaRecorder's wall-clock timestamps gave files an editor conforms unevenly. That holds for the offline render (ui/render.ts), which steps the engine and drops nothing. The main app's live recorder used the same stamping, fed one frame per rAF, and three things went wrong with it. All were measured in Firefox Nightly on a 47.89 Hz panel; agent-docs/handoffs/record-clip-audio.md has the runs.

A live take played fast. The engine renders below 60 Hz whenever the display or the frame lock says so, and every render counted as 1/60 s. A 10.03 s take at a full window came back as a 6.3 s file, playing at 1.6x, with the clip in it at 1.6x too.

Sound cannot follow count-stamped picture. A take that carries what the speakers play has to keep real time, because sound cannot be stretched to match a picture that was.

Reading the canvas blocked the page. new VideoFrame(webgpuCanvas) costs Firefox 16-22 ms of main thread per frame at a 1494x933 canvas, and recording took the page from 48.1 Hz to 40.5 Hz.

A held frame can be written as one longer sample or as repeated samples. Repeated samples keep the file strictly constant-framerate, and scripts/repeatcost.mjs measured what they cost: between fresh frames a repeat costs the encoder about two thirds of a fresh one, because Firefox's B-frames code it against neighbours it does not match. At a full window that cuts 31.4 fresh frames a second to 19.2.

Decision#

A live take places each frame the engine renders by when it was rendered, on the take's clock, snapped to the 1/60 s grid. With sound, the clock is the audio context's, averaged against currentTime, which the main thread sees refreshed 74 times a second and up to 56 ms stale, and moved back by the output latency (ui/takeClock.ts). Without sound it is performance.now(). A frame whose period is taken, or that finds the encoder three behind, is dropped, and the frame before it stays up as a longer sample.

The engine copies each rendered frame into a pool of mappable buffers inside the frame's own submit (core/gpu/frameread.ts). The map lands 10-25 ms later, and building the VideoFrame then costs about 3 ms at that size. A window resized mid-take is scaled into the take's size on the GPU.

The muxer writes from presentation times, with ctts and an edit list for the B-frames Firefox's encoder emits.

The offline render keeps count stamping and strict constant framerate. It is where a frame-exact file comes from.

Consequences#