Skip to content

Commit 8f05457

Browse files
Merge pull request #977 from func25/ceil-duration-preview
fix(core): ceil timeline payload duration to match render frames
2 parents 852008b + 0fc3937 commit 8f05457

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

packages/core/src/runtime/timeline.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ describe("collectRuntimeTimelinePayload", () => {
183183
expect(result.durationInFrames).toBe(300); // 10s * 30fps
184184
});
185185

186+
it("ceil durationInFrames to match render frame count", () => {
187+
const root = document.createElement("div");
188+
root.setAttribute("data-composition-id", "main");
189+
root.setAttribute("data-duration", "1.01");
190+
document.body.appendChild(root);
191+
192+
const clip = document.createElement("div");
193+
clip.setAttribute("data-start", "0");
194+
clip.setAttribute("data-duration", "1.01");
195+
root.appendChild(clip);
196+
197+
const result = collectRuntimeTimelinePayload(defaultParams);
198+
expect(result.durationInFrames).toBe(31); // ceil(1.01s * 30fps), same as render.
199+
});
200+
186201
it("preserves the authored root duration when clips end earlier", () => {
187202
const root = document.createElement("div");
188203
root.setAttribute("data-composition-id", "main");

packages/core/src/runtime/timeline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ export function collectRuntimeTimelinePayload(params: {
674674
const shouldEmitNonDeterministicInf = timelineLooksLoopInflated && attrDurationCandidate == null;
675675
const durationInFrames = shouldEmitNonDeterministicInf
676676
? Number.POSITIVE_INFINITY
677-
: Math.max(1, Math.round(safeDuration * Math.max(1, params.canonicalFps)));
677+
: Math.max(1, Math.ceil(safeDuration * Math.max(1, params.canonicalFps)));
678678
return {
679679
source: "hf-preview",
680680
type: "timeline",

0 commit comments

Comments
 (0)