OpenCV with Gstreamer blocked on read when server rtsp disconnect

Andressio www.andreabertolaso at gmail.com
Tue Sep 25 15:22:25 UTC 2018


Dear all
I'm tring to build an application with Gstreamer (v.1.14.2) and VideoCapture
from OpenCV (v.3.4.3). My goal is to obtain a 4k stream from an IP camera
via rtsp protocol.
This is the code:

int main(int argc, char *argv[])
{
    static std::string pipe = "rtspsrc
location=rtsp://192.168.0.3:8554/axis-media/media.amp
protocols=GST_RTSP_LOWER_TRANS_TCP timeout=5000000 ! rtph264depay ! queue !
avdec_h264 ! videoconvert ! appsink";
    cv::VideoCapture *p_video_capture = nullptr;

    while(true)
    {
        if (!p_video_capture || !p_video_capture->isOpened()) 
        {
            p_video_capture = new cv::VideoCapture(pipe, CV_CAP_GSTREAMER);

            if (p_video_capture->isOpened())
                std::cout << "VideoCapture open" << std::endl;
        }
        else
        {
            cv::Mat img;
            bool res = p_video_capture->read(img);

            if (!res)
            {
                delete p_video_capture;
                p_video_capture = nullptr;
                return 0;
            }
        }
    }
    
    delete p_video_capture;
    return 0;
}

Everthing is fine util I disconnect the camera by unplugging the cable. Two
scenarios might happen:
1) VideoCapture detects the disconnection and the read() function return
false (desired behaviour);
2) VideoCapture gets stucked in the read() function (undesired behaviour).

This seems to be a non-deterministic behaviour. In the second case I was
able to print some warning messages by setting the environment variable
GST_DEBUG to 5. The system keeps printing the same set of messages in the
attachments.
For every itaration an incremental number is assignet to each element of the
pipilene (e.g. rtspsrc66 in the attached file).

After 1 hour and 39 minutes I got the 294 useless iteration.
I cannot say if this is a problem of opencv or gstremer. Have you any
suggestions?

Regards
Andressio

error_log.txt
<http://gstreamer-devel.966125.n4.nabble.com/file/t378552/error_log.txt>  



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/


More information about the gstreamer-devel mailing list