Skip to content

Commit 81f60db

Browse files
fix(producer): exports no longer fail on a video clip outside the composition's length (#5431)
* fix(engine): exports no longer fail on a video clip outside the composition's length A clip that starts at or after the composition's end (or ends before 0) is never on screen, so extraction skips it. Its timeline window stayed as authored, so the frame-coverage gate still expected its full length and aborted the render with "captured 0 of expected N frames". Such a clip now leaves extraction with an empty window, the same way a partly visible clip is already trimmed to its visible part, so it owes no frames. * fix(producer): drop clips outside the timeline before extraction, cloud renders included The previous commit marked such a clip with end = start, but the window resolver reads a zero-length slot as "use the source's natural length", and the distributed plan still required an extracted entry for every declared clip. Instead, the extract stage (shared by in-process and distributed renders) removes clips that lie entirely outside [0, duration) from the composition before probing and extraction, using one engine predicate that the extractor's own early skip also uses, so a clip ending before 0 is no longer downloaded or probed either. * fix(engine): keep natural-length clips when dropping clips outside the timeline A clip with no authored end carries end 0 (script-created media, or a src set from a script), which the window resolver reads as "natural source length". The outside-the-timeline check treated it as ending at 0 and dropped it, so the clip froze on its first frame. Only an authored end (after the start) at or before 0 now counts as before the timeline. * fix(producer): only drop clips that start at or after the composition's end A clip with no authored length carries end 0, the same value as an authored end at 0, so "ends at or before 0" cannot be told apart from "natural length" and a script-created clip with a negative start was dropped and froze. Clips entirely before 0 keep main's behaviour; the filter now only drops clips starting at or after the end, which never reads the end. * test(producer): pin that a clip starting just before the end is still extracted
1 parent 748cda9 commit 81f60db

4 files changed

Lines changed: 44 additions & 3 deletions

File tree

‎packages/engine/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export {
204204
parseImageElements,
205205
extractVideoFramesRange,
206206
extractAllVideoFrames,
207+
isVideoPastTimelineEnd,
207208
resolveTimelineExtractionWindow,
208209
resolveVideoExtractionWindow,
209210
resolveFinalFrameExtractionWindow,

‎packages/engine/src/services/videoFrameExtractor.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,10 @@ function canHoldFinalFramePastEof(video: TimelineWindowVideo): boolean {
13481348
// one frame, while FFmpeg seeks to the separately probed real frame timestamp.
13491349
const FINAL_FRAME_LOGICAL_DURATION_SECONDS = 1e-6;
13501350

1351+
export function isVideoPastTimelineEnd(video: Pick<VideoElement, "start">, timelineEnd: number) {
1352+
return video.start >= timelineEnd;
1353+
}
1354+
13511355
/** Move a clip to its extraction window; a rate lane is shifted so it keeps integrating from the new origin. */
13521356
export function rebaseVideoToWindow(video: VideoElement, window: TimelineExtractionWindow): void {
13531357
if (window.preserveTimelinePhase) return;
@@ -1868,7 +1872,9 @@ export async function extractAllVideoFrames(
18681872
const warnedSrcs = new Set<string>();
18691873
for (const video of videos) {
18701874
if (signal?.aborted) break;
1871-
if (options.timelineEnd !== undefined && video.start >= options.timelineEnd) continue;
1875+
if (options.timelineEnd !== undefined && isVideoPastTimelineEnd(video, options.timelineEnd)) {
1876+
continue;
1877+
}
18721878
try {
18731879
let videoPath = video.src;
18741880
if (!isHttpUrl(videoPath)) {

‎packages/producer/src/services/render/stages/extractVideosStage.timelineBound.test.ts‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const extractionCalls = vi.hoisted(
1212
);
1313
const toneMapHdrToSdrCalls = vi.hoisted(() => new Array<boolean | undefined>());
1414
const contentKeyedDirsCalls = vi.hoisted(() => new Array<readonly string[] | undefined>());
15+
const requestedVideoIds = vi.hoisted(() => new Array<string[]>());
1516
const fixtureState = vi.hoisted(() => ({ sourceDurationSeconds: 60 }));
1617

1718
vi.mock("@hyperframes/engine", async (importOriginal) => {
@@ -27,6 +28,7 @@ vi.mock("@hyperframes/engine", async (importOriginal) => {
2728
contentKeyedDirs?: readonly string[];
2829
},
2930
): Promise<ExtractionResult> => {
31+
requestedVideoIds.push(videos.map((v) => v.id));
3032
const sourceDurationSeconds = fixtureState.sourceDurationSeconds;
3133
const video = videos[0];
3234
if (!video) throw new Error("timeline-bound fixture requires one video");
@@ -80,8 +82,8 @@ import { runExtractVideosStage } from "./extractVideosStage.js";
8082
async function runStage(
8183
compositionDuration: number,
8284
materializeSymlinks: boolean,
83-
options: { source?: string; log?: ProducerLogger } = {},
84-
): Promise<void> {
85+
options: { source?: string; log?: ProducerLogger; extraVideos?: VideoElement[] } = {},
86+
): Promise<VideoElement[]> {
8587
const composition = {
8688
duration: compositionDuration,
8789
videos: [
@@ -94,6 +96,7 @@ async function runStage(
9496
loop: false,
9597
hasAudio: false,
9698
},
99+
...(options.extraVideos ?? []),
97100
],
98101
audios: [],
99102
images: [],
@@ -115,6 +118,7 @@ async function runStage(
115118
assertNotAborted: () => {},
116119
materializeSymlinks,
117120
});
121+
return composition.videos;
118122
}
119123

120124
describe.each([
@@ -150,6 +154,32 @@ describe.each([
150154
expect(toneMapHdrToSdrCalls).toEqual([true]);
151155
});
152156

157+
it("drops clips starting at or after the end before extraction, keeping natural-length ones", async () => {
158+
requestedVideoIds.splice(0);
159+
const outside = (id: string, start: number, end: number): VideoElement => ({
160+
id,
161+
src: "outside.mp4",
162+
start,
163+
end,
164+
mediaStart: 0,
165+
loop: false,
166+
hasAudio: false,
167+
});
168+
169+
const videos = await runStage(2, materializeSymlinks, {
170+
extraVideos: [
171+
outside("after-end", 2, 4),
172+
outside("just-before-end", 1.99, 0),
173+
outside("natural-length", 0, 0),
174+
outside("negative-natural-length", -1, 0),
175+
],
176+
});
177+
178+
const kept = ["root-video", "just-before-end", "natural-length", "negative-natural-length"];
179+
expect(requestedVideoIds).toEqual([kept]);
180+
expect(videos.map((v) => v.id)).toEqual(kept);
181+
});
182+
153183
it("caches the compiled remote-media copies by content", async () => {
154184
contentKeyedDirsCalls.splice(0);
155185

‎packages/producer/src/services/render/stages/extractVideosStage.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
detectTransfer,
4646
extractAllVideoFrames,
4747
extractMediaMetadata,
48+
isVideoPastTimelineEnd,
4849
isHdrColorSpace,
4950
resolveProjectRelativeSrc,
5051
runVideoExtractionWithRetry,
@@ -389,6 +390,9 @@ export async function runExtractVideosStage(
389390

390391
const stage2Start = Date.now();
391392
const extractionPolicy = resolveVideoExtractionPolicy();
393+
composition.videos = composition.videos.filter(
394+
(video) => !isVideoPastTimelineEnd(video, composition.duration),
395+
);
392396

393397
let frameLookup: FrameLookupTable | null = null;
394398
let extractionResult: Awaited<ReturnType<typeof extractAllVideoFrames>> | null = null;

0 commit comments

Comments
 (0)