Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

strategy to resume RTSP stream

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