Skip to content

FrameTimeCode should be identic to itself when applying the resulting values to create a new FrameTimeCode #268

@Wirg

Description

@Wirg

Hi !

Thank you for PySceneDetect.

I ran into issues where after some serialization the resulting time frame was not the expected one.
For example:

frame_time_code = FrameTimecode(61, fps=14)
seconds = frame_time_code.get_seconds()
time_code = frame_time_code.get_timecode()

...

FrameTimecode(seconds, fps=14).get_frames() == 60 # not 61
FrameTimecode(time_code, fps=14).get_frames() == 60 # not 61

I found the corresponding code with flooring (with int instead of round) :

def _seconds_to_frames(self, seconds):
# type: (float) -> int
""" Converts the passed value seconds to the nearest number of frames using
the current FrameTimecode object's FPS (self.framerate).
Returns:
Integer number of frames the passed number of seconds represents using
the current FrameTimecode's framerate property.
"""
return int(seconds * self.framerate)

return int(secs * self.framerate)

I ran into the following code which seems to indicate this is on purpose. What is the reason?

assert FrameTimecode(timecode='00:00:01', fps=1).frame_num == 1
assert FrameTimecode(timecode='00:00:01.9999', fps=1).frame_num == 1
assert FrameTimecode(timecode='00:00:02.0000', fps=1).frame_num == 2

Have a nice day !

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions