Timed comments that cross the video as clickable DOM
Each comment below is an HTML element that the canvas draws over the video, at a position worked out from the time of the video frame. Press Play. Tap a comment to stop it and open its Like button. Write one of your own and it's added at the current time.
The video hasn't been played yet.
Show the code comments as cues, one element each, placed per frame
- The markup. The video and a control bar are children of the canvas. Comment elements are added beside them.
- Store comments as cues.
video.addTextTrack('metadata')makes a track that is never shown. Each comment is aVTTCuewhose text is JSON. - One element per active cue. The same library as the captions page, with a
renderfunction that makes a comment. - The comment element. A
drawablediv holding buttons. - Where a comment is at a time. A function of the media time, so the same time always gives the same picture.
- Draw. One
drawElementImage()call per comment, inside a transform. The call also moves the element's hit-test region. - Taps. Ordinary click handlers on the buttons.
- Export.
exportFrames()seeks the video frame by frame, andonframechooses the comments for each time. - The CSS.
How it works
- The comments live in a text track of kind
metadata. A cue runs from the comment's time for 4 seconds, the time a comment takes to cross. The browser keepsactiveCuescurrent, so the page holds elements only for the comments on screen. - Every comment is its own
drawablechild of the canvas. The paint handler computesx = W − (t − start) ÷ 4 × (W + width)from the media timetthatrequestVideoFrameCallback()reported for the frame, and draws the element there. drawElementImage()sets the element's hit-test region to where it was drawn, including the rotation in the wave mode. A tap on a moving comment is an ordinaryclickon its button.- The inverting mode sets
globalCompositeOperation = 'difference'for the draw call. White text then shows the inverse of the frame under it. - A Like is written back into the cue's JSON text, so the count is still there when the video loops and the element is built again.
- The export pauses the video, seeks to each frame time and asks the cue library for the cues at that time by comparing times, because
activeCuesis updated only after the seek has finished.
Live checks
Each check builds its own small video and canvas in a corner of the window. The player above isn't touched.
| Result | Experiment | Detail |
|---|
Findings
From Chromium 157 headless with software video decoding, 2026-11-21. The rows above say what your browser does.
- Works: a metadata track as the store.
addTextTrack('metadata')starts in thehiddenmode, and cues added by script enteractiveCueslike cues from a file. - Works: elements added and removed while the video plays. A new
drawablechild can't be drawn until the browser has recorded it once. The firstdrawElementImage()call throws, so the paint handler skips the element and asks for another paint. - Works: the position matches the frame. The third check plays a fixture and, in each paint, reads the frame number from the stripes in the picture. It reports how many paints drew the comment for that same frame.
- Works: taps on moving and rotated comments.
elementFromPoint()finds the comment's button at the drawn place, and no longer finds it there after the comment has moved on. - Works: the
differenceblend mode on an element. The composite operation applies todrawElementImage()as it does todrawImage(). - Works: frame-exact export. In an exported file the comment moves the same number of pixels in every frame.
- Limit: a comment that starts in the last 4 seconds is cut off when the clip loops. Its cue can't run past the end of the video.
- Not verified: the frame match with a hardware decoder on Android, the cost of 30 or more comments on a phone, and tapping a moving comment with a finger. The third check and the line under the player report the first two on the device.