Skip to content

Instantly share code, notes, and snippets.

@kingardor
Created March 4, 2019 17:53
Show Gist options
  • Save kingardor/285296ec94580ea0a96e638ed075e953 to your computer and use it in GitHub Desktop.
Save kingardor/285296ec94580ea0a96e638ed075e953 to your computer and use it in GitHub Desktop.
Access RTSP or UDP video stream that is streamed using FFMPEG
# ffmpeg -i video.mp4 -v 0 -vcodec mpeg4 -f mpegts udp://192.168.0.101:23000
import os
cap = cv2.VideoCapture('udp://192.168.0.101:23000?overrun_nonfatal=1&fifo_size=50000000')
# cap = cv2.VideoCapture('rtsp://192.168.0.101')
os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "udp_transport;0"
# os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;0"
while cap.isOpened():
ret, frame = cap.read()
if ret:
cv2.imshow('Test', frame)
if cv2.waitKey(1) & 0xFF == ord('q'): break
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment