PyAV
PyAV copied to clipboard
OverflowError when adding stream with float framerate
When adding a stream with a floating point framerate, as follows:
import av
output = av.open('test.avi', 'w')
output.add_stream('rawvideo', rate=30.000001)
I receive the following error message:
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
av/container/output.pyx in av.container.output.OutputContainer.add_stream (src\av\container\output.c:2656)()
av/container/output.pyx in av.container.output.OutputContainer.add_stream (src\av\container\output.c:2322)()
OverflowError: Python int too large to convert to C long
My av version is 0.3.3, on Win64, Python 3.5.2. My guess is that it gets converted to a fraction, which contains an integer that is too large for a Clong. Is there a possibility to get around this?
30.000001 is interpreted as 30.000001000000001 in Fraction. This error does not occur when the argument is passed as a string.
>>> from fractions import Fraction
>>> Fraction(30.000001)
Fraction(8444249582794657, 281474976710656)
>>> Fraction('30.000001')
Fraction(30000001, 1000000)
output.add_stream('rawvideo', rate='30.000001')
@vbkaisetsu thanks, the following solved this for me. I limit the rate to 4 decimals, as I noted that MPEG-4 only allows a timebase of max 66535.
import av
output = av.open('test.avi', 'w')
output.add_stream('rawvideo', rate='{0:.4f}'.format(30.000001))
In that case, I think you can also use limit_denominator:
stream = output.add_stream(codec, rate=Fraction(export_rate).limit_denominator(65535))
Ok thanks, that works too indeed
Does anyone know if there is a way to detect what the maximum denominator is for a codec except for hard-coding one?
We could bypass the overflow error by limiting to 2**32-1, or (I'm leaning towards) throwing an error of our own that is more descriptive.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Let's keep this alive.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.