Skip to content

Write HTML. Render video. Built for agents.

feat(producer): routing predicate for non-drawelement parallel streaming

vanceingalls2416e9bcd588
diff --git a/packages/producer/src/services/renderOrchestrator.test.ts b/packages/producer/src/services/renderOrchestrator.test.ts
index f3eb95841c..2472932db9 100644
--- a/packages/producer/src/services/renderOrchestrator.test.ts
+++ b/packages/producer/src/services/renderOrchestrator.test.ts
@@ -34,6 +34,7 @@ import {
shouldRetryViaPinnedFallback,
shouldPreferParallelDrawElement,
shouldPreferSingleWorkerDrawElement,
+ shouldStreamParallelCapture,
shouldUseStreamingEncode,
} from "./renderOrchestrator.js";
import { ensureFrameWritten } from "./render/stages/captureHdrFrameShared.js";
@@ -2049,3 +2050,43 @@ describe("shouldRetryViaPinnedFallback (widen the self-verify retry to generic c
).toBe(false);
});
});
+
+describe("shouldStreamParallelCapture (non-DE parallel streaming router)", () => {
+ const eligible = {
+ routerEnabled: true,
+ workerCount: 3,
+ useDrawElement: false,
+ outputFormat: "mp4" as const,
+ streamingOk: true,
+ layeredOrEffectRoute: false,
+ };
+
+ it("routes an eligible multi-worker non-drawElement render", () => {
+ expect(shouldStreamParallelCapture(eligible)).toBe(true);
+ });
+
+ it("is disabled by default (kill switch off is the shipped default)", () => {
+ expect(shouldStreamParallelCapture({ ...eligible, routerEnabled: false })).toBe(false);
+ });
+
+ it("never fires for single-worker renders (those already stream)", () => {
+ expect(shouldStreamParallelCapture({ ...eligible, workerCount: 1 })).toBe(false);
+ });
+
+ it("never fires when drawElement will capture (the DE routers own that path)", () => {
+ expect(shouldStreamParallelCapture({ ...eligible, useDrawElement: true })).toBe(false);
+ });
+
+ it("only applies to mp4", () => {
+ expect(shouldStreamParallelCapture({ ...eligible, outputFormat: "webm" })).toBe(false);
+ expect(shouldStreamParallelCapture({ ...eligible, outputFormat: "png-sequence" })).toBe(false);
+ });
+
+ it("respects the streaming-encode config/duration gates", () => {
+ expect(shouldStreamParallelCapture({ ...eligible, streamingOk: false })).toBe(false);
+ });
+
+ it("skips HDR-layered and shader-transition routes", () => {
+ expect(shouldStreamParallelCapture({ ...eligible, layeredOrEffectRoute: true })).toBe(false);
+ });
+});
diff --git a/packages/producer/src/services/renderOrchestrator.ts b/packages/producer/src/services/renderOrchestrator.ts
index c915ec5d29..c5a39a82a0 100644
--- a/packages/producer/src/services/renderOrchestrator.ts
+++ b/packages/producer/src/services/renderOrchestrator.ts
@@ -1299,6 +1299,54 @@ export function shouldRetryViaPinnedFallback(args: {
return args.deWorkerInversion === "inverted" || args.deParallelRouter === "routed";
}
+/**
+ * Parallel-streaming router for NON-drawElement capture (screenshot on
+ * macOS/Windows/forced-screenshot, BeginFrame on Linux): should this
+ * multi-worker render stream captured frame buffers straight into the single
+ * ffmpeg stdin encoder (interleaved distribution + ordered reorder-buffer
+ * writer — the PR #2056 machinery) instead of the parallel disk path (workers
+ * write JPEGs, a separate sequential encode pass reads them back)?
+ *
+ * Measured motivation (2026-07-10, macOS SS W3): the disk path's encode is a
+ * purely additive tail (~27% of wall clock on a 3,600-frame comp). Streaming
+ * overlapped it for 1.29x on a uniform-cost comp and was a wash (not a
+ * regression) on a 39%-static bimodal comp — the interleaved writer's
+ * near-lockstep coupling eats the encode win when frame costs are bimodal.
+ * v1 accepts the wash; static-aware routing is a documented follow-up.
+ *
+ * Unlike the DE router this deliberately does NOT require auto-resolved
+ * workers: streaming doesn't change the worker count, so an explicit
+ * `--workers 3` should benefit too. It requires !useDrawElement
+ * (post-resolveConfig — always true on Linux): DE parallel renders belong to
+ * the DE parallel router (HF_DE_PARALLEL_ROUTER) with its self-verify
+ * machinery; both DE predicates independently require useDrawElement, making
+ * the two routers mutually exclusive by construction.
+ */
+export function shouldStreamParallelCapture(args: {
+ /** HF_CAPTURE_PARALLEL_STREAM === "true" — kill switch, default OFF. */
+ routerEnabled: boolean;
+ workerCount: number;
+ /** cfg.useDrawElement AFTER resolveConfig clamps. */
+ useDrawElement: boolean;
+ outputFormat: NonNullable<RenderConfig["format"]>;
+ /** shouldUseStreamingEncode(cfg, format, 1, duration) at the call site —
+ * carries the enableStreamingEncode/format/duration-cap gates. */
+ streamingOk: boolean;
+ /** HDR layered composite or shader transitions — bespoke pipelines
+ * (including page-side compositing, which only engages when
+ * hasShaderTransitions) that never stream. */
+ layeredOrEffectRoute: boolean;
+}): boolean {
+ return (
+ args.routerEnabled &&
+ args.workerCount > 1 &&
+ !args.useDrawElement &&
+ args.outputFormat === "mp4" &&
+ args.streamingOk &&
+ !args.layeredOrEffectRoute
+ );
+}
+
export function resolveCaptureForceScreenshotForPageSideCompositing(args: {
forceScreenshot: boolean;
usePageSideCompositing: boolean;