Skip to content

feat(runtime): let a page supply its own video frames to the runtime - #8847

Open
robinebers wants to merge 5 commits into
heygen-com:mainfrom
robinebers:pr/frame-source-picture
Open

robinebers wants to merge 5 commits into
heygen-com:mainfrom
robinebers:pr/frame-source-picture

Conversation

@robinebers

Copy link
Copy Markdown
Contributor

I embed HyperFrames in a dashboard where one post can have 40 or more cuts from the same long recording. With native media elements every clip fetches that file on its own. For a single play of a 45 s post we measured 48.8 MB in Chrome and 771 MB in Safari. So our page decodes the media itself (WebCodecs, bounded reads) and hands the frames to the runtime. The same play now costs about 26 MB, and the runtime makes no media requests at all.

I plan to eventually with Miguel's help bring these improvements upstream, but this allows testing them safely in production.

To do that I need a few small additions to the frame-source API. All of them are optional, and nothing changes for a composition that doesn't use them.

  • When a frame source is registered on a timed video or audio element, the runtime leaves that element alone: no load, preload, seek or play, and the first-frame asset scan skips it.
  • canPlayAt(sourceTime) and received() plug into the existing buffering hold. Returning false holds the film. The 8 s give-up counts from the last time received() grew, the same way el.buffered is used today.
  • length() gives the source length for an element that has no duration of its own, so clips end and loop wraps.
  • picture() returns { canvas, time, frame? }, so drawImage(video), WebGL uploads, the colour grade and requestVideoFrameCallback have pixels to work with.

Each part has tests (init.frameSourceMedia.test.ts, plus additions to compositionReadiness.test.ts), and docs/guides/frame-sources.md is updated.

This builds on the buffering hold from #8138 and sits next to #8636.

It's three commits. I'm happy to split it into three pull requests, or to reshape the API if you'd rather have a different seam.

…es it

A frame source can now stand in for a timed <video> or <audio>: a page that
decodes the recording itself (WebCodecs, its own byte reader) registers one on
the element. The runtime then never loads, preloads, seeks or plays that
element: runtimeLoad, setRuntimePreload, syncRuntimeMedia and the hard sync
skip it, and the first-frame asset scan leaves it out, since its readyState
never moves and the player's assets-ready gate would wait out its timeout.

Nothing changes for an element without a frame source.
A frame source that supplies a media element decodes on its own schedule, so
the runtime cannot read its readiness from readyState. Two optional members let
it join the existing Buffering hold:

- canPlayAt(sourceTime): false while the source cannot play on from that
  source time; the film holds until it is true. A source without it never
  holds the film.
- received(): grows while the source still receives data. The hold's 8 s
  give-up reads it where it sums el.buffered, so a slow source keeps holding
  while its data arrives and gives up 8 s after it last grew, as a media
  element does.

The time the hold asks about is the one render() gets (frameSourceTimeAt), and
window.__hf.sourceTimeAt(el, t) returns it to the page, so a source can read
ahead to its clip's last frame. Elements without a frame source take the same
path as before.
A media element a frame source supplies is never loaded, so its duration stays
NaN. A clip without data-duration then has no end, and a loop element has no
length to wrap at.

FrameSource.length() now answers sourceLengthOf when the element has none of
its own; the source announces it with a durationchange event on the element,
as a loaded element does. The source time a loop element's frame source is
asked for wraps at that length, the same rule mediaSourceTimeAt applies to
media the runtime plays itself.
A video a frame source supplies has no picture of its own, so a script's
drawImage(video), a WebGL texture upload and the colour grade read nothing,
and its requestVideoFrameCallback never fires. Those readers already take a
paused frame in its place (getPausedVideoFrame), and the frame-callback shim
already fires for one.

FrameSource.picture() returns the picture on screen as { canvas, time } and,
optionally, the decoded VideoFrame it shows. The paused-frame lookup falls back
to the canvas; after each render the picture is staged for the video's frame
callbacks; the colour grade uploads the VideoFrame when given, which skips a
canvas readback per frame. WebGPU's external texture path is unchanged.
@mintlify

mintlify Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 78c69f1.

Approve preview

@robinebers robinebers changed the title Let a page supply its own video frames to the runtime feat(runtime): let a page supply its own video frames to the runtime Nov 25, 2026
The hook adds frame sources to the published core: both runtime bundles
carry the new members, and compositionReadiness, pausedVideoFrames and
runtimeAttributes now import runtime/frameSources, so tsc also emits it
and adapters/seek-dispatch into dist. That takes the packed core to
1969505 bytes in the Build check, more than 1% over the 1948041 budget,
so verify:packed-manifests fails. The budget rises to 1989200, about 1%
above the measured size.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant