8000 [PyAV Plugin] Setting Float `fps` Causes `OverflowError` · Issue #1120 · imageio/imageio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[PyAV Plugin] Setting Float fps Causes OverflowError #1120
Open
@drcege

Description

@drcege

Description

Currently, the init_video_stream method in the PyAV plugin converts float fps to a Fraction. However, for some common fps numbers, this results in an OverflowError: value too large to convert to int.

Steps to Reproduce

The full code to reproduce the issue is as follows:

writer = iio.imopen("<bytes>", 'w', extension='.mp4', plugin='pyav')
writer.init_video_stream('h264', fps=29.97)
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
Cell In[36], line 1
----> 1 writer.init_video_stream('h264', fps=29.97)

File ~/miniconda3/envs/test/lib/python3.9/site-packages/imageio/plugins/pyav.py:886, in PyAVPlugin.init_video_stream(self, codec, fps, pixel_format, max_keyframe_interval, force_keyframes)
    850 """Initialize a new video stream.
    851 
    852 This function adds a new video stream to the ImageResource using the
   (...)
    882 
    883 """
    885 fps = Fraction.from_float(fps)
--> 886 stream = self._container.add_stream(codec, fps)
    887 stream.time_base = Fraction(1 / fps).limit_denominator(int(2**16 - 1))
    888 if pixel_format is not None:

File av/container/output.pyx:93, in av.container.output.OutputContainer.add_stream()

File av/utils.pyx:51, in av.utils.to_avrational()

OverflowError: value too large to convert to int

Cause

This issue arises because float number is converted to a Fraction with very large numerator and denominator. For example, Fraction.from_float(29.97) returns Fraction(1054475631502295, 35184372088832).

Impact

This is difficult for me to work around since I am trying to maintain the original fps of the input file, as in

fps = reader.metadata()["fps"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0