Capturing a stream from raspberry via Gstreamer

I am trying to capture a vide stream coming from a rapberry zero. I can stream the video via gstreamer using below command on terminal.
gst-launch-1.0 -v v4l2src device=/dev/video0 num-buffers=-1 ! video/x-raw, width=640, height=480, framerate=30/1 ! videoconvert ! jpegenc ! rtpjpegpay ! udpsink host= port=5200
And I can capture the stream from nano using the terminal command.
gst-launch-1.0 -v udpsrc port=5200 ! application/x-rtp, media=video, clock-rate=90000, payload=96 ! rtpjpegdepay ! jpegdec ! videoconvert ! autovideosink

How can I integrate those commands into a python script so that I can process the stream with opencv. I want to use a python script both on the sender raspberry and on the receiving jetson.

Everything works fine on linux terminal but could not succeed to make it work on python.

below is the python script and it can not capture the frame.

import numpy as np
import cv2

cimport numpy as np
import cv2

cap =cv2.VideoCapture(‘udpsrc port=5200 caps = “application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96” ! rtph264depay ! decodebin ! videoconvert ! appsink’, cv2.CAP_GSTREAMER)
while True:

ret,frame =

if not ret:

  • print(‘empty frame’)*
  • continue *

cv2.imshow(‘receive’, frame)
if cv2.waitKey(1)&0xFF == ord(‘q’):

  • break*
  • cap.release()*