"""How to stream frames using gstreamer, with opencv in python?
https://forums.developer.nvidia.com/t/how-to-stream-frames-using-gstreamer-with-opencv-in-python/121036/2
"""
import cv2
cap = cv2.VideoCapture("rtsp://admin:xxxx@10.168.1.248:554/h264/ch1/main/av_stream")
out = cv2.VideoWriter("appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw, format=BGRx ! nvvidconv ! omxh264enc ! video/x-h264, stream-format=byte-stream ! h264parse ! rtph264pay pt=96 config-interval=1 ! udpsink host=10.168.1.177 port=50001", cv2.CAP_GSTREAMER, 0, 25.0, (1920,1080))
while cap.isOpened():
ret, frame = cap.read()
if ret:
if out.isOpened():
out.write(frame)
print('writing frame')
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()