StageRec

Engineering Methodology

Spring-Physics Camera Modeling & Browser-Local Media Pipeline

This page documents the exact mathematical camera model, compositing geometry, and open web standards that power StageRec.

1. Damped Harmonic Spring Camera Solver

Rather than abrupt linear or fixed-bezier easing between zoom targets, StageRec models camera magnification (zoom) and normalized focal coordinates (focusX, focusY) as independent 1D damped harmonic oscillators governed by Hooke’s law and viscous damping:

F = -k * (x - target) - c * v
a = F / m
v_next = v + a * dt
x_next = x + v_next * dt

The solver integrates at a fixed 240 Hz internal sub-step to guarantee numerical stability regardless of monitor refresh rate or export frame rate (30 fps vs. 60 fps). At every sampled frame, focal coordinates are strictly clamped to [0.5 / zoom, 1 - 0.5 / zoom] so zoomed viewports never expose empty black edges outside the recorded frame.

2. Deterministic Frame Compositing & Export

Live preview playback and offline export share the exact same Canvas 2D compositing routine. Layers are rendered in deterministic order: (1) studio gradient, radial mesh, or custom background image; (2) soft elevation drop shadow; (3) clipped rounded window frame with optional macOS or browser title bar; (4) spring-transformed source frame; (5) optional click-pulse highlight ring; and (6) circular webcam Picture-in-Picture overlay.

For MP4 export, frames are rendered offline at exact output timestamps, ensuring even dimensions required by YUV 4:2:0 H.264 profiles and writing fast-start container metadata for immediate web playback. When a browser does not expose H.264 WebCodecs encoding, export automatically falls back to VP9/Opus WebM. Animated GIF exports quantize each composited frame to an adaptive 256-color RGB565 palette for crisp UI typography at lightweight file sizes.

3. Open Web Standards Cited

StageRec relies on published browser specifications rather than proprietary server encoders:

  • W3C Screen Capture Specification

    Powers display, application window, and browser tab capture via getDisplayMedia() with explicit user permission and resolution/frame-rate constraints.

  • W3C WebCodecs Specification

    Enables low-level, hardware-accelerated H.264 video and AAC audio frame encoding directly in browser memory for deterministic offline MP4 exports.

  • W3C Web Audio API

    Mixes microphone narration and captured tab/system audio tracks through independent gain nodes into a synchronized destination stream without clipping.

  • WHATWG HTML Canvas 2D Context

    Composites studio wallpapers, elevation shadows, window chrome, spring-zoomed video crops, click pulse rings, and circular webcam overlays identically for preview and export.

  • WHATWG File System Standard (OPFS)

    Streams incremental local recording chunks into the browser Origin Private File System so long sessions survive unexpected tab closures without cloud storage.