Repository navigation
Description
Follow-up to #69, which documented that CapCut snaps every duration to the project's frame grid the first time it opens a draft. The docs now end with the formula a caller needs:
frame = 1_000_000 / fps
quantised = Math.round(us / frame) * frame
Every caller who wants what they write to equal what the app stores has to copy that out of the docs and hand-roll it. It should be a helper.
Scope
A small exported helper, plus tests:
quantizeToFrame(us, fps)returns the nearest on-grid microsecond value. Round to nearest, not truncate, because CapCut rounds to nearest and truncating drifts a frame short over a long timeline.framesFor(us, fps)returns the frame count a duration lands on. This is what makes the 866000 vs 867000 case from docs: note CapCut's frame quantisation of durations on first open #69 explainable to a caller: both return 26.- Resolve fps from the draft where a draft is in hand, falling back to 30.
src/interchange.tsaround line 383 already does exactly this, so follow that pattern rather than inventing a second one.
Out of scope
Do not change what any existing command writes. This adds a helper callers can opt into; it does not start quantising timeranges behind their back. Wiring it into lint as an off-grid check is a reasonable stretch if it stays small, but it is not required and it can be a separate issue.
Acceptance criteria
- The five rows in the docs: note CapCut's frame quantisation of durations on first open #69 table round-trip: 2767000 → 2766666 or 2766667, 3133000 → 3133334 or 3133333, 334000 → 333333, and both 866000 and 867000 → 866667, at 30 fps. Assert the frame count rather than the exact microsecond where the two differ by rounding direction.
- 866000 and 867000 both give 26 from
framesFor. - Sub-frame durations survive rather than collapsing to zero. A 33 ms segment at 30 fps stays one frame, matching the finding in docs: note CapCut's frame quantisation of durations on first open #69.
- Non-integer frame rates behave: 29.97 and 23.976 do not produce NaN or negative values.
- fps of 0, negative, missing or non-numeric falls back to 30 instead of dividing by zero.
- A test file under
test/, driven the wayCONTRIBUTING.mddescribes.
Notes
The measured behaviour and the sample table are in docs/draft-schema/01-tracks-and-segments.md under "Durations are quantised to the frame grid on first open". Worth linking the helper from that section once it exists.
Activity
floze-the-genius commentedon Aug 10, 2026
I’d like to take this. I’ll keep it opt-in: add the two exported frame-grid helpers with the documented 30 fps fallback, cover the #69 rows plus invalid/non-integer fps and sub-frame behavior in a focused test file, and link the helper from the existing schema section and Unreleased changelog. I won’t change what any current command writes.
renezander030 commentedon Aug 10, 2026
Hi Floze, thanks for restating the scope so precisely, including the out-of-scope part. It's yours, assigning you now.
A few pointers so the review stays short:
src/time.tsis the home for both helpers. It already holds the other microsecond conversions.src/lib.tsso callers can actually reach them. That file is the public library surface (dist/lib.js).dist/lib.jsthe waytest/lib.test.mjsdoes, rather than thespawnCli+tmpDraftpattern in CONTRIBUTING. These are pure functions, so the CLI harness would only get in the way.draftToOtioinsrc/interchange.ts:typeof draft.fps === "number" && draft.fps > 0 ? draft.fps : 30. That already covers the 0, negative, missing and non-numeric cases in the acceptance criteria.Pre-commit runs
npm testand Biome, so keep it green. Changelog under## [Unreleased].feat(time): add frame-grid helpers (#81)