Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scenedetect/frame_timecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _seconds_to_frames(self, seconds):
Integer number of frames the passed number of seconds represents using
the current FrameTimecode's framerate property.
"""
return int(seconds * self.framerate)
return round(seconds * self.framerate)


def _parse_timecode_number(self, timecode):
Expand Down Expand Up @@ -304,7 +304,7 @@ def _parse_timecode_string(self, timecode_string):
if not (hrs >= 0 and mins >= 0 and secs >= 0 and mins < 60 and secs < 60):
raise ValueError('Invalid timecode range (values outside allowed range).')
secs += (((hrs * 60.0) + mins) * 60.0)
return int(secs * self.framerate)
return self._seconds_to_frames(secs)


def __iadd__(self, other):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_frame_timecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,11 @@ def test_subtraction():

with pytest.raises(TypeError): FrameTimecode('00:00:02.000', fps=20.0) == x - 10

@pytest.mark.parametrize("frame_num,fps", [(1, 1), (61, 14), (29, 25), (126, 24000/1001)])
def test_identity(frame_num, fps):
''' Test FrameTimecode values, when used in init return the same values '''
frame_time_code = FrameTimecode(frame_num, fps=fps)
assert FrameTimecode(frame_time_code) == frame_time_code
assert FrameTimecode(frame_time_code.get_frames(), fps=fps) == frame_time_code
assert FrameTimecode(frame_time_code.get_seconds(), fps=fps) == frame_time_code
assert FrameTimecode(frame_time_code.get_timecode(), fps=fps) == frame_time_code