Videocapture grab function does not return (blocking call) when IP camera is disconnected.

asked 2016-11-13 09:49:27 -0600

aestaq gravatar image

updated 2016-12-19 13:24:06 -0600

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.

edit retag flag offensive close merge delete

Comments

Have you read this? May be you should use gstreamer

LBerger gravatar imageLBerger ( 2016-12-19 14:53:09 -0600 )edit

did you tried to open the capture with cv::CAP_GSTREAMER api preference ?

avilleret gravatar imageavilleret ( 2018-12-22 08:56:46 -0600 )edit

i think this is fixed already.

sturkmen gravatar imagesturkmen ( 2018-12-22 09:03:29 -0600 )edit