Skip to content

fix: use wall-clock timing for SVG and ffmpeg framerate#6

Open
xav-ie wants to merge 2 commits intoagentstation:mainfrom
xav-ie:fix/svg-wall-clock-timing
Open

fix: use wall-clock timing for SVG and ffmpeg framerate#6
xav-ie wants to merge 2 commits intoagentstation:mainfrom
xav-ie:fix/svg-wall-clock-timing

Conversation

@xav-ie
Copy link

@xav-ie xav-ie commented Feb 26, 2026

Summary

  • Capture wall-clock timestamps during recording so SVG animation duration matches real elapsed time, even when CanvasToImage runs slower than the target framerate
  • Derive the actual capture rate (totalFrames / wallDuration) and pass it to ffmpeg as the input framerate so MP4 duration matches too

Context

When CanvasToImage is slower than the target frame interval, fewer frames are captured than framerate × duration predicts. Previously the SVG used frame-index-based timing, causing animations to play back too fast. This fix uses real wall-clock timestamps instead.

Test plan

  • Existing tests pass (go test ./...)
  • Added TestSVGGenerator_SlowCaptureTimestamp to verify non-uniform timestamps produce correct animation timing
  • Each commit compiles individually (bisectable)

Replace time.After with time.Ticker and track actual elapsed time
so SVG animation duration and keyframe percentages reflect real
wall-clock time. When CanvasToImage is slower than the target frame
interval, frames are captured at a lower rate but timestamps remain
accurate, preventing compressed playback in the SVG output.
Derive the real capture rate (totalFrames / wallDuration) and pass it
to ffmpeg as the input framerate. This ensures MP4 video duration
matches the wall-clock recording time when CanvasToImage runs slower
than the target framerate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant