Repository navigation
feat(runtime): let a page supply its own video frames to the runtime - #8847
Open
robinebers wants to merge 5 commits into
Open
robinebers wants to merge 5 commits into
robinebers wants to merge 5 commits into
Conversation
…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.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
canPlayAt(sourceTime)andreceived()plug into the existing buffering hold. Returning false holds the film. The 8 s give-up counts from the last timereceived()grew, the same wayel.bufferedis used today.length()gives the source length for an element that has no duration of its own, so clips end andloopwraps.picture()returns{ canvas, time, frame? }, sodrawImage(video), WebGL uploads, the colour grade andrequestVideoFrameCallbackhave pixels to work with.Each part has tests (
init.frameSourceMedia.test.ts, plus additions tocompositionReadiness.test.ts), anddocs/guides/frame-sources.mdis 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.