strategy to resume RTSP stream

asked 2015-04-24 11:17:27 -0500

dAAvid gravatar image

Hi,
I use Windows 7 and OpenCV 2.4.8. I can easily capture an RTSP/H.264 stream issued from an Axis encoder (or from a Videolan VLC stream).
But i cannot resume the capture once the stream was interrupted by an encoder restart (or by a VLC stream restart - with VLC closure), release works but open hangs and never returns.
This is the simple code i use :

cv::namedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
cv::moveWindow("mainWin", 100, 100);
string url = "rtsp://10.7.0.68:8554/test";
cv::VideoCapture capture(url.c_str()); // rtsp://127.0.0.1:8554/test
if (!capture.isOpened()) {
    exit(0);
}

int key = 0;
while (key != 'q') {

    cv::Mat frame;
    capture >> frame;

    if (!frame.empty()) {
        printf(".");
        cv::imshow("mainWin", frame);
        key = cvWaitKey(10);
    } else {
        printf("nok\n");
        capture.release();
        capture.open(url.c_str());
        Sleep(1000);
    }
}
capture.release();

dAAvid

edit retag flag offensive close merge delete

Comments

Anybody ever had that problem? Does it work on Linux? Tx for your answers

dAAvid gravatar imagedAAvid ( 2015-05-12 04:56:00 -0500 )edit