Skip to content

fix(capture): anchor the video start time to the first frame - #1965

Open
abrichr wants to merge 1 commit into
mainfrom
agent/grok-95-frames
Open

abrichr wants to merge 1 commit into
mainfrom
agent/grok-95-frames

Conversation

@abrichr

@abrichr abrichr commented Nov 5, 2026

Copy link
Copy Markdown
Member

Anchors a recording's video_start_time to the timestamp of its first encoded frame instead of the moment the video writer opened.

Why: the encoded stream starts at its first frame, and CaptureSession.get_frame_at turns a wall-clock time into video time by subtracting video_start_time. macOS ScreenCaptureKit only delivers a frame when the screen changes, so on a static screen the first frame can arrive many seconds after the writer opens. Every lookup was then shifted by that delay and could land past the end of the video. I hit this on a macOS 15 VM recording: the first frame arrived about 15 s late, the video was 1.54 s long, and compiling failed with "no captured frame available for click at t=15.682s".

Change: in write_video_event, when the first frame is written (no last_frame yet), store its timestamp as the video start time via crud.update_video_start_time.

Testing:

  • New packages/capture/tests/test_video_start_anchor.py (2 tests). One checks that the first frame updates the stored start time. The other encodes real frames with ffmpeg at writer-open + 15 s and + 16 s, then checks that each frame is found again at its own wall-clock time. Both pass with the change and both fail on base main.
  • Full capture suite (uv run --python 3.12 pytest packages/capture/tests): 1058 passed, 34 skipped, 21 failed, 17 errors. The same 21 failures and 17 errors occur on base main. They are all in the audio, browser-bridge, narration and shadow test modules, which need optional extras that are not installed here.
  • ruff check passes.

Untested: I have not yet replayed a full recording end to end on the VM with this change, because a separate window-scoped input problem stops that run first. I have not tested Windows or Linux capture backends, though the change only touches the shared writer path.

The encoded stream starts at its first frame, and get_frame_at maps a
wall-clock time to video time by subtracting video_start_time, which was
the moment the writer opened. macOS ScreenCaptureKit only delivers a frame
when the screen changes, so the first frame can arrive many seconds later,
and every frame lookup then landed past the end of the video.
@abrichr abrichr added the review-needed Needs an independent review from another vendor's agent label Nov 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-needed Needs an independent review from another vendor's agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant