Cannot get v412src that runs on gstreamer to run in Python3 via OpenCV

I am having a problem running gstreamer pipeline from Python 3 via OpenCv. I do not know gstreamer very well although I am comfortable with opencv. My issues stem from my ignorance not actual issue with Jetson TX2. I am working with Jetpack 4.4, running OpenCV 4.1.1 with gstreamer (unchanged build from Jetpack), and the Python version I am using is Python 3.6.9. On the hardware side I am using a devkit with Jetson TX2. The camera I am using is an ELP USB camera. The dev kit is headless. With this setup I am able to take pictures, record video, and stream video from the Jetson using gstreamer directly. My problem arises when I attempted to use it in python. Right now I am using a very simple python script to open my camera and stream video to another computer on the same network. My goal is to latter use a neural network I made to do detection, add bounding boxes, and pipe the post processed video via g streamer to another computer. I have tested a number of pipelines on command line and in general they work fine. When I add the pipeline to Python add attempt to use the same pipeline it errors out.
For example I am using these pipelines

On the Jetson/server
gst-launch-1.0 v4l2src device=/dev/video0 ! ‘video/x-raw, format=YUY2’ ! nvvidconv ! ‘video/x-raw(memory:NVMM), width=640, height=480’ ! omxh264enc ! h264parse ! rtph264pay config-interval=1 ! udpsink host= port=5000
gst-launch-1.0 udpsrc port=5000 ! ‘application/x-rtp, encoding-name=H264, payload=96’ ! rtph264depay ! h264parse ! avdec_h264 ! xvimagesink

This works fine although very low frame rate.
Now if I try to do the following python it wont work. My goal is to get the output from my YOLO4 implementation to stream as HD264.

import cv2
cap = cv2.VideoCapture(0)

framerate = 25.0
gst_str =‘video/x-raw, format=YUY2 ! nvvidconv ! video/x-raw(memory:NVMM), width=640, height=480 ! omxh264enc ! h264parse ! rtph264pay config-interval=1 ! udpsink host= port=5000’

out = cv2.VideoWriter(gst_str, 0, framerate, (640, 480))

while cap.isOpened():
ret, frame =
if ret:


    if cv2.waitKey(1) & 0xFF == ord('q'):

Release everything if job is finished


I know this is an issue with how I am implementing this but I am sort of clueless on how to integrate gstreamer with opencv. I have done some looking around and looking at some tutorials, but none were helpful. I would appreciate any assistance even if it is pointing me to a similar example somewhere.