Frame::second_to_frame truncates f32 product, causing periodic off-by-one frames
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
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
30fps:frame.second_to_frame(frame.frame_to_second(63))returns62(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(expected63),4.2→125(expected126),8.4→251(expected252).
- At
60fps:2.1→125(expected126), 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dmtrKovalenko/fframes
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
dmtrKovalenko/fframes#280 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
dmtrKovalenko/fframes#277 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
dmtrKovalenko/fframes#273 · 4 comments ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
dmtrKovalenko/fframes#260 · 1 comment ·
Maintainers usually reply within 1 day
-
Would SRT caption import be worth a PR?Possibly taken @silouanwright claimed this 29 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
dmtrKovalenko/fframes#258 · 1 comment ·
Maintainers usually reply within 1 day
All issues in dmtrKovalenko/fframes
Similar issues
-
Update Wasmtime to 48.0.11 for RUSTSEC-2026-0648Possibly taken @flyingrobots claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
flyingrobots/edict#457 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
O-windows relnotes relnotes-needs-review relnotes-tracking-issue T-libs
Difficulty 1/5 Under an hour Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
approved
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
fritzprix/libr-agent#3266 ·
Maintainers usually reply within 1 day
-
marketing
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
Maintainers usually reply within 1 day