Skip to content

fix(core): at full quality a 4K clip plays a copy at the size the preview shows it - #7723

Merged
miguel-heygen merged 4 commits into
mainfrom
fix/preview-4k-shown-size
Nov 14, 2026
Merged

miguel-heygen merged 4 commits into
mainfrom
fix/preview-4k-shown-size

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

What

At full preview quality, a video with at least twice the pixels the preview shows it at (a 4K take in a 1080p-or-smaller preview) now plays a copy made at the size it is shown. Until that copy is ready, the clip shows a still frame and never loads its original. Below full quality nothing changes, except that an oversized file is held the same way while its lighter copy is made. Render and export never use copies, as before.

Why

A preview of many 4K takes ran the renderer out of memory. Each clip near the playhead decoded its original at 3840x2160 to show it at about a quarter of that. Lighter copies existed only below full quality, and even there the original kept decoding until its copy arrived, so opening such a project spiked memory before any copy landed.

Related work

Builds on #7679, which frees a clip's decoder once the playhead leaves it. This change addresses the clips that are near the playhead.

How

  • previewProxyBox.ts: wantsLighterCopy(facts, box, level) is the one rule for when a copy is made. Below full quality it is the existing isHeavyForPreview. At full quality it is only isOversizedForPreview, the pixel share, so a 10-bit, HDR or high-bitrate source that is not oversized keeps its own look.
  • mediaProxy.ts: the proactive path and setPreviewQuality apply that rule at every level, and keepSized asks it too, so going back to full quality keeps a copy only while the file is still oversized for its box. While the copy of an oversized file is made, holdForCopy records the authored src (readers still see the file), removes the src, asks for the existing server still at the playhead on each poll, and holds frame captures up to the existing HOLD_CAP_MS. If the copy cannot be made, or the wait ends for any other reason, the hold ends as it found the clip: one the preload held until due stays held (giveBackWhenDue brings it back), any other gets its src back with its in-point record, so fix(core): free a preview clip's decoder when the playhead leaves it #7679's idle hold still frees it.
  • mediaProxy.ts holds and ends the hold (holdForCopy, endCopyHold); proxySrc.ts only shares the state (heldForCopy, inPointOf), and giveBackWhenDue in preloadMedia.ts skips a clip in heldForCopy, so the near-playhead path does not load the file the hold just stopped.

Test plan

  • Unit tests added/updated
  • Manual testing performed

Unit tests, run one file at a time:

  • src/runtime/mediaProxy.test.ts: 81 of 81 pass.
  • src/runtime/preloadMedia.test.ts: 43 of 43 pass.
  • src/runtime/entry.test.ts: 57 of 57 pass.
  • src/runtime/media.test.ts: 195 of 195 pass.
  • src/previewProxyBox.test.ts: 8 of 8 pass.

New tests at full quality:

  • a 3840x2160 file shown in a 2048x1218 box holds no src while its copy is made, then plays the 2048x1218 copy, and readers see the authored src throughout;
  • it is not given its file back as its clip comes due;
  • it gets its file back when the copy fails, as it was before the copy: still held if it was not due, with its idle hold if it was opened at its in-point;
  • it waits for the lower copy, still not loading, when the level drops;
  • 2560x1440 files, 8-bit and 10-bit, are left alone.

Three existing tests that asserted "full quality never makes a copy" now use files that are not oversized at that box.

fails without the fix: mediaProxy.test.ts > at full quality, a file with at least twice the pixels it shows > never loads the file while its copy is made, and plays a copy at the shown box (with the hold removed the file keeps its src); and > stays held until due when its copy fails, as it was before the copy (with the old give-back the not-due clip gets /video.mp4 back).

Each test was shown to fail without its code:

  • removing the hold fails 3 tests;
  • letting giveBackWhenDue ignore the wait fails 1;
  • making full quality want no copy fails the new tests;
  • writing the file back on a failed copy without its record (the first head's behaviour) fails the two copy-failure tests, 2 of 81.

Also checked: tsc --noEmit for core, oxfmt and oxlint are clean. @hyperframes/core stays inside its size budget without raising it: the hold code ships only inside the minified runtime.

Manual, in an app that embeds the Studio preview, running this runtime against today's. The project was generated: 1080x1920, six 3840x2160 h264 takes cut into 65 clips. I sampled the app's renderer memory every 2 s for 60 s after opening, on a Linux box with software rendering, one run each.

Full quality Main renderer peak Sum of renderers + GPU, peak Videos decoding 3840x2160
today, untagged takes 3,089 MB 4,623 MB 5
this change, untagged takes (two runs) 2,043 / 1,880 MB 3,087 / 3,095 MB 0 (5 copies at 1082x609)
today, BT.709-tagged takes 2,960 MB 4,322 MB 5
this change, BT.709-tagged takes 1,896 MB 4,047 MB 0

Picture at full quality, the same paused frame, today against this change, the preview cropped from the app window:

  • BT.709-tagged takes (most camera footage): the same colours, sampled yellow (254,255,12) and blue (1,0,243) in both, SSIM 0.97. A thin diagonal line is slightly softer at 2x zoom.
  • Untagged takes: the copy's colours differ from today's preview, yellow (255,241,3) today against (250,255,11) for the copy, while the pattern's true yellow is (254,254,0) and a BT.709-tagged take shows (254,255,12) both ways. The copy is the right one. An untagged file's pixels are BT.601 (as ffmpeg writes them and as export reads them); the browser decodes an untagged original as BT.709, so today's preview of such a file is off from its export, and the copy (converted to the BT.709 it is tagged with) matches the export.

At 1/2 (the level the app picks with no GPU), the main renderer peak is 1,812 MB with this change.

What I did not exercise:

  • a machine with a GPU, macOS or Windows;
  • real camera footage;
  • more than one run per arm, except the repeat noted above;
  • an untagged source from a camera (the colour check used generated untagged takes).

With software rendering the copies took about 50 s to land at full quality. Until then those clips showed the still.

BT.709-tagged takes at full quality: today (left) and this change (right), same paused frame

Untagged takes: today at full, this change at full, 1/2 copy (the copies match the export; today's preview of an untagged file does not)

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 114 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

Unstable (1)

  • seqab-none-center-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@heygengenesis heygengenesis Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST CHANGES · 2 blocker · 0 important · 0 nits · head 65ca9f8b

  • blocker — the body has no fails without the fix: line. This lane requires one on fix PRs, naming a test that fails without the fix. "Each test was shown to fail without its code" lists counts, not a named test. Add, for example, fails without the fix: mediaProxy.test.ts › at full quality… › never loads the file while its copy is made….
  • blocker — a failed copy undoes #7679's idle hold for exactly the oversized clips this PR targets. ↓ inline
Scope

Read all 5 files. The 5 test files in the body pass locally (382/382), and all CI runs on this head passed. The copy-served path, the level-drop path and the giveBackWhenDue skip behave as the body describes. I checked the failure finding with probe tests run against this head and against main.

Comment thread packages/core/src/runtime/mediaProxy.ts Resolved

@heygengenesis heygengenesis Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST CHANGES — 2 resolved, 0 open, 1 new · 65ca9f8 → 2c16f19

  • blocker — required Build is red in both runs on this head. verify:packed-manifests reports "@hyperframes/core unpacked size 4373870 bytes is over its budget of 4330000 by more than 1%" (the limit is 4,373,300 bytes, so it is 570 bytes over). main passes. Raise core's entry in scripts/package-size-budgets.json and give the reason in the body.

@heygengenesis heygengenesis Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE — 3 resolved, 0 open, 0 new · 2c16f19 → 69697b2

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