Reputation: 404
I am trying to read the frames using imageio API. I have a reader as an object which I have received using imageio.get_reader(video_path,"ffmpeg")
nframes =int(reader.get_length())
for ii in range(nframes):
while frame_q.qsize() > 500: # so that we dont use huge amounts of memory
time.sleep(1)
cur_img = reader.get_next_data()
frame_q.put(cur_img)
#shape = cur_img.shape
#noisy_img = np.uint8(cur_img.astype(np.float) + np.random.randn(*shape) * 20)
#frame_q.put(noisy_img)
if ii % 100 == 0:
print("%i / %i frames in queue" % (ii, nframes))
print("All %i frames in queue" % (nframes))
Traceback:
Traceback (most recent call last):
File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "multiprocess_detect_actions.py", line 61, in read_frames
nframes =int(reader.get_length())
OverflowError: cannot convert float infinity to integer
Initially, the nframe
was a float value then I tried to convert it into an integer but then I am getting an OverflowError.I will appreciate your advice on this. Thank you.
Upvotes: 2
Views: 13461
Reputation: 404
According to the new 2019 update 2.5.0 version from imageio
:
"The reader of the ffmpeg
plugin now always reports inf
as the number of frames. Use reader.count_frames()
to get the actual number, or estimate it from the fps
and duration in the meta data."
imageio update
Upvotes: 4
Reputation: 472
In Python, float type can be infinity. To fixe your bug, you check if the value is inf
ou -inf
before convert to int:
def float_to_int(x):
if x == float('inf') or x == float('-inf'):
return float('nan') # or a large value you choose
return int(x)
As @ShadowRanger noted, this solution just prevent the OverflowError
error. You should investigate on the reader
to fix the problem of infinite float.
Upvotes: 1