AI media harness for planning, generating, and editing locally
TypeScript
Preview the active video trim edge
Bitti2fdf5293d274
diff --git a/docs/video-references.md b/docs/video-references.mdindex 0b868a7..1fe3f2a 100644--- a/docs/video-references.md+++ b/docs/video-references.md@@ -76,7 +76,9 @@ selection limit. The handles also support arrow keys (0.1 seconds), Shift+arrowYou can also seek in the video player and choose **Start at playhead**.**Play selection** previews only the chosen segment and stops at its end.**Include sound** controls the selected interval's soundtrack. Changing the-selection seeks the existing player without reloading the source. The segment+selection seeks the existing player without reloading the source. Trimming the+start previews the start frame; trimming the end previews the end frame, which+remains visible after releasing the handle. The segmentand sound setting are saved with the project and used during generation.Each selected clip must last 2–15 seconds. A generation can use up to three video clipsdiff --git a/src/components/workspace/ReferenceVideo.test.tsx b/src/components/workspace/ReferenceVideo.test.tsxindex cd660f3..8354df7 100644--- a/src/components/workspace/ReferenceVideo.test.tsx+++ b/src/components/workspace/ReferenceVideo.test.tsx@@ -39,8 +39,10 @@ it("starts at 0–15 seconds and moves and resizes the selection without reloadiexpect(video.currentTime).toBe(60);fireEvent.keyDown(screen.getByRole("slider", { name: "Selection end" }), { key: "ArrowLeft", shiftKey: true });expect(saved().durationSeconds).toBe(14);+ expect(video.currentTime).toBe(74);fireEvent.keyDown(screen.getByRole("slider", { name: "Selection start" }), { key: "ArrowRight", shiftKey: true });expect(saved()).toMatchObject({ startSeconds: 61, durationSeconds: 13 });+ expect(video.currentTime).toBe(61);expect(screen.getByLabelText("Long video video preview")).toBe(video);expect(readMediaFileUrl).toHaveBeenCalledTimes(1);});@@ -65,7 +67,7 @@ it("drags the selected interval and its edges", async () => {constructor(type: string, init: PointerEventInit) { super(type, init); this.pointerId = init.pointerId ?? 1; }});render(<Harness />);- await ready();+ const video = await ready();const bar = screen.getByLabelText("Drag the selection or its edges");Object.defineProperty(bar, "setPointerCapture", { value: vi.fn() });vi.spyOn(bar, "getBoundingClientRect").mockReturnValue({ width: 300, left: 0 } as DOMRect);@@ -73,10 +75,21 @@ it("drags the selected interval and its edges", async () => {fireEvent.pointerMove(bar, { pointerId: 1, clientX: 125 });fireEvent.pointerUp(bar, { pointerId: 1 });expect(saved()).toMatchObject({ startSeconds: 5, durationSeconds: 15 });+ expect(video.currentTime).toBe(5);fireEvent.pointerDown(screen.getByRole("slider", { name: "Selection end" }), { button: 0, pointerId: 2, clientX: 200 });+ expect(video.currentTime).toBe(20);fireEvent.pointerMove(bar, { pointerId: 2, clientX: 150 });+ expect(video.currentTime).toBe(15);fireEvent.pointerUp(bar, { pointerId: 2 });expect(saved()).toMatchObject({ startSeconds: 5, durationSeconds: 10 });+ expect(video.currentTime).toBe(15);+ fireEvent.pointerDown(screen.getByRole("slider", { name: "Selection start" }), { button: 0, pointerId: 3, clientX: 50 });+ expect(video.currentTime).toBe(5);+ fireEvent.pointerMove(bar, { pointerId: 3, clientX: 70 });+ expect(video.currentTime).toBe(7);+ fireEvent.pointerUp(bar, { pointerId: 3 });+ expect(saved()).toMatchObject({ startSeconds: 7, durationSeconds: 8 });+ expect(video.currentTime).toBe(7);});it("starts the segment at the frame chosen in the video player", async () => {diff --git a/src/components/workspace/ReferenceVideo.tsx b/src/components/workspace/ReferenceVideo.tsxindex e9bb7ae..fc368db 100644--- a/src/components/workspace/ReferenceVideo.tsx+++ b/src/components/workspace/ReferenceVideo.tsx@@ -35,11 +35,13 @@ export function ReferenceVideo({ folderPath, reference, onChange }: {const [dragging, setDragging] = useState(false);const selectionPlayback = useRef(false);const frameCallback = useRef<number | null>(null);+ const previewEdge = useRef<"start" | "end">("start");useEffect(() => {let disposed = false;let owned: string | null = null;setUrl(null); setError(null); setSourceDuration(null); setPreviewing(false);selectionPlayback.current = false;+ previewEdge.current = "start";gesture.current = null; setDragging(false);void readMediaFileUrl(folderPath, reference, "video/mp4").then((value) => {if (disposed) { if (value) URL.revokeObjectURL(value); return; }@@ -71,12 +73,20 @@ export function ReferenceVideo({ folderPath, reference, onChange }: {}, [url]);useEffect(() => {stop();- if (video.current && sourceDuration !== null) video.current.currentTime = start;+ const time = previewEdge.current === "end" ? end : start;+ if (video.current && sourceDuration !== null && video.current.currentTime !== time) video.current.currentTime = time;}, [start, length]);+ const previewTrim = (action: TrimAction, selection: ReferenceVideoTrim) => {+ stop();+ previewEdge.current = action === "end" || action === "duration" ? "end" : "start";+ const time = selection.startSeconds + (previewEdge.current === "end" ? selection.durationSeconds : 0);+ if (video.current && video.current.currentTime !== time) video.current.currentTime = time;+ };const change = (action: TrimAction, value: number, original = trim) => {if (!original || sourceDuration === null) return;const next = editReferenceVideoTrim(original, sourceDuration, action, value);+ previewTrim(action, next);onChange({ ...next, includeAudio: reference.video?.includeAudio ?? true });};const checkPlayback = () => {@@ -101,7 +111,7 @@ export function ReferenceVideo({ folderPath, reference, onChange }: {event.preventDefault(); event.stopPropagation();const box = bar.current.getBoundingClientRect();if (!box.width) return;- stop();+ previewTrim(action, trim);gesture.current = { pointerId: event.pointerId, action, x: event.clientX, width: box.width, trim, windowStart, windowDuration };bar.current.setPointerCapture(event.pointerId);setDragging(true);