Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Videocapture suddenly blocks on reading a frame from IP camera

I'm using OpenCV 3. Grabbing a frame using VideoCapture with an IP Camera is blocking if the camera goes disconnected from the network or there is an issue with a frame. I first check if videoCapture.isOpened(). If it is, I tried these methods but nothing seems to work:

1) grabber >> frame

if(grabber.isOpened()) {
    grabber >> frame; 
    // DO SOMETHING WITH FRAME
}

2) read

if(grabber.isOpened()) {
    if(!grabber.grab()){
      cout << "failed to grab from camera" << endl;
    } else {
      if (grabber.retrieve(frame,0) ){
        // DO SOMETHING WITH FRAME
      } else {
        // SHOW ERROR
      }
    }
}

3) grab/retrieve

if(grabber.isOpened()) {
    if ( !grabber.read(frame) ) {
      cout << "Unable to retrieve frame from video stream." << endl;
    }
    else {
     // DO SOMETHING WITH FRAME
    } 
}

The video stream gets stuck at some point grabbing a frame with all of the previous options, each one blocks but doesn't exit or returns any error.

Do you know if there is a way to handle or solve this? Maybe some validations, try/catch or timer?