mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
feat(producer): render a part of the film with HDR video or shader transitions (#8802)
* feat(producer): render a part of the film with HDR video or shader transitions The layered route now takes the frame window too, so a range renders HDR compositions and webm/mov shader transitions in one pass instead of being refused. Both layered loops seek the film frame and look up transitions by it, and the transition count that picks the hybrid loop counts only the window's frames. A whole render frees each HDR video's frames once it passes the clip's end, and the compositor draws a video until then. A window replays that freeing for the frames before it, so its first frame no longer shows a video that ended earlier in the film. * refactor(producer): name the window start and transition lookup the layered loops share * test(producer): pin the frame where a range stops replaying ended HDR videos
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveFrameWindow } from "./frameWindow.js";
|
||||
import { assertRangeSupported, resolveFrameWindow } from "./frameWindow.js";
|
||||
|
||||
const fps30 = { num: 30, den: 1 };
|
||||
const ntsc = { num: 30000, den: 1001 };
|
||||
@@ -42,3 +42,21 @@ describe("resolveFrameWindow", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("assertRangeSupported", () => {
|
||||
const window = { startFrame: 75, endFrame: 120 };
|
||||
|
||||
it("lets the disk and layered routes capture a window", () => {
|
||||
expect(() => assertRangeSupported(window, "sdr_disk")).not.toThrow();
|
||||
expect(() => assertRangeSupported(window, "hdr_layered")).not.toThrow();
|
||||
});
|
||||
|
||||
it("refuses a window on the streaming routes, which render whole films", () => {
|
||||
expect(() => assertRangeSupported(window, "sdr_streaming")).toThrow(
|
||||
/renders the whole film only/,
|
||||
);
|
||||
expect(() => assertRangeSupported(window, "sdr_segmented")).toThrow(
|
||||
/renders the whole film only/,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -30,12 +30,16 @@ export function resolveFrameWindow(range: RenderRange, fps: Fps, filmFrames: num
|
||||
return { startFrame, endFrame };
|
||||
}
|
||||
|
||||
/** Only the disk route captures a frame window; HDR content and shader transitions render whole films for now. */
|
||||
export function windowStartFrame(frameWindow: FrameWindow | undefined): number {
|
||||
return frameWindow?.startFrame ?? 0;
|
||||
}
|
||||
|
||||
/** The disk and layered routes capture a frame window; the streaming routes render whole films. */
|
||||
export function assertRangeSupported(
|
||||
frameWindow: FrameWindow | undefined,
|
||||
route: CapturePlan["kind"],
|
||||
): void {
|
||||
if (!frameWindow || route === "sdr_disk") return;
|
||||
if (!frameWindow || route === "sdr_disk" || route === "hdr_layered") return;
|
||||
throw new Error(
|
||||
`This composition renders on the "${route}" capture route, which renders the whole film only; ` +
|
||||
"render it without a start or end.",
|
||||
|
||||
@@ -171,6 +171,11 @@ describe("partitionTransitionFrames", () => {
|
||||
expect(set.has(3)).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps a window's film frames, from its first frame", () => {
|
||||
const set = partitionTransitionFrames([{ startFrame: 95, endFrame: 105 }], 10, 100);
|
||||
expect([...set].sort((a, b) => a - b)).toEqual([100, 101, 102, 103, 104, 105]);
|
||||
});
|
||||
|
||||
it("returns empty set for non-positive totalFrames", () => {
|
||||
expect(partitionTransitionFrames([{ startFrame: 0, endFrame: 5 }], 0).size).toBe(0);
|
||||
expect(partitionTransitionFrames([{ startFrame: 0, endFrame: 5 }], -1).size).toBe(0);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
* centralized here.
|
||||
*/
|
||||
|
||||
import type { Fps } from "@hyperframes/core";
|
||||
import {
|
||||
type BeforeCaptureHook,
|
||||
type CaptureSession,
|
||||
@@ -89,12 +90,13 @@ export function distributeLayeredHybridFrameRanges(
|
||||
export function partitionTransitionFrames(
|
||||
transitionRanges: ReadonlyArray<Pick<TransitionRange, "startFrame" | "endFrame">>,
|
||||
totalFrames: number,
|
||||
firstFrame = 0,
|
||||
): Set<number> {
|
||||
const frames = new Set<number>();
|
||||
if (totalFrames <= 0) return frames;
|
||||
for (const range of transitionRanges) {
|
||||
const start = Math.max(0, range.startFrame);
|
||||
const end = Math.min(totalFrames - 1, range.endFrame);
|
||||
const start = Math.max(firstFrame, range.startFrame);
|
||||
const end = Math.min(firstFrame + totalFrames - 1, range.endFrame);
|
||||
for (let i = start; i <= end; i++) frames.add(i);
|
||||
}
|
||||
return frames;
|
||||
@@ -416,3 +418,25 @@ export function cleanupEndedHdrVideos(args: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function transitionAtFrame(
|
||||
transitionRanges: TransitionRange[],
|
||||
frame: number,
|
||||
): TransitionRange | undefined {
|
||||
return transitionRanges.find((t) => frame >= t.startFrame && frame <= t.endFrame);
|
||||
}
|
||||
|
||||
export function cleanupHdrVideosEndedBefore(
|
||||
firstFrame: number,
|
||||
fps: Fps,
|
||||
transitionRanges: TransitionRange[],
|
||||
state: Omit<Parameters<typeof cleanupEndedHdrVideos>[0], "time" | "activeTransition">,
|
||||
): void {
|
||||
for (let frame = 0; frame < firstFrame; frame++) {
|
||||
cleanupEndedHdrVideos({
|
||||
...state,
|
||||
time: (frame * fps.den) / fps.num,
|
||||
activeTransition: transitionAtFrame(transitionRanges, frame),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ShaderBlendRequest } from "../../shaderTransitionWorkerPool.js";
|
||||
import { type HybridLoopInput, runHybridLayeredFrameLoop } from "./captureHdrHybridLoop.js";
|
||||
import {
|
||||
captureTransitionFrameOnWorker,
|
||||
seekInjectAndQueryStacking,
|
||||
} from "./captureHdrFrameShared.js";
|
||||
|
||||
vi.mock("@hyperframes/engine", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("@hyperframes/engine")>()),
|
||||
@@ -47,11 +51,18 @@ vi.mock("../../shaderTransitionWorkerPool.js", () => ({
|
||||
function loopInput(overrides: {
|
||||
writeFrame?: (frame: number) => boolean;
|
||||
assertNotAborted?: () => void;
|
||||
firstFrame?: number;
|
||||
}): HybridLoopInput {
|
||||
const first = overrides.firstFrame ?? 0;
|
||||
const log = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() };
|
||||
let frame = 0;
|
||||
const input = {
|
||||
job: { config: { fps: { num: 30, den: 1 } }, totalFrames: 16, framesRendered: 0 },
|
||||
job: {
|
||||
config: { fps: { num: 30, den: 1 } },
|
||||
totalFrames: 16,
|
||||
framesRendered: 0,
|
||||
...(first && { frameWindow: { startFrame: first, endFrame: first + 16 } }),
|
||||
},
|
||||
cfg: {},
|
||||
log,
|
||||
framesDir: "/tmp/unused",
|
||||
@@ -78,8 +89,8 @@ function loopInput(overrides: {
|
||||
ease: "",
|
||||
fromScene: "a",
|
||||
toScene: "b",
|
||||
startFrame: 2,
|
||||
endFrame: 13,
|
||||
startFrame: first + 2,
|
||||
endFrame: first + 13,
|
||||
},
|
||||
],
|
||||
sceneElements: { a: ["a"], b: ["b"] },
|
||||
@@ -117,6 +128,25 @@ describe("runHybridLayeredFrameLoop failures with 2 workers", () => {
|
||||
expect(escaped).toEqual([]);
|
||||
});
|
||||
|
||||
it("seeks film frames and finds the film's transition inside a window", async () => {
|
||||
vi.mocked(seekInjectAndQueryStacking).mockClear();
|
||||
vi.mocked(captureTransitionFrameOnWorker).mockClear();
|
||||
const input = loopInput({ firstFrame: 100 });
|
||||
await runHybridLayeredFrameLoop(input);
|
||||
expect(input.job.framesRendered).toBe(16);
|
||||
const transitions = vi
|
||||
.mocked(captureTransitionFrameOnWorker)
|
||||
.mock.calls.map(([args]) => args as { frameIdx: number; time: number });
|
||||
const normalTimes = vi.mocked(seekInjectAndQueryStacking).mock.calls.map((call) => call[1]);
|
||||
const seekedFrames = [...normalTimes, ...transitions.map((t) => t.time)]
|
||||
.map((time) => Math.round(Number(time) * 30))
|
||||
.sort((a, b) => a - b);
|
||||
expect(seekedFrames).toEqual(Array.from({ length: 16 }, (_, k) => 100 + k));
|
||||
expect(transitions.map((t) => t.frameIdx).sort((a, b) => a - b)).toEqual(
|
||||
Array.from({ length: 12 }, (_, k) => 102 + k),
|
||||
);
|
||||
});
|
||||
|
||||
let aborts = 0;
|
||||
it.each([
|
||||
{
|
||||
|
||||
@@ -54,8 +54,10 @@ import {
|
||||
ensureFrameWritten,
|
||||
partitionTransitionFrames,
|
||||
seekInjectAndQueryStacking,
|
||||
transitionAtFrame,
|
||||
} from "./captureHdrFrameShared.js";
|
||||
import { reportFrameProgress } from "../shared.js";
|
||||
import { windowStartFrame } from "../frameWindow.js";
|
||||
|
||||
export interface HybridLoopInput {
|
||||
job: RenderJob;
|
||||
@@ -112,7 +114,8 @@ export async function runHybridLayeredFrameLoop(input: HybridLoopInput): Promise
|
||||
assertNotAborted,
|
||||
onProgress,
|
||||
} = input;
|
||||
const transitionFramesSet = partitionTransitionFrames(transitionRanges, totalFrames);
|
||||
const firstFrame = windowStartFrame(job.frameWindow);
|
||||
const transitionFramesSet = partitionTransitionFrames(transitionRanges, totalFrames, firstFrame);
|
||||
const hasTransitions = transitionRanges.length > 0;
|
||||
const bufSize = width * height * 6;
|
||||
|
||||
@@ -228,9 +231,10 @@ export async function runHybridLayeredFrameLoop(input: HybridLoopInput): Promise
|
||||
for (let i = range.start; i < range.end; i++) {
|
||||
throwIfFailed();
|
||||
assertNotAborted();
|
||||
const time = (i * job.config.fps.den) / job.config.fps.num;
|
||||
const activeTransition = transitionFramesSet.has(i)
|
||||
? transitionRanges.find((t) => i >= t.startFrame && i <= t.endFrame)
|
||||
const frame = firstFrame + i;
|
||||
const time = (frame * job.config.fps.den) / job.config.fps.num;
|
||||
const activeTransition = transitionFramesSet.has(frame)
|
||||
? transitionAtFrame(transitionRanges, frame)
|
||||
: undefined;
|
||||
if (activeTransition && ring) {
|
||||
// Pick the next ring slot. If it's still in flight from an earlier
|
||||
@@ -247,7 +251,7 @@ export async function runHybridLayeredFrameLoop(input: HybridLoopInput): Promise
|
||||
// because the per-worker browser session is single-threaded.
|
||||
await captureTransitionFrameOnWorker({
|
||||
session,
|
||||
frameIdx: i,
|
||||
frameIdx: frame,
|
||||
time,
|
||||
transition: activeTransition,
|
||||
buffers,
|
||||
@@ -265,7 +269,7 @@ export async function runHybridLayeredFrameLoop(input: HybridLoopInput): Promise
|
||||
const progress =
|
||||
activeTransition.endFrame === activeTransition.startFrame
|
||||
? 1
|
||||
: (i - activeTransition.startFrame) /
|
||||
: (frame - activeTransition.startFrame) /
|
||||
(activeTransition.endFrame - activeTransition.startFrame);
|
||||
// BLEND + ENCODE without awaiting. The promise drains back into
|
||||
// `ringInFlight[slot]`; the next iteration that picks `slot`
|
||||
@@ -327,7 +331,7 @@ export async function runHybridLayeredFrameLoop(input: HybridLoopInput): Promise
|
||||
// Rebind ctx to this worker's session for per-layer captures
|
||||
const wctx: HdrCompositeContext = { ...hdrCompositeCtx, domSession: session };
|
||||
await timeHdrPhaseAsync(hdrPerf, "normalCompositeMs", () =>
|
||||
compositeHdrFrame(wctx, canvas, time, stackingInfo, undefined, i),
|
||||
compositeHdrFrame(wctx, canvas, time, stackingInfo, undefined, frame),
|
||||
);
|
||||
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
||||
writeFileExclusiveSync(
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { expect, it, vi } from "vitest";
|
||||
import { compositeHdrFrame } from "../../hdrCompositor.js";
|
||||
import { captureSceneIntoBuffer, seekInjectAndQueryStacking } from "./captureHdrFrameShared.js";
|
||||
import {
|
||||
type SequentialLoopInput,
|
||||
runSequentialLayeredFrameLoop,
|
||||
} from "./captureHdrSequentialLoop.js";
|
||||
|
||||
vi.mock("./captureHdrFrameShared.js", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("./captureHdrFrameShared.js")>()),
|
||||
captureSceneIntoBuffer: vi.fn(async () => {}),
|
||||
seekInjectAndQueryStacking: vi.fn(async () => []),
|
||||
}));
|
||||
vi.mock("../../hdrCompositor.js", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("../../hdrCompositor.js")>()),
|
||||
compositeHdrFrame: vi.fn(async () => {}),
|
||||
}));
|
||||
|
||||
function windowInput(written: number[]): SequentialLoopInput {
|
||||
return {
|
||||
job: {
|
||||
config: { fps: { num: 30, den: 1 } },
|
||||
totalFrames: 10,
|
||||
framesRendered: 0,
|
||||
frameWindow: { startFrame: 100, endFrame: 110 },
|
||||
},
|
||||
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
|
||||
width: 1,
|
||||
height: 1,
|
||||
totalFrames: 10,
|
||||
nativeHdrIds: new Set<string>(),
|
||||
nativeHdrImageIds: new Set<string>(),
|
||||
hdrCompositeCtx: {},
|
||||
hdrPerf: undefined,
|
||||
hdrEncoder: { writeFrame: async () => written.push(written.length) > 0 },
|
||||
domSession: { page: {} },
|
||||
transitionRanges: [
|
||||
{ time: 0, duration: 0, shader: "crossfade", ease: "", fromScene: "a", toScene: "b" },
|
||||
].map((t) => ({ ...t, startFrame: 104, endFrame: 106 })),
|
||||
sceneElements: { a: ["a"], b: ["b"] },
|
||||
compositeTransfer: "srgb",
|
||||
hdrTargetTransfer: undefined,
|
||||
hdrVideoEndTimes: new Map(),
|
||||
cleanedUpVideos: new Set(),
|
||||
hdrVideoFrameSources: new Map(),
|
||||
debugDumpEnabled: false,
|
||||
debugDumpDir: null,
|
||||
assertNotAborted: () => {},
|
||||
// The loop only touches the fields above.
|
||||
} as unknown as SequentialLoopInput;
|
||||
}
|
||||
|
||||
it("seeks film frames and finds the film's transition inside a window", async () => {
|
||||
const written: number[] = [];
|
||||
await runSequentialLayeredFrameLoop(windowInput(written));
|
||||
|
||||
const seeked = vi
|
||||
.mocked(seekInjectAndQueryStacking)
|
||||
.mock.calls.map((call) => Math.round(Number(call[1]) * 30));
|
||||
expect(seeked).toEqual(Array.from({ length: 10 }, (_, k) => 100 + k));
|
||||
// Two scenes per transition frame, film frames 104-106.
|
||||
const transitionFrames = vi
|
||||
.mocked(captureSceneIntoBuffer)
|
||||
.mock.calls.map(([args]) => args.frameIdx);
|
||||
expect(transitionFrames).toEqual([104, 104, 105, 105, 106, 106]);
|
||||
expect(written).toHaveLength(10);
|
||||
});
|
||||
|
||||
it("starts a window without the HDR videos a whole render has already passed the end of", async () => {
|
||||
const input = windowInput([]);
|
||||
const close = vi.fn();
|
||||
input.hdrVideoEndTimes.set("ended", 1);
|
||||
input.hdrVideoEndTimes.set("playing", 5);
|
||||
// Ends between frames 99 and 100: a whole render still draws it at frame 100, then frees it.
|
||||
input.hdrVideoEndTimes.set("endsAtFirstFrame", 3.31);
|
||||
for (const id of ["ended", "playing", "endsAtFirstFrame"]) {
|
||||
const dir = mkdtempSync(join(tmpdir(), `hf-hdr-${id}-`));
|
||||
input.hdrVideoFrameSources.set(id, { dir, windows: { close } } as never);
|
||||
}
|
||||
let shownAtFirstFrame: string[] = [];
|
||||
vi.mocked(compositeHdrFrame).mockImplementationOnce(async () => {
|
||||
shownAtFirstFrame = [...input.hdrVideoFrameSources.keys()];
|
||||
});
|
||||
|
||||
await runSequentialLayeredFrameLoop(input);
|
||||
|
||||
expect(shownAtFirstFrame).toEqual(["playing", "endsAtFirstFrame"]);
|
||||
});
|
||||
@@ -36,11 +36,14 @@ import { writeFileExclusiveSync } from "../shared.js";
|
||||
import {
|
||||
captureSceneIntoBuffer,
|
||||
cleanupEndedHdrVideos,
|
||||
cleanupHdrVideosEndedBefore,
|
||||
transitionAtFrame,
|
||||
ensureFrameWritten,
|
||||
type LayeredTransitionBuffers,
|
||||
seekInjectAndQueryStacking,
|
||||
} from "./captureHdrFrameShared.js";
|
||||
import { reportFrameProgress } from "../shared.js";
|
||||
import { windowStartFrame } from "../frameWindow.js";
|
||||
|
||||
export interface SequentialLoopInput {
|
||||
job: RenderJob;
|
||||
@@ -104,9 +107,18 @@ export async function runSequentialLayeredFrameLoop(input: SequentialLoopInput):
|
||||
: null;
|
||||
const normalCanvas = Buffer.alloc(bufSize);
|
||||
|
||||
const firstFrame = windowStartFrame(job.frameWindow);
|
||||
cleanupHdrVideosEndedBefore(firstFrame, job.config.fps, transitionRanges, {
|
||||
hdrVideoEndTimes,
|
||||
cleanedUpVideos,
|
||||
hdrVideoFrameSources,
|
||||
sceneElements,
|
||||
log,
|
||||
});
|
||||
for (let i = 0; i < totalFrames; i++) {
|
||||
assertNotAborted();
|
||||
const time = (i * job.config.fps.den) / job.config.fps.num;
|
||||
const frame = firstFrame + i;
|
||||
const time = (frame * job.config.fps.den) / job.config.fps.num;
|
||||
if (hdrPerf) hdrPerf.frames += 1;
|
||||
|
||||
const stackingInfo = await seekInjectAndQueryStacking(
|
||||
@@ -119,12 +131,12 @@ export async function runSequentialLayeredFrameLoop(input: SequentialLoopInput):
|
||||
"frameInjectMs",
|
||||
"stackingQueryMs",
|
||||
);
|
||||
const activeTransition = transitionRanges.find((t) => i >= t.startFrame && i <= t.endFrame);
|
||||
const activeTransition = transitionAtFrame(transitionRanges, frame);
|
||||
|
||||
if (i % 30 === 0 && (log.isLevelEnabled?.("debug") ?? true)) {
|
||||
const hdrEl = stackingInfo.find((e) => e.isHdr);
|
||||
log.debug("[Render] HDR layer composite frame", {
|
||||
frame: i,
|
||||
frame,
|
||||
time: time.toFixed(2),
|
||||
hdrElement: hdrEl ? { z: hdrEl.zIndex, visible: hdrEl.visible, width: hdrEl.width } : null,
|
||||
stackingCount: stackingInfo.length,
|
||||
@@ -138,7 +150,7 @@ export async function runSequentialLayeredFrameLoop(input: SequentialLoopInput):
|
||||
const progress =
|
||||
activeTransition.endFrame === activeTransition.startFrame
|
||||
? 1
|
||||
: (i - activeTransition.startFrame) /
|
||||
: (frame - activeTransition.startFrame) /
|
||||
(activeTransition.endFrame - activeTransition.startFrame);
|
||||
const sceneAIds = new Set(sceneElements[activeTransition.fromScene] ?? []);
|
||||
const sceneBIds = new Set(sceneElements[activeTransition.toScene] ?? []);
|
||||
@@ -169,7 +181,7 @@ export async function runSequentialLayeredFrameLoop(input: SequentialLoopInput):
|
||||
hdrTargetTransfer,
|
||||
hdrPerf,
|
||||
log,
|
||||
frameIdx: i,
|
||||
frameIdx: frame,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -196,7 +208,7 @@ export async function runSequentialLayeredFrameLoop(input: SequentialLoopInput):
|
||||
if (hdrPerf) hdrPerf.normalFrames += 1;
|
||||
timeHdrPhase(hdrPerf, "canvasClearMs", () => normalCanvas.fill(0));
|
||||
await timeHdrPhaseAsync(hdrPerf, "normalCompositeMs", () =>
|
||||
compositeHdrFrame(hdrCompositeCtx, normalCanvas, time, stackingInfo, undefined, i),
|
||||
compositeHdrFrame(hdrCompositeCtx, normalCanvas, time, stackingInfo, undefined, frame),
|
||||
);
|
||||
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
||||
writeFileExclusiveSync(
|
||||
|
||||
@@ -80,6 +80,7 @@ import { wrapCaptureStageError } from "../captureStageError.js";
|
||||
import { encoderFailureError } from "../encoderInterruption.js";
|
||||
import type { HdrLayeredCapturePlan } from "../capturePlan.js";
|
||||
import type { DeliveryEncoderOptions } from "../deliveryEncoder.js";
|
||||
import { windowStartFrame } from "../frameWindow.js";
|
||||
|
||||
export interface CaptureHdrStageInput {
|
||||
job: RenderJob;
|
||||
@@ -369,7 +370,11 @@ export async function runCaptureHdrStage(
|
||||
|
||||
// ── Dispatch to sequential or hybrid frame loop ────────────────────
|
||||
const effectiveWorkerCount = Math.max(1, workerCount);
|
||||
const transitionFrameCount = partitionTransitionFrames(transitionRanges, totalFrames).size;
|
||||
const transitionFrameCount = partitionTransitionFrames(
|
||||
transitionRanges,
|
||||
totalFrames,
|
||||
windowStartFrame(job.frameWindow),
|
||||
).size;
|
||||
const useHybrid = shouldUseHybridLayeredPath({
|
||||
hasHdrContent,
|
||||
transitionFramesCount: transitionFrameCount,
|
||||
|
||||
@@ -12,6 +12,10 @@ const { state, CAPTURE_REACHED } = vi.hoisted(() => ({
|
||||
shaderTransitions: false,
|
||||
disk: [] as { totalFrames: number; frameRange?: { startFrame: number; endFrame: number } }[],
|
||||
streaming: 0,
|
||||
layered: [] as {
|
||||
totalFrames: number;
|
||||
frameWindow?: { startFrame: number; endFrame: number };
|
||||
}[],
|
||||
audio: [] as { totalFrames: number; frameWindow?: { startFrame: number; endFrame: number } }[],
|
||||
},
|
||||
CAPTURE_REACHED: "capture reached",
|
||||
@@ -102,6 +106,16 @@ vi.mock("./render/stages/captureStage.js", async (importOriginal) => ({
|
||||
throw new Error(CAPTURE_REACHED);
|
||||
},
|
||||
}));
|
||||
vi.mock("./render/stages/captureHdrStage.js", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("./render/stages/captureHdrStage.js")>()),
|
||||
runCaptureHdrStage: async (input: {
|
||||
totalFrames: number;
|
||||
job: { frameWindow?: { startFrame: number; endFrame: number } };
|
||||
}) => {
|
||||
state.layered.push({ totalFrames: input.totalFrames, frameWindow: input.job.frameWindow });
|
||||
throw new Error(CAPTURE_REACHED);
|
||||
},
|
||||
}));
|
||||
vi.mock("./render/stages/captureStreamingStage.js", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("./render/stages/captureStreamingStage.js")>()),
|
||||
runCaptureStreamingStage: async () => {
|
||||
@@ -115,6 +129,7 @@ beforeEach(() => {
|
||||
state.shaderTransitions = false;
|
||||
state.disk = [];
|
||||
state.streaming = 0;
|
||||
state.layered = [];
|
||||
state.audio = [];
|
||||
});
|
||||
afterEach(() => {
|
||||
@@ -164,12 +179,13 @@ it("renders the whole film as before without a range", async () => {
|
||||
expect(state.disk[0]?.frameRange).toBeUndefined();
|
||||
});
|
||||
|
||||
it("refuses a range on the layered route instead of rendering the whole film", async () => {
|
||||
it("captures the range's frames on the layered route", async () => {
|
||||
// webm and mov composite shader transitions on the layered route; mp4 composites them in the page.
|
||||
state.shaderTransitions = true;
|
||||
await expect(render({ startSeconds: 2.5, endSeconds: 4 }, "webm")).rejects.toThrow(
|
||||
/"hdr_layered" capture route, which renders the whole film only/,
|
||||
);
|
||||
await render({ startSeconds: 2.5, endSeconds: 4 }, "webm");
|
||||
expect(state.layered).toEqual([
|
||||
{ totalFrames: 45, frameWindow: { startFrame: 75, endFrame: 120 } },
|
||||
]);
|
||||
expect(state.disk).toEqual([]);
|
||||
expect(state.streaming).toBe(0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user