Skip to content

perf(producer): --gpu renders encode while frames are captured - #6631

Merged
miguel-heygen merged 1 commit into
mainfrom
perf/gpu-encode-while-capturing
Oct 28, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
perf/gpu-encode-while-capturing

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

What

Multi-worker mp4 renders with --gpu now encode while frames are still being captured, as software encodes already do. The encode left after capture drops to about zero.

Why

#5952 added encode-while-capturing for multi-worker disk captures but limited it to software libx264. With --gpu, the hardware encoder waited until every frame was captured and then encoded them all serially. That made --gpu slower than the default on a fast Mac: VideoToolbox spent 6.1 s after a 42 s film's capture finished, while overlapped libx264 had 0.1 s left.

The exclusion's stated reason was that overlap reuses the streaming encoder, which had to build the same arguments as the disk encoder. For the GPU encoders it already does: both builders emit identical arguments from -c:v on, for videotoolbox, nvenc, qsv, vaapi and amf. A new test pins that.

Why under 100 lines

One lever: the GPU encoder joins the existing encode-while-capturing path, which already builds the same encoder args. The change is dropping one exclusion, with a test that pins the args match.

Related work

Refs #5952.

How

canEncodeWhileCapturing drops its useGpu !== true condition. Everything else is unchanged: h264 from JPEG frames, not HDR, not chunked, not png/gif, and capture must leave a core free. If the overlapped encode fails, the frames are still encoded after capture as before.

Test plan

  • Unit tests added: encodeWhileCapturing.test.ts (GPU renders are eligible) and deliveryEncoderOptions.test.ts (disk and streaming builders emit the same GPU arguments for all five GPU encoders).
  • Fails without the fix: encodeWhileCapturing.test.ts > runs only when the capture workers leave a core free for the encoder (1 failed / 4 passed with only the tests applied). The argument-parity test passes on main too; it guards the invariant this change relies on.
  • tsc --noEmit (engine, producer) exit 0; engine deliveryEncoderOptions.test.ts 9 passed; producer encodeWhileCapturing.test.ts 5 passed; oxfmt and oxlint clean.
  • Manual testing performed: before/after on the real CLI (below).
  • Documentation updated (not applicable)
  • Comments follow CONTRIBUTING.md "Comments"

Before / after

hyperframes render --gpu, published [email protected] vs the same bundle with only this change, Apple M4 Pro (14 cores, 24 GB, VideoToolbox), repo fixtures, interleaved, medians. wall - compile drops compile, which is network-bound for these fixtures.

fixture wall - compile before after encode after capture, before after
style-11-prod, 1080x1920, 14 s, 4 workers 13.28 s 10.30 s (-22%) 2.7 s 0.0 s
overlay-montage-prod + one mix-blend layer, 42 s, 4 workers 30.92 s 24.94 s (-19%) 6.1 s 0.0 s

Output: VideoToolbox output is not byte-stable on its own (two runs of main on the first fixture gave two different files), so this compares timing only. Encoder, arguments and settings are unchanged.

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 152 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 (0)

Unstable (2)

  • seqplainkeys-none-center-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo false, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true
  • seqresizeundo-none-pct-r0-nested-z100: tracking 0.04, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.04, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.04, 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: APPROVE · 0 blocker · 0 important · 0 nits · head 224f7ce6

Scope

I diffed buildEncoderArgs against buildStreamingArgs. The GPU branches match, including the vaapi -vaapi_device unshift (which sits before -c:v) and the SDR filter/even-pad. The only differences are the input args and -xerror. spawnStreamingEncoder resolves the GPU encoder with getCachedGpuEncoder the same way the disk path does. A failed overlap still falls back to runEncodeStage. The fails-without-fix test is named. All workflows are green on this head.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Oct 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 28, 2026
@miguel-heygen
miguel-heygen force-pushed the perf/gpu-encode-while-capturing branch 2 times, most recently from b22b23a to a98075d Compare October 28, 2026 08:23
@miguel-heygen
miguel-heygen force-pushed the perf/gpu-encode-while-capturing branch from a98075d to 169eaa8 Compare October 28, 2026 08:45
@miguel-heygen
miguel-heygen added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit 6553b1f Oct 28, 2026
79 of 82 checks passed
@miguel-heygen
miguel-heygen deleted the perf/gpu-encode-while-capturing branch October 28, 2026 09:51
@heygengenesis heygengenesis Bot mentioned this pull request Oct 28, 2026
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