Skip to content

fix: SG-42144: Fix off-by-one frame count error for audio-only files#1068

Merged
cedrik-fuoco-adsk merged 8 commits intoAcademySoftwareFoundation:mainfrom
skyhhh666:fix/audio-frame-rounding
Feb 24, 2026
Merged

fix: SG-42144: Fix off-by-one frame count error for audio-only files#1068
cedrik-fuoco-adsk merged 8 commits intoAcademySoftwareFoundation:mainfrom
skyhhh666:fix/audio-frame-rounding

Conversation

@skyhhh666
Copy link
Copy Markdown
Contributor

PR Description: Fix off-by-one frame count error for audio-only files

Summary

This PR fixes a bug where pure audio files (like .wav) could be misidentified as having one frame less than their actual duration. This was caused by floating-point truncation when converting the audio duration (in seconds) to a frame count.

The Issue

When OpenRV calculates the frame count for an audio file, it multiplies the duration reported by FFmpeg by the target FPS.
For example:

  • An audio file with 28,000 samples at 48kHz is exactly 14 frames at 24fps.
  • Because of microsecond precision in FFmpeg's duration reporting, the timeDuration might be 0.583333.
  • 0.583333 * 24 = 13.999992.
  • Assigning this to an integer frames variable resulted in 13 due to truncation.

The Fix

Changed the calculation to use std::round() on the result before assigning it to the integer frames variable. This ensures that tiny precision errors don't cause the loss of the final frame.

Affected File

  • src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp

Verification Results

  • Manual calculation: std::round(13.999992) now correctly yields 14.
  • This matches the behavior of other industry tools like Maya and Nuke.

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Jan 19, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: skyhhh666 / name: skyhhh666 (4fb310b)

@skyhhh666 skyhhh666 force-pushed the fix/audio-frame-rounding branch from 1d25d04 to 296c87c Compare January 19, 2026 15:52
@skyhhh666
Copy link
Copy Markdown
Contributor Author

Hi @bernie-laberge @eloisebrosseau @cedrik-fuoco-adsk , just a gentle ping. Could you please take a look when you have a chance? Thanks!

Copy link
Copy Markdown
Contributor

@bernie-laberge bernie-laberge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @skyhhh666 !

@bernie-laberge bernie-laberge added the community Contribution from the Open RV Community label Jan 22, 2026
@cedrik-fuoco-adsk cedrik-fuoco-adsk changed the title Fix off-by-one frame count error for audio-only files SG-42144: Fix off-by-one frame count error for audio-only files Feb 18, 2026
@cedrik-fuoco-adsk cedrik-fuoco-adsk changed the title SG-42144: Fix off-by-one frame count error for audio-only files fix: SG-42144: Fix off-by-one frame count error for audio-only files Feb 19, 2026
@cedrik-fuoco-adsk cedrik-fuoco-adsk merged commit c4e0e15 into AcademySoftwareFoundation:main Feb 24, 2026
19 checks passed
chenlj1 pushed a commit to chenlj1/OpenRV that referenced this pull request Mar 6, 2026
…cademySoftwareFoundation#1068)

# PR Description: Fix off-by-one frame count error for audio-only files

## Summary
This PR fixes a bug where pure audio files (like `.wav`) could be
misidentified as having one frame less than their actual duration. This
was caused by floating-point truncation when converting the audio
duration (in seconds) to a frame count.

## The Issue
When OpenRV calculates the frame count for an audio file, it multiplies
the duration reported by FFmpeg by the target FPS.
For example:
- An audio file with 28,000 samples at 48kHz is exactly 14 frames at
24fps.
- Because of microsecond precision in FFmpeg's duration reporting, the
`timeDuration` might be `0.583333`.
- `0.583333 * 24 = 13.999992`.
- Assigning this to an integer `frames` variable resulted in `13` due to
truncation.

## The Fix
Changed the calculation to use `std::round()` on the result before
assigning it to the integer `frames` variable. This ensures that tiny
precision errors don't cause the loss of the final frame.

## Affected File
- `src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp`

## Verification Results
- Manual calculation: `std::round(13.999992)` now correctly yields `14`.
- This matches the behavior of other industry tools like Maya and Nuke.

Signed-off-by: skythj <214037181@qq.com>
eloisebrosseau pushed a commit to eloisebrosseau/OpenRV that referenced this pull request Apr 1, 2026
…cademySoftwareFoundation#1068)

# PR Description: Fix off-by-one frame count error for audio-only files

## Summary
This PR fixes a bug where pure audio files (like `.wav`) could be
misidentified as having one frame less than their actual duration. This
was caused by floating-point truncation when converting the audio
duration (in seconds) to a frame count.

## The Issue
When OpenRV calculates the frame count for an audio file, it multiplies
the duration reported by FFmpeg by the target FPS.
For example:
- An audio file with 28,000 samples at 48kHz is exactly 14 frames at
24fps.
- Because of microsecond precision in FFmpeg's duration reporting, the
`timeDuration` might be `0.583333`.
- `0.583333 * 24 = 13.999992`.
- Assigning this to an integer `frames` variable resulted in `13` due to
truncation.

## The Fix
Changed the calculation to use `std::round()` on the result before
assigning it to the integer `frames` variable. This ensures that tiny
precision errors don't cause the loss of the final frame.

## Affected File
- `src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp`

## Verification Results
- Manual calculation: `std::round(13.999992)` now correctly yields `14`.
- This matches the behavior of other industry tools like Maya and Nuke.

Signed-off-by: skythj <214037181@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Contribution from the Open RV Community tracked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants