Trying to stream a video through gstreamer with a python code:
My python code is:
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
#gst_out = “appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw,format=BGRx ! nvvidconv ! video/x-raw(memory:NVMM),format=NV12 ! nvv4l2h264enc maxperf-enable=1 insert-sps-pps=1 ! h264parse ! rtph264pay pt=96 ! queue ! application/x-rtp, media=video, encoding-name=H264 ! udpsink host=192.168.43.208 port=5000”
#gst_out = ‘appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000’
#gst_out = ‘appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000’
gst_out = “appsrc ! video/x-raw, format=BGR, pixel-aspect-ratio=1/1 ! queue ! videoconvert ! video/x-raw, format=BGRx ! nvvidconv ! nvv4l2h264enc insert-vui=1 ! video/x-h264, stream-format=byte-stream, alignment=au ! h264parse ! video/x-h264, stream-format=byte-stream ! rtph264pay pt=96 config-interval=1 ! application/x-rtp, media=video, encoding-name=H264 ! udpsink host=224.1.1.1 port=5000 auto-multicast=true”
#out = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, 20, (640,480), True)
out = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, (640,480))
#out = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, 20, (640,480))
if not out.isOpened() :
print(“Writer failed”)
exit()
print(“Writer opened”)
while True:
ret,frame = cap.read()
if not ret:
break
out.write(frame)
if (cv2.waitKey(1) & 0xFF) == 27:
break # esc to quit
out.release()
cap.release()
#video.release()
cv2.destroyAllWindows()
tried several different pipelines and cv2.VideoWriter() combinations, as you can see with the comment outs, receiving always this error:
Traceback (most recent call last):
File “/home/xbio/software/Cam2_5.py”, line 15, in
out = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, (640,480))
TypeError: must be real number, not tuple
Edit: Discovered that my openCV installation has no gstreamer support, at the moment trying to figure out how to install gstreamer support for openCV