The problem which I am facing is that the grab function of Videocapture object gets stuck when my IP cam is disconnected. Ideally, the grab() function or the isOpened() function should return false on IP cam failure after some timeout but instead function isOpened() returns true and grab() doesn't return anything (stuck at grabbing).
I am using python2.7 interpreter and I have tried this on ubuntu 14.04 and windows 10 with prebuilt opencv package, manually compiled opencv 2.4.13 and 3.1.0 with ffmpeg. Same result on all the versions.
I searched on different forums and dug into the source files to pinpoint the line, function and the file where the grab call is getting stuck. So the function CvCapture_FFMPEG::grabFrame() (sources/modules/highgui/src/cap_ffmpeg_impl.h) is stuck in while loop when IP camera is disconnected and somehow the timeout interrupt is not working in this case. I have checked this by adding log statements at different points in the CvCapture_FFMPEG::grabFrame() function.
So is this the problem with ffmpeg libraries or the CvCapture_FFMPEG::grabFrame() function or am I missing something?
Note: This problem does not occur when I compile OpenCV with gstreamer (either 0.10 or 1.0). There grab() function returns false on IP camera disconnect. I have tested this on opencv 2 and 3 on ubuntu 14.04 and windows 10.