kpranav022 Claude Opus 4.8 commited on
Commit
a7ec099
·
1 Parent(s): 5756769

Composite the editor preview in the browser so edits show up live

Browse files

The preview was a single <video> whose src was swapped per clip, so every cut
re-fetched from the CDN and stalled, and captions/titles/music existed only in
ffmpeg at export — you styled a caption and saw nothing until a multi-minute
round trip. Now the playhead (global timeline seconds) is the single source of
truth: one <video> per clip stays mounted and preloaded and only the active one
is shown, so playback is gapless; captions and titles are drawn as DOM boxes
using the export's own geometry (preview.ts mirrors _render_overlay_png and
_OVERLAY_Y, scaled by previewWidth/videoWidth); music previews through a synced
<audio>. The timeline scrubs on click/drag and space toggles playback.

Fixes three ways an edit could silently corrupt:
- Caption edits were keyed by array index, so reordering or trimming a clip
moved hand-edited text onto different words. Cues now carry a stable
clip-key#ordinal identity.
- Titles held absolute timeline seconds while trims moved the timeline under
them; they're now anchored to a clip + offset and resolved at export, and one
whose clip was deleted is dropped rather than exported at 0s.
- Closing the editor discarded every trim, caption and overlay. State autosaves
per render and is restored with a "start fresh" escape hatch.

Also: deleting a clip is undoable, the playhead no longer jumps backwards at a
clip boundary, and rAF drives the playhead at ~30fps instead of onTimeUpdate's
~4fps so captions track the video smoothly.

preview.check.ts covers the cue-key and geometry invariants (21 assertions); no
test runner is configured, so it documents its own esbuild+node one-liner.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

3 files changed +1115 -488
Files changed (3)
frontend/src/components/VideoEditor.tsx+882-488
frontend/src/components/editor/preview.check.tsAdded+76
frontend/src/components/editor/preview.tsAdded+157