Stream image with gstreamer and python over tcp

hi I’m trying to stream the camera feed of the jetson nano camera from Jetson to another Linux system with gstreamer over TCP
I can take frames from Jetson and show them with autovideosink element in the terminal with this pipeline:
gst-launch-1.0 tcpclientsrc host=10.42.0.118 port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 max-threads=1 ! videoconvert ! fpsdisplaysink sync=false
and it’s working pretty good
but when I try to run this pipeline in python with appsink it doesn’t work at all and i can’t see the images
I’m running this script :
import cv2

cap = cv2.VideoCapture(‘tcpclientsrc host=10.42.0.118 port=5000 ! gdpdepay ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! “video/x-raw,format=(string)BGR” ! videoconvert ! appsink sync=false’, cv2.CAP_GSTREAMER)

if not cap.isOpened():
print(“Failed to open video stream”)
exit()

while True:
ret, frame = cap.read()
if not ret:
break

cv2.imshow('Frame', frame)

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

cap.release()
cv2.destroyAllWindows()
and i get this message
‘Failed to open video stream’
can anybody help me to do this ?
thank you all

Hi,
The pipeline may not be well read due to " " or ' '. There are working samples:
Doesn't work nvv4l2decoder for decoding RTSP in gstreamer + opencv - #3 by DaneLLL
Displaying to the screen with OpenCV and GStreamer - #9 by DaneLLL

You may put the pipeline in " " for a try:

"tcpclientsrc host=10.42.0.118 port=5000 ! gdpdepay ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! video/x-raw,format=BGR ! videoconvert ! appsink sync=false"

no i tried this befor it dosent work

I’m not positive about using RTP repayed into GDP for TCP. I’d advise to use mkv such as this as sender:

# Video test case
gst-launch-1.0 videotestsrc ! queue ! nvvidconv ! nvv4l2h264enc insert-vui=1 insert-sps-pps=1 idrinterval=15 ! h264parse ! matroskamux streamable=1 ! tcpserversink host=<Jeston_IP> port=4953

# CSI camera with argus
gst-launch-1.0 nvarguscamerasrc ! nvvidconv ! nvv4l2h264enc insert-vui=1 insert-sps-pps=1 idrinterval=15 ! h264parse ! matroskamux streamable=1 ! queue ! tcpserversink host=<Jeston_IP> port=4953

Then on client:

gst-launch-1.0 tcpclientsrc host=<Jetson_IP> port=4953 ! queue ! matroskademux ! h264parse ! avdec_h264 ! queue ! videoconvert ! fpsdisplaysink text-overlay=0 video-sink=fakesink -v

where <Jetson_IP> is the IP address of the Jetson.
If this works, try the following python code :

import cv2

# Check for gstreamer support from opencv
import re
print('GStreamer support: %s' % re.search(r'GStreamer\:\s+(.*)', cv2.getBuildInformation()).group(1))


# Create capture (you would edit for setting your Jetson's IP)
cap = cv2.VideoCapture('tcpclientsrc host=<Jetson_IP> port=4953 ! queue ! matroskademux ! h264parse ! avdec_h264 ! queue ! videoconvert ! video/x-raw,format=BGR ! queue ! appsink drop=1', cv2.CAP_GSTREAMER)
if not cap.isOpened():
	print('Failed to open camera');
	exit(-1)
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = cap.get(cv2.CAP_PROP_FPS)
print('camera opened, framing %dx%d@%f fps' % (w,h,fps))

# Loop reading frame and displaying	
while True:
	ret,frame = cap.read()
	if not ret:
		print('Failed to read from camera')
		cap.release()
		exit(-3)
	cv2.imshow('Test', frame)
	cv2.waitKey(1)
cap.release()

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