forked from bantonj/PyTimeCode
-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Description
The folloing code
from timecode import Timecode
seconds = 0
for _ in range(12):
seconds += 0.04
print(Timecode(framerate=25, start_seconds=seconds).frames)
prints
1
2
3
4
5
6
7
8
9
10
10
11
This is because of the float_to_tc method:
def float_to_tc(self, seconds):
"""set the frames by using the given seconds
"""
return int(seconds * self._int_framerate)
If the float is not exactly represented, the result may not be accurate.
In the example :
int(0.43999999999999995*25)=int(10.999999999999998)=10
It would be safer to round the result before casting to integer:
def float_to_tc(self, seconds):
"""set the frames by using the given seconds
"""
return int(round(seconds * self._int_framerate))
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels