Non-integer frame rates (29.97fps = 30000/1001) cause cumulative rounding errors. Follow these rules to avoid drift.
For float-to-frame conversion:
int(9000 * 29.97)— wrong, truncates and loses framesround(9000 * 29.97)— correct, gets the right answer
Convert frames → total milliseconds via:
total_ms = round(frames * fps_den * 1000 / fps_num)Then decompose with integer division. Avoid intermediate floats that drift over long durations.
In roundtrip tests at non-integer FPS, exact equality is mathematically impossible. Accept ±1 frame tolerance.