Video lab: title editor, cinema sound, wide gamut, timeline skin, WebGPU player
Five experiments with a <video> as a canvas child. The first three share one WebGL canvas: choose a scene with the buttons. In the editor, tap the text of a title card on the canvas and type. In the cinema, tap play on the screen, then tap a seat. The last two sections have their own canvases further down.
The controls on the screen in the room are the video's own and take taps there. The Play button here does the same as the one on the screen. Headphones make the position of the sound clearer. The yellow seat is the listener, and the arrow on it is the way the head faces.
The timeline hasn't been found yet.
Play, seek and the other controls are the browser's own. Only the pixels of the timeline strip are changed.
Show the code one WebGL canvas for three scenes: shots and transitions, export, the room and its sound, the timeline skin
- One drawable canvas. Every shot, the cinema screen, the seat map and the player are its children.
- A title card is HTML. Its text is
contenteditable. - The card's motion is CSS driven by one custom property.
- Which shots are on screen at a time. Two shots overlap for the length of a transition.
- The editor's paint. Upload one or two shots with
texElementSubImage2D()and draw one quad. - The fragment shader. The transitions (three of them from
lib/live-transition.js), the timeline skin, the screen and the floor. - Export.
exportFrames()is given an object that seeks the whole timeline. - The seat map. Buttons whose place in the grid is their place in the room.
- The room. Three planes and a camera.
- The cinema's paint. The same matrix draws a quad and places its hit box.
- From a clip-space matrix to
updateElementGeometry(). - The sound. The video element through a
PannerNodeat the screen. - The timeline skin: the CSS.
- The timeline skin: finding the strip.
- The timeline skin: the paint.
Wide-gamut video in a Display P3 canvas
The same element (a video and three CSS swatches at the Display P3 primaries) is a child of two 2D canvases. The left context is sRGB and the right one is Display P3. On a wide-gamut screen the right canvas is more saturated. On any screen, "Read the pixels" reports the values and marks the pixels that sRGB can't hold.
Show the code a Display P3 context, and reading its pixels from a copy
- The canvas.
getContext('2d', { colorSpace: 'display-p3' })and onedrawElementImage()per paint. - Reading. A
drawImage()copy in a plain canvas, read as Display P3 values.
The player shader in WebGPU
The shader of /player-fx/ in WGSL. The controls of the video are one texture and its frame is another. "Meld" draws the play button's glyph large as a lens over the frame while the video is paused: tap play to see it shrink into the button.
Starts when this section is near the screen.
Show the code two textures from one video in WebGPU, the WGSL shader
- The markup.
- The CSS that leaves only the controls in the element's picture, and the probe colours.
- The device. From
webgpu()in/shared/backend.js, with a 2D fallback. - The frame texture.
- The paint.
drawElementImageToTexture()for the controls, then one render pass. - Finding the parts. The probe picture is copied out of its texture once.
- The shader.
How it works
- One WebGL context. The three scenes are sets of children of one canvas. A scene that isn't chosen has its elements hidden, so they aren't painted and take no taps. One fragment shader has a mode for each kind of quad.
- Title editor. Each shot is an element the size of the canvas: a
<video>in a wrapper, or a title card. At any time one or two shots are uploaded withtexElementSubImage2D(). Where two overlap, the shader mixes them with the chosen transition. The shot in front has its hit box on the canvas, so a title card is edited in place. - Export.
exportFrames()fromlib/video-export.jsseeks one video per frame. Here it is given an object withcurrentTime,pause()and aseekedevent that seeks every video on the timeline and sets each card's--t. Each frame is onepaintand oneVideoFramefrom the canvas. - Cinema screen. The screen, its reflection and the floor are three quads with perspective matrices. The same matrix, with the conversion to CSS pixels, goes to
updateElementGeometry(), so the video's native controls and the seat buttons take taps where they are drawn. The page doesn't use three.js here: the site allows one WebGL context per page and the scenes share it. - Sound.
createMediaElementSource(video)feeds aPannerNodeat the centre of the screen. TheAudioListeneris at the chosen seat. The two meters are the level of each output channel, measured by twoAnalyserNodes. - Timeline skin. For one paint,
::-webkit-media-controls-timelinegets a magenta background. That picture goes into a spare texture, the bottom quarter is read once, and the box of the magenta pixels is the timeline. The shader replaces the pixels inside the box and adds a glow at the playhead. - Wide gamut. The two canvases differ only in the
colorSpaceof their 2D context. Pixels are never read from them: each is copied withdrawImage()into a plain canvas with the same colour space, and that copy is read withgetImageData({ colorSpace: 'display-p3' }). - WebGPU player.
GPUQueue.drawElementImageToTexture()uploads the controls.copyExternalImageToTexture()uploads the frame from the same video. The device comes from the page's sharedwebgpu(). Where that gives none, the player is drawn with the 2D context and no shader.
Live checks
The checks build their own small canvases in a corner of the window. The demos above aren't touched.
Findings
Measured in Chromium 157, headless, software rendering, on 2026-11-21. The rows above say what your browser does.
- Works: video clips and HTML title cards as shots, with shader transitions. All five transitions start on the first shot and end on the second. Three of them are the GLSL of
/transitions/, unchanged. - Works: a title card edited on a WebGL canvas. The card in front takes the tap, the caret and the typing.
- Works: frame-by-frame export of several videos and cards. The exported file holds the frames that were asked for. It has no sound track:
exportFrames()takes the sound of one video. - Works: native video controls and buttons on quads in perspective.
elementFromPoint()returns the video at the projected centre of the screen and a seat button at its projected centre. - Works: a
PannerNodeat the screen. Rendered offline, a seat on the left hears more in the right ear and a seat near the screen hears more than one at the back. - Works: a shader on the timeline only. With the skin on and off, no pixel outside the strip and its glow changes.
- Works: a wide-gamut video keeps its colours in a Display P3 canvas. The red of a BT.2020 clip reads as Display P3 (118, 0, 3) there and as (119, 21, 12) from the sRGB canvas.
drawElementImage()anddrawImage(video)give the same values. - Limit: an HDR10 video is tone-mapped to at most 1.0. In a float16 Display P3 canvas the brightest part of a PQ clip is 1.0, the same as in an 8-bit canvas.
- Works off screen: the WGSL shader. On the software adapter the pass was rendered to a texture and read back.
copyExternalImageToTexture(video)failed there, and the frame came throughcreateImageBitmap(video). - Not verified: WebGPU on screen, an HDR screen, and the sound through real speakers. The test browser has none of them.