Repository navigation
[timecode] Truncate instead of rounding up in get_timecode(use_rounding=False) - #602
Closed
rishi02102017 wants to merge 1 commit into
Closed
rishi02102017 wants to merge 1 commit into
rishi02102017 wants to merge 1 commit into
Conversation
…ng=False) get_timecode() truncated by formatting the seconds with one extra digit and dropping it, but formatting rounds that extra digit, which can carry into the digits that are kept. With use_rounding=False, 0.4996 seconds at precision 2 gave 00:00:00.50, and 1.99997 seconds gave 00:00:01.000 (the carry was lost once it reached the whole seconds). Truncate the value to the requested precision before splitting it into hours, minutes and seconds instead, allowing for float error so exact frame times such as 504 frames at 23.976 fps (21.021 seconds) are not truncated down.
MuhammadBilalKhan267
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for catching this! #591 already fixes the same truncation bug in Timecode, and we’re planning to remove FrameTimecode in 0.8.
Contributor
Author
|
Ah, makes sense, thanks. Since #591 is still a draft, would it be worth having this in 0.7.x until 0.8 is out? If not, I'm happy to close it. |
Collaborator
|
Unfortunately, the next planned release is 0.8. Feel free to pick up any other issues though. |
Contributor
Author
|
Got it, closing this then. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FrameTimecode.get_timecode()is documented to truncate to the requested precision whenuse_rounding=False. It currently formats the seconds with one extra digit and then drops it, but formatting rounds that digit, which can carry into the digits that are kept:When the carry reaches the whole seconds it is lost, so the result can be almost a second early. This reproduces on 0.7.3 and on main.
This change truncates the value to the requested precision before it is split into hours, minutes and seconds, allowing for float error so exact frame times are not truncated down (for example, 504 frames at 23.976 fps is exactly 21.021 seconds and still prints
00:00:21.021). Output withuse_rounding=Trueis unchanged.test_precision_truncationtotests/test_timecode.py; it fails on main and passes with this change.pytest,ruff checkandruff format --checkpass.