Cant open gstreamer pipeline in cv2

Im trying to access rtsp stream using cv2 and gstreamer pipeline in python.
I tried running the gst-launch in terminal and it worked perfectly, but when I try to use gstreamer in cv2, it won’t open the pipeline.

gst-launch command I used gst-launch-1.0 rtspsrc location=rtsp://192.168.42.120:554/snl/live/1/1 latency=0 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! autovideosink

My python code

I was only able to open cv2 and get frames using cv2.VideoCapture("rtsp_uri"), any other parameters to VideoCapture() (ie: cv2.CAP_GSTREAMER) will have cam.isOpened() to return False

You would try:

video_src = 'rtspsrc location=rtsp://192.168.42.120:554/snl/live/1/1 latency=0 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1'
cam = cv2.VideoCapture(video_src, cv2.CAP_GSTREAMER) 

The problem turns out to be not having gstreamer plugin installed for opencv when I use pip3 install opencv-python.
After building cv from source (OpenCV: Install OpenCV-Python in Ubuntu), I was able to open the pipeline and get super low latency stream with

video_src = "rtspsrc location=rtsp://192.168.42.120:554/snl/live/1/1 latency=0 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! appsink"
cam = cv2.VideoCapture(video_src, cv2.CAP_GSTREAMER)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.