Read Frames from RTSP Stream in Python Read Frames from RTSP Stream in Python python python

Read Frames from RTSP Stream in Python


Using the same method listed by "depu" worked perfectly for me.I just replaced "video file" with "RTSP URL" of actual camera.Example below worked on AXIS IP Camera. (This was not working for a while in previous versions of OpenCV)Works on OpenCV 3.4.1 Windows 10)

import cv2cap = cv2.VideoCapture("rtsp://root:pass@192.168.0.91:554/axis-media/media.amp")while(cap.isOpened()):    ret, frame = cap.read()    cv2.imshow('frame', frame)    if cv2.waitKey(20) & 0xFF == ord('q'):        breakcap.release()cv2.destroyAllWindows()


Bit of a hacky solution, but you can use the VLC python bindings (you can install it with pip install python-vlc) and play the stream:

import vlcplayer=vlc.MediaPlayer('rtsp://:8554/output.h264')player.play()

Then take a snapshot every second or so:

while 1:    time.sleep(1)    player.video_take_snapshot(0, '.snapshot.tmp.png', 0, 0)

And then you can use SimpleCV or something for processing (just load the image file '.snapshot.tmp.png' into your processing library).


use opencv

video=cv2.VideoCapture("rtsp url")

and then you can capture framse. read openCV documentation visit: https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_video_display/py_video_display.html