OpenCV VideoCapture() capture freezes when GStreamer is enabled

I uses the following sample code to capture RTP stream from IP camera. But it freezes.
string gstStr = “rtspsrc location=rtsp://192.168.50.253:8554/test latency=200 ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! appsink”;

VidecoCapture capture(gstStr, CAP_GSTREAMER);
Mat captureFrame;
capture.read(captureFrame);

Hi,
Please check if you can launch the pipeline:

gst-launch-1.0 rtspsrc location=rtsp://192.168.50.253:8554/test latency=200 ! rtph264depay ! nvv4l2decoder ! nvoverlaysink

If yes, please try the python sample:

import sys
import cv2

def read_cam():
    cap = cv2.VideoCapture("rtspsrc location=rtsp://192.168.50.253:8554/test latency=200 ! rtph264depay ! nvv4l2decoder ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink ")
    if cap.isOpened():
        cv2.namedWindow("demo", cv2.WINDOW_AUTOSIZE)
        while True:
            ret_val, img = cap.read();
            cv2.imshow('demo',img)
            cv2.waitKey(10)
    else:
     print "rtsp open failed"

    cv2.destroyAllWindows()


if __name__ == '__main__':
    read_cam()

Thanks for your reply! I can launch the following pipeline on NX.
gst-launch-1.0 rtspsrc location=rtsp://192.168.50.253:8554/test latency=200 ! rtph264depay ! nvv4l2decoder ! nvoverlaysink

I have replaced GStreamer command according your suggestion and doing overnight testing to see if capture frame freezing issue is solved .

VideoCapture still freezes with the following command.
"rtspsrc location=rtsp://192.168.50.253:8554/test latency=200 ! rtph264depay ! nvv4l2decoder ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink "

Hi,
We launch a RTSP server:

$ ./test-launch "videotestsrc pattern=18 ! video/x-raw,width=1280,height=720 ! nvvidconv ! nvv4l2h264enc ! h264parse ! rtph264pay name=pay0 pt=96"

And don’t hit video freeze in running the python sample. Probably the issue is because your RTSP source is not stable?

OpenCV VideoCapture without GStreamer enabled doesn’t have freezing issue.
VidecoCapture capture(“rtsp://192.168.50.253:8554/test”);
Mat captureFrame;
capture.read(captureFrame);

Hi,
We would suggest use gstreamer pipeline to enable hardware decoding.

If software decoder is good enough in your usecase, you may try: