Repository navigation
[timecode] Truncate instead of rounding up in get_timecode(use_rounding=False) - #602
rishi02102017 wants to merge 1 commit into
Conversation
MuhammadBilalKhan267
left a comment
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.
|
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. |
|
Unfortunately, the next planned release is 0.8. Feel free to pick up any other issues though. |
|
Got it, closing this then. Thanks! |
Can you file a bug for this so it's documented for posterity? For correctness issues like this I don't mind making another .7x release if needed... I don't think anything in main is a breaking change yet so 0.7.4 is still an option if needed. Either way, while FrameTimecode exists on main, this should be fixed, so we can and should at least land this now (even if it will be superceded by #591). |
Breakthrough
left a comment
There was a problem hiding this comment.
We can merge this once the conflicts are resolved, thanks for the PR.
…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.
eb1a449 to
abcecb1
Compare
|
Thanks for taking another look. I filed the bug as #611 and rebased onto main. The only conflict was the changelog, so it should be ready to merge now. |
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.