[PR #11435] Use more accurate rounding in GetFixedOutputSize #12897

Closed
opened 2026-02-07 07:03:42 +03:00 by OVERLORD · 0 comments
Owner

Original Pull Request: https://github.com/jellyfin/jellyfin/pull/11435

State: closed
Merged: Yes


Changes

The current method of rounding to an integer for calculating output size may suffer from accuracy loss, resulting in the output size not being exact. This used to be a non-issue until we introduced trickplay, which requires the generated images to have an exact width to make tiles.

For example, for a video with a width of 1432 pixels and a required output width of 480 pixels, the calculated scale * inputWidth will become 479.99999999999994, which is smaller than the requested 480. Our logic will then pick the smaller value, which is cast into an integer. The casting simply discards all decimal parts, making it 479. Then, in the next part of rounding, we round it to an even number, which makes it smaller and the produced width becomes 478.

This PR also forces the trickplay manager to generate images with even width because a lot of filters may have trouble sampling a frame with odd width.

Issues

Fixes #11409

**Original Pull Request:** https://github.com/jellyfin/jellyfin/pull/11435 **State:** closed **Merged:** Yes --- <!-- Ensure your title is short, descriptive, and in the imperative mood (Fix X, Change Y, instead of Fixed X, Changed Y). For a good inspiration of what to write in commit messages and PRs please review https://chris.beams.io/posts/git-commit/ and our documentation. --> **Changes** <!-- Describe your changes here in 1-5 sentences. --> The current method of rounding to an integer for calculating output size may suffer from accuracy loss, resulting in the output size not being exact. This used to be a non-issue until we introduced trickplay, which requires the generated images to have an exact width to make tiles. For example, for a video with a width of 1432 pixels and a required output width of 480 pixels, the calculated `scale * inputWidth` will become `479.99999999999994`, which is smaller than the requested `480`. Our logic will then pick the smaller value, which is cast into an integer. The casting simply discards all decimal parts, making it `479`. Then, in the next part of rounding, we round it to an even number, which makes it smaller and the produced width becomes `478`. This PR also forces the trickplay manager to generate images with even width because a lot of filters may have trouble sampling a frame with odd width. **Issues** <!-- Tag any issues that this PR solves here. ex. Fixes # --> Fixes #11409
OVERLORD added the pull-request label 2026-02-07 07:03:42 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/jellyfin#12897