HTML overlays on video: record, export, send

The picture below is one canvas. It draws a <div> that holds a video, a caption bar, a poll and a CSS-animated ticker. Vote in the poll and change the name. Then record it with the video's sound, export it frame by frame, or send it over WebRTC as a camera would be sent. The result plays under the buttons.

LIVE 0:00.00
Ada LovelaceGuest, programme notes

Which is drawn by the video?

This ticker is a CSS animation on a <span>. The caption bar is a CSS transition. The poll is a <form> with two buttons. Everything in this picture except the video frame is HTML.

Nothing recorded yet.

Show the code video and HTML in one canvas, three ways out
  1. The markup. The video and the overlays are children of one drawable element in the canvas.
  2. The CSS. Ordinary positioning, a transition and an animation.
  3. The paint handler. One drawElementImage() call, with the destination size given. It runs for each video frame and each DOM change.
  4. Record. canvas.captureStream() gives the picture and video.captureStream() gives the sound. MediaRecorder writes both.
  5. Export frame by frame. Seek the video, set each animation's currentTime, wait for one paint, wrap the canvas in a VideoFrame and encode it. The sound track is decoded, cut and encoded as Opus.
  6. Send. The canvas stream is added to an RTCPeerConnection like a camera track.
  7. The three buttons on this page.
  8. The whole library file.

How it works

Live checks

Each check builds its own small canvas in a corner of the window. The picture above isn't touched.

ResultExperimentDetail

Findings

From Chromium 157 with software video decoding. The rows above say what your browser does.