Skip to content

Correct frame_from_ms and ms_from_frame semantics - #12

Open
CoffeeFlux wants to merge 1 commit into
masterfrom
frame-conversion-docs
Open

CoffeeFlux wants to merge 1 commit into
masterfrom
frame-conversion-docs

Conversation

@CoffeeFlux

Copy link
Copy Markdown
Member

The Misc. APIs page describes aegisub.frame_from_ms and aegisub.ms_from_frame as exact frame-boundary conversions, but they don't work that way. In src/auto4_lua.cpp both call the video controller with agi::vfr::START, so:

  • frame_from_ms(ms) returns the first frame that begins at or after ms, which is the first frame a line starting at ms is shown on. A time in the middle of a frame rounds up, not down as the docs say.
  • ms_from_frame(frame) returns prev + (cur - prev + 1) / 2 (Framerate::TimeAtFrame in libaegisub/common/vfr.cpp), the midpoint between the previous frame's start and this frame's start. It is not the first millisecond inside the frame. At 23.976 fps, frame 24 begins at 1001 ms and ms_from_frame(24) returns 980.

This has been the case since at least the 2019 Aegisub/Aegisub master, so this updates both the latest and the 3.5 docs. It also adds a short paragraph explaining that these are subtitle times, and why the midpoint is useful (it survives centisecond rounding and round-trips with frame_from_ms).

I checked the claims against a Python port of FrameAtTime/TimeAtFrame:

  • Round-tripping and surviving centisecond rounding hold at 23.976, 25, 29.97, 50, 59.94, 60 and 100 fps, and for a mixed VFR timeline.
  • Centisecond rounding stops working above 100 fps, which the docs now mention.

The zh-cn translation and the old 3.0–3.2 pages aren't changed.

🤖 Generated with Claude Code

Both use Aegisub's START conversion: frame_from_ms rounds up to the first frame a line starting at that time is displayed on, and ms_from_frame returns the midpoint between the previous frame and the requested one, not the frame's beginning.

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

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
aegisite-nycd Ready Ready Preview Oct 25, 2026 10:35pm UTC

Request Review

@arch1t3cht

Copy link
Copy Markdown
Member

Thanks!

I find the "A time at which a line starting there is first displayed on frame" part a bit confusing. Maybe this is better:

The start time that a subtitle line should have if it is supposed to first become visible at the frame frame. This is also the end time that a subtitle line should have if it is supposed to first become invisible at the frame frame. If no frame rate data is loaded, returns nil.

The rest LGTM.

This branch was successfully deployed

1 active deployment
Preview — c961eb63 Deployed Oct 25, 2026 by vercel[bot]
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.

2 participants