feat(playlist): seamless playback of selected shots, cut only
Deploy / deploy (push) Successful in 3m12s

Check shots on the Playlist page and "Play selection" plays them back to
back without slate or handles. The cut comes from the version's handle and
slate metadata (new cutSpan in lib/handles); the media is never changed.

SequencePlayer double-buffers two videos: the next clip is parked a few
frames before its cut-in and pre-rolled hidden, the outgoing clip pauses on
its last cut frame, and the cut fires on the incoming clip's cut-in frame
(requestVideoFrameCallback), with the start time calibrated at each cut.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
twotalesanimation
2026-09-26 08:55:46 +02:00
parent 824695ef30
commit b596c97faf
5 changed files with 1087 additions and 12 deletions
+33 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { computeEditRange, frameRegion, isHandleFrame } from "./handles";
import { computeEditRange, cutSpan, frameRegion, isHandleFrame } from "./handles";
describe("computeEditRange", () => {
it("is null when no handles are marked", () => {
@@ -92,3 +92,35 @@ describe("frameRegion", () => {
expect(isHandleFrame(range, 1)).toBe(true);
});
});
describe("cutSpan", () => {
it("plays the cut when handles are marked, skipping slate and handles", () => {
// 1 slate + 8 head + 84 cut + 8 tail = 101 MP4 frames
expect(cutSpan({ handleHead: 8, handleTail: 8, frameCount: 100 }, 101)).toEqual({
start: 9,
end: 93,
});
});
it("plays the whole picture minus the slate when no handles are marked", () => {
expect(cutSpan({ frameCount: 100 }, 101)).toEqual({ start: 1, end: 101 });
expect(cutSpan({ pictureStartFrame: 2 }, 50)).toEqual({ start: 2, end: 50 });
});
it("plays the whole media when nothing is known about it", () => {
expect(cutSpan(null, 48)).toEqual({ start: 0, end: 48 });
expect(cutSpan({}, 48)).toEqual({ start: 0, end: 48 });
});
it("is null until the media length is known", () => {
expect(cutSpan({ handleHead: 8, handleTail: 8 }, 0)).toBeNull();
});
it("never returns an empty span", () => {
// Handles longer than the picture
expect(cutSpan({ handleHead: 30, handleTail: 30, frameCount: 40 }, 40)).toEqual({
start: 0,
end: 40,
});
});
});
+41 -3
View File
@@ -61,6 +61,21 @@ export function computeEditRange(
const tail = Math.max(0, Math.floor(handles.handleTail ?? 0));
if (head === 0 && tail === 0) return null;
const { pictureStart, pictureEnd } = pictureBounds(handles, totalFrames);
const cutIn = Math.min(pictureStart + head, pictureEnd);
const tailStart = Math.max(cutIn, pictureEnd - tail);
return { pictureStart, cutIn, tailStart, pictureEnd };
}
/**
* Where the picture sits in the media: after any slate, up to the end of the
* rendered frames. See computeEditRange for how the slate is found.
*/
function pictureBounds(
handles: VersionHandles,
totalFrames: number
): { pictureStart: number; pictureEnd: number } {
const frameCount =
handles.frameCount != null && handles.frameCount > 0 ? Math.floor(handles.frameCount) : null;
@@ -80,10 +95,33 @@ export function computeEditRange(
const pictureEnd =
frameCount != null ? Math.min(totalFrames, pictureStart + frameCount) : totalFrames;
const cutIn = Math.min(pictureStart + head, pictureEnd);
const tailStart = Math.max(cutIn, pictureEnd - tail);
return { pictureStart, pictureEnd };
}
return { pictureStart, cutIn, tailStart, pictureEnd };
/** A half-open frame range [start, end) of the review media. */
export interface FrameSpan {
start: number;
end: number;
}
/**
* The frames a seamless playlist plays for this version: the cut when handles
* are marked, otherwise the whole picture — never the slate. Falls back to
* the whole media rather than an empty span, so a clip never plays nothing.
*/
export function cutSpan(
handles: VersionHandles | null | undefined,
totalFrames: number
): FrameSpan | null {
if (!(totalFrames > 0)) return null;
const edit = computeEditRange(handles, totalFrames);
const span = edit
? { start: edit.cutIn, end: edit.tailStart }
: (() => {
const { pictureStart, pictureEnd } = pictureBounds(handles ?? {}, totalFrames);
return { start: pictureStart, end: pictureEnd };
})();
return span.end > span.start ? span : { start: 0, end: totalFrames };
}
export type FrameRegion = "slate" | "head" | "edit" | "tail";