OpenCV - how to capture rtsp video stream

47,197

The following code works for me without any problem. If you have a username and password for the stream, do not forget to include it in the url address.

cv::VideoCapture capture(url);

if (!capture->isOpened()) {
    //Error
}

cv::namedWindow("TEST", CV_WINDOW_AUTOSIZE);

cv::Mat frame;

while(m_enable) {
    if (!capture->read(frame)) {
        //Error
    }
    cv::imshow("TEST", frame);

    cv::waitKey(30);
}
Share:
47,197
Niedved
Author by

Niedved

Updated on July 09, 2022

Comments

  • Niedved
    Niedved almost 2 years

    for example we have working rtsp stream test like: "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov" (it works in moment of publishing this post)

    Now I want to catch this video stream in openCV (opencv 2.4.7 / 2.4.8) I've my code works perfectly on local movie files but when I try to capture rtsp I get msgs like: "Couldn't read movie file rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"

    I've tried few different ways like:

    CvCapture *camera = cvCreateFileCapture("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"); 
    if (camera == NULL) {
     printf("video is null, aborting...");
     return -1;
    }
    else{ 
     printf("video ok");
    }
    

    or:

    cv::VideoCapture vcap;
    //open the video stream and make sure it's opened
    if(!vcap.open("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov")) {
        std::cout << "Error opening video stream or file" << std::endl;
        return -1;
    }
    

    Any idea ?

    --

    Niedved

  • Shridutt Kothari
    Shridutt Kothari over 9 years
    I have added this code to VideoCapture and exposed the api but this is not working
  • Murat Şeker
    Murat Şeker over 9 years
    Did you put the ffmpeg dll into the same folder with your executable ?
  • Shridutt Kothari
    Shridutt Kothari over 9 years
    where to get that? and where to put it? i an trying on android. In my log-cat i am getting following error-CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library 01-05 15:25:06.185: E/OpenCV::camera(18562): Native_camera returned opening error: 4
  • Murat Şeker
    Murat Şeker over 9 years
    Sorry, i have no idea about Android