Skip to content

TypeError: Timecode.frames in mtc_decode #6

Open
@Tomasz-Mankowski

Description

@Tomasz-Mankowski

Environment:

  • Windows 10
  • python 3.9.10
  • mido 1.2.10
  • python-rtmidi 1.4.9
  • timecode 1.3.1

Input: 24 fps quarter frame

While running mtc_listener.py call of mtc_decode rises error:

  File "***\timecode_tools\mtc_listener.py", line 46, in <module>
    main()
  File "***\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "***\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "***\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "***\AppData\Local\Programs\Python\Python39\lib\site-packages\click\core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "***\timecode_tools\mtc_listener.py", line 43, in main
    listen(port)
  File "***\timecode_tools\mtc_listener.py", line 33, in listen
    handle_message(msg)
  File "***\timecode_tools\mtc_listener.py", line 15, in handle_message
    tc = tools.mtc_decode_quarter_frames(quarter_frames)
  File "***\timecode_tools\tools.py", line 208, in mtc_decode_quarter_frames
    return mtc_decode(mtc_bytes)
  File ***\timecode_tools\tools.py", line 158, in mtc_decode
    return Timecode(fps, frames=total_frames)
  File "***\Local\Programs\Python\Python39\lib\site-packages\timecode\__init__.py", line 80, in __init__
    self.frames = frames
  File "***\AppData\Local\Programs\Python\Python39\lib\site-packages\timecode\__init__.py", line 105, in frames
    raise TypeError(
TypeError: Timecode.frames should be a positive integer bigger than zero, not a float

Indeed total_frames is a float value, and frames value is forced to be int:

    @frames.setter
    def frames(self, frames):
        """setter for the _frames attribute

        :param int frames: A positive int bigger than zero showing the number
          of frames that this TimeCode represents.
        :return:
        """
        # validate the frames value
        if not isinstance(frames, int):
            raise TypeError(
                "%s.frames should be a positive integer bigger "
                "than zero, not a %s" % (self.__class__.__name__, frames.__class__.__name__)
            )

Changing return Timecode(fps, frames=total_frames) to return Timecode(fps, frames=int(total_frames)) fixes this issue.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions