Skip to content

Write HTML. Render video. Built for agents.

fix(core): the runtime never reports a film's length as Infinity (#4372)

Miguel Ángelc6913aabe26c
diff --git a/packages/core/src/runtime/timeline.test.ts b/packages/core/src/runtime/timeline.test.ts
index ae4e4b87e2..a783442128 100644
--- a/packages/core/src/runtime/timeline.test.ts
+++ b/packages/core/src/runtime/timeline.test.ts
@@ -1026,4 +1026,36 @@ describe("collectRuntimeTimelinePayload", () => {
const result = collectRuntimeTimelinePayload(defaultParams);
expect(result.clips.find((c) => c.id === "my-script")).toBeUndefined();
});
+
+ describe("root duration with no data-duration and a GSAP timeline past the voiceover", () => {
+ function appendVoicedRoot(timelineSeconds: number) {
+ const root = document.createElement("div");
+ root.setAttribute("data-composition-id", "main");
+ document.body.appendChild(root);
+ const voiceover = document.createElement("audio");
+ voiceover.id = "voiceover";
+ voiceover.setAttribute("data-start", "0");
+ voiceover.setAttribute("data-duration", "154.8");
+ root.appendChild(voiceover);
+ (window as TimelineTestWindow).__timelines = { main: { duration: () => timelineSeconds } };
+ }
+
+ it("reports the timeline when its animations simply end after the voiceover", () => {
+ appendVoicedRoot(156);
+
+ const result = collectRuntimeTimelinePayload(defaultParams);
+
+ expect(result.durationSeconds).toBe(156);
+ expect(result.durationInFrames).toBe(156 * 30);
+ });
+
+ it("reports the voiceover's window for an endless loop (GSAP repeat: -1), never Infinity", () => {
+ appendVoicedRoot(1e10);
+
+ const result = collectRuntimeTimelinePayload(defaultParams);
+
+ expect(result.durationSeconds).toBe(154.8);
+ expect(result.durationInFrames).toBe(Math.ceil(154.8 * 30));
+ });
+ });
});
diff --git a/packages/core/src/runtime/timeline.ts b/packages/core/src/runtime/timeline.ts
index e4fdfbfc00..89ccfccf55 100644
--- a/packages/core/src/runtime/timeline.ts
+++ b/packages/core/src/runtime/timeline.ts
@@ -27,6 +27,11 @@ import { COMPOSITION_CONTRACT_VERSION } from "../compositionContract.js";
import { runtimeProtocolMetadata } from "./protocol.js";
import { isElementNode, isMediaElement } from "./domRealm";
+/** A root timeline this long is an endless loop, not a film: GSAP reports 1e10 s for `repeat: -1`.
+ * Studio's sanitizeDurationSeconds rejects the same length. Animations that simply end past the
+ * voiceover are real duration, and the runtime player already plays them. */
+const LOOP_INFLATED_TIMELINE_SECONDS = 7200;
+
export function isRuntimeElementVisibleAt(
rawNode: HTMLElement,
options: {
@@ -368,7 +373,7 @@ export function collectRuntimeTimelinePayload(params: {
const timelineLooksLoopInflated =
timelineDurationCandidate != null &&
finiteWindowFloor != null &&
- timelineDurationCandidate > finiteWindowFloor + 1;
+ timelineDurationCandidate >= LOOP_INFLATED_TIMELINE_SECONDS;
// Prefer explicit authored root duration first.
// If absent, guard against loop-inflated GSAP durations by trusting finite media window.
const preferredRootDuration =
@@ -690,16 +695,13 @@ export function collectRuntimeTimelinePayload(params: {
// payload duration down to the last visible clip end, the controls jump even
// though playback still runs for the full authored root duration.
const safeDuration = Math.max(1, maxEnd || 1, rootCompositionDuration ?? 0);
- const shouldEmitNonDeterministicInf = timelineLooksLoopInflated && attrDurationCandidate == null;
- const durationInFrames = shouldEmitNonDeterministicInf
- ? Number.POSITIVE_INFINITY
- : Math.max(1, Math.ceil(safeDuration * Math.max(1, params.canonicalFps)));
+ const durationInFrames = Math.max(1, Math.ceil(safeDuration * Math.max(1, params.canonicalFps)));
return {
...runtimeProtocolMetadata(params.canonicalFps),
source: "hf-preview",
type: "timeline",
compositionContractVersion: COMPOSITION_CONTRACT_VERSION,
- durationSeconds: shouldEmitNonDeterministicInf ? Number.POSITIVE_INFINITY : safeDuration,
+ durationSeconds: safeDuration,
durationInFrames,
clips,
scenes,