You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reading from webcam hangs unreplicably on Linux #227
That seems to work as expected with one exception: In about 20% of the cases, the code hangs while fetching the next frame. I see that when I explicitly read frames using reader.get_next_frame() and also in the traceback I see when I press Ctrl-C after a minute or two:
File "isolate.py", line 4, in <module>
for i, frame in zip([1, 2], reader):
File "/home/ingo/code/orquestra/.venv3/lib/python3.5/site-packages/imageio/core/format.py", line 386, in iter_data
im, meta = self._get_data(i)
File "/home/ingo/code/orquestra/.venv3/lib/python3.5/site-packages/imageio/plugins/ffmpeg.py", line 340, in _get_data
result = self._read_frame()
File "/home/ingo/code/orquestra/.venv3/lib/python3.5/site-packages/imageio/plugins/ffmpeg.py", line 543, in _read_frame
s = self._read_frame_data()
File "/home/ingo/code/orquestra/.venv3/lib/python3.5/site-packages/imageio/plugins/ffmpeg.py", line 519, in _read_frame_data
s = self._frame_catcher.get_frame()
File "/home/ingo/code/orquestra/.venv3/lib/python3.5/site-packages/imageio/plugins/ffmpeg.py", line 774, in get_frame
time.sleep(0.001)
KeyboardInterrupt
Is this a bug or am I missing something important?
Do you mean that the problem shows up reliably, or that the problem is not present on OS X? :)
Its likely that imageio is using your system ffmpeg. You could try setting the environment variable IMAGEIO_FFMPEG_EXE to another (newer?) version of ffmpeg to try if that helps.
Hi @almarklein, I just checked your suggestion to set the IMAGEIO_FFMPEG_EXE variable to point to ffmpeg 3.2.4 that I compiled from source. That doesn't seem to solve the problem.
Mmm, I tried reproducing this on 2 Linux VM's (Ubuntu 16.04 and Ubuntu Pingulin), and I cannot reproduce the error. Could it be that the webcam is busy, e.g. because its used by another application? Also, does it hang before even reading a frame, or after reading a few frames?
Strange. The webcam is not used by another process. After occasionally running into it, I made multiple attempts to call the script and in the beginning it usually happened after calling the script multiple times. When I tried setting IMAGEIO_FFMPEG_EXE, I found that it often hung on the first call. But that hasn't been like that before and it isn't reliably the case. So it might be that the previous call to imageio does not do proper cleanup. I can't see anything in the code that would suggest that, though. After all, it seems as if this would mostly be handled by ffmpeg anyway, right?
Imageio should shut down ffmpeg when its down. Though that bit of code has changed a few times. Maybe it does not work reliably in your case. Also, if the Python process is killed, imageio does not get a chance to kill the ffmpeg process.
Do you know what process is using the webcam? If its not ffmpeg, then the above does not apply.
I'm not quite sure if what I understood you right. At any time there is only a single ffmpeg process that seems to try to read from the webcam. As to be expected, that process changes every time I rerun the above script, but it is never more than one process. Is there another way to track who is attempting to access the webcam?
Is there another way to track who is attempting to access the webcam?
Not that I know of.
You could try to wait a little after stopping the script, and see if the ffmpeg exe is indeed stopped. If it is not stopped, there is a problem. If the ffmpeg process does stop, and by waiting a bit the problem never occurs, perhaps the ffmpeg process needs more time to stop or something...
Activity
igordertigor commentedon Feb 24, 2017
Notably, this seems to work reliably on Mac.
almarklein commentedon Feb 24, 2017
Do you mean that the problem shows up reliably, or that the problem is not present on OS X? :)
Its likely that imageio is using your system ffmpeg. You could try setting the environment variable
IMAGEIO_FFMPEG_EXEto another (newer?) version of ffmpeg to try if that helps.igordertigor commentedon Feb 27, 2017
Oh, I meant that the problem is not present on OS X. I'll try how things are with the system ffmpeg.
igordertigor commentedon Feb 27, 2017
Hi @almarklein, I just checked your suggestion to set the
IMAGEIO_FFMPEG_EXEvariable to point to ffmpeg 3.2.4 that I compiled from source. That doesn't seem to solve the problem.almarklein commentedon Mar 1, 2017
Mmm, I tried reproducing this on 2 Linux VM's (Ubuntu 16.04 and Ubuntu Pingulin), and I cannot reproduce the error. Could it be that the webcam is busy, e.g. because its used by another application? Also, does it hang before even reading a frame, or after reading a few frames?
[-]Reading from webcam hangs unreplicably[/-][+]Reading from webcam hangs unreplicably on Linux[/+]igordertigor commentedon Mar 3, 2017
Strange. The webcam is not used by another process. After occasionally running into it, I made multiple attempts to call the script and in the beginning it usually happened after calling the script multiple times. When I tried setting
IMAGEIO_FFMPEG_EXE, I found that it often hung on the first call. But that hasn't been like that before and it isn't reliably the case. So it might be that the previous call toimageiodoes not do proper cleanup. I can't see anything in the code that would suggest that, though. After all, it seems as if this would mostly be handled byffmpeganyway, right?almarklein commentedon Mar 3, 2017
Imageio should shut down ffmpeg when its down. Though that bit of code has changed a few times. Maybe it does not work reliably in your case. Also, if the Python process is killed, imageio does not get a chance to kill the ffmpeg process.
Do you know what process is using the webcam? If its not ffmpeg, then the above does not apply.
igordertigor commentedon Mar 10, 2017
I'm not quite sure if what I understood you right. At any time there is only a single ffmpeg process that seems to try to read from the webcam. As to be expected, that process changes every time I rerun the above script, but it is never more than one process. Is there another way to track who is attempting to access the webcam?
almarklein commentedon Mar 10, 2017
Not that I know of.
You could try to wait a little after stopping the script, and see if the ffmpeg exe is indeed stopped. If it is not stopped, there is a problem. If the ffmpeg process does stop, and by waiting a bit the problem never occurs, perhaps the ffmpeg process needs more time to stop or something...
almarklein commentedon Feb 5, 2019
Termination of the ffmpeg subprocess should be a lot better with #425. I am going to assume that it will fix this error. If not, please reopen!