Unable to capture 2 recorded video streams simultaneously

asked 2020-02-25 00:58:48 -0600

deen gravatar image

updated 2020-02-25 04:22:20 -0600

supra56 gravatar image

I am able to capture (using cv::VideoCapture) 2 live video streams (or 1 live stream & 1 recorded stream) simultaneously using OpenCV C++ in Visual Studio.

But, I am unable to capture more than 1 recorded streams simultaneously.

My code is:

   #include <iostream>
`#include "opencv2/core/core.hpp"`<br/>
`#include "opencv2/highgui/highgui.hpp"`<br/>
`#include "opencv2/imgproc.hpp"`<br/>
`#include "opencv2/opencv.hpp"`<br/>
`#include "opencv2/videoio.hpp"`<br/>

`using namespace std;`

`using namespace cv;`

`const string camera1_main_streamURL = "rtsp://(..........SOME URL............)";`<br/>
`const string camera2_main_streamURL = "rtsp://(..........SOME URL............)";`

`const string windowName1 = "Output Image";`<br/>
`const string windowName = "camera1 main streaming";`<br/>
`const string windowName2 = "camera2 main streaming";`<br/>


int main(int argc, const char * argv[])

{

    //create video capture object for camera1 and camera2

        cv::VideoCapture cam1_capture(camera1_main_streamURL, cv::CAP_FFMPEG);
        cv::VideoCapture cam2_capture(camera2_main_streamURL, cv::CAP_FFMPEG);

        if (!cam1_capture.isOpened())
    {
        //Error
        std::cout << "Input error 1\n";
        return -2;
    }

    if (!cam2_capture.isOpened())
    {
        //Error
        std::cout << "Input error 1\n";
        return -3;
    }

    while (true)
    {
        // initialise the window for camera1 and camera2 streaming
        cv::namedWindow("camera1 main streaming", WINDOW_AUTOSIZE);
        cv::namedWindow("camera2 main stream", WINDOW_AUTOSIZE);

        //grab and retrieve each frames of the camera1 and camera2  sequentially 
        cv::Mat3b frame1;
        cam1_capture >> frame1;

        cv::Mat3b frame2;
        cam2_capture >> frame2;

        if (!cam1_capture.read(frame1))
        {
            //Error
            std::cout << "Input error 2\n";
            return -1;
        }

        if (!cam2_capture.read(frame2))
        {
            //Error
            std::cout << "Input error 2\n";
            return -1;
        }

        //display  both the frame 
        cv::imshow("camera1 main streaming", frame1);
        cv::imshow("camera2 main stream", frame2);


        if (cv::waitKey(1) >= 0) break;
        cv::waitKey(30);
        //press any key from keyboard to stop and save the video
    }


    cam1_capture.release();
    cam2_capture.release();
    return 0;

}

Output:

[rtsp @ 000000ea2bf8fc40] method DESCRIBE failed: 453 Not Enough Bandwidth
Input error 1
edit retag flag offensive close merge delete

Comments

1

error message is off topic

LBerger gravatar imageLBerger ( 2020-02-25 02:26:38 -0600 )edit
1

capture.read() blocks, so if your 1st stream hangs (because of a network error, like above) your 2nd stream cannot read either.

berak gravatar imageberak ( 2020-02-25 05:24:07 -0600 )edit