Frame::second_to_frame truncates f32 product, causing periodic off-by-one frames

Open Beginner friendly
#296 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@ShamanicArts is already working on this.

Since Dec 5, 2026.

  • #297 by @ShamanicArts — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

Start in fframes/src/frame.rs at Frame::second_to_frame, then compare its conversion with the f64 and rounding approach already used in clip.rs and time_spec.rs. Add regression tests for round trips and the reported 30 and 60 fps examples; done means these conversions return the expected frame numbers without periodic off-by-one results.

Written by the indexing model from the issue text.

Description

Frame::second_to_frame in fframes/src/frame.rs multiplies in f32 and truncates with as usize:

pub fn frame_to_second(&self, frame: usize) -> f32 {
    frame as f32 / self.fps as f32
}

pub fn second_to_frame(&self, second: f32) -> usize {
    (second * self.fps as f32) as usize
}

Because of f32 rounding + truncating cast, second_to_frame is not even a round-trip inverse of frame_to_second / frame.seconds():

  • At 30 fps:
    • frame.second_to_frame(frame.frame_to_second(63)) returns 62 (62.999996 as usize) — 20 frames fail in the first 1,000 frames (63, 125, 126, 127, 250, ...).
    • Exact tenths also miss: 2.1 → 62 (expected 63), 4.2 → 125 (expected 126), 8.4 → 251 (expected 252).
  • At 60 fps: 2.1 → 125 (expected 126), with the same 20/1,000 round-trip failures.
  • When seeking into video plates with frame.second_to_frame(offset + frame.seconds()) (e.g. 2.0 + frame.seconds() at 30 fps), it truncates roughly every ~15 frames (62.999996, 94.999992, 109.999992, 125.999992, ...), duplicating a frame and immediately jumping two frames on the next tick. On smooth camera pans that shows up as periodic micro-stutter.

clip.rs and time_spec.rs already avoid this by converting in f64 and rounding:

pub fn second_to_frame(&self, second: f32) -> usize {
    (f64::from(second.max(0.0)) * self.fps as f64).round() as usize
}

Opening a PR with the fix and regression tests.

Dominant language
Rust
Stars
3.3k
Forks
118
Avg merge
1d 8h
Merged PRs (30d)
16

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dmtrKovalenko/fframes

All issues in dmtrKovalenko/fframes

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.