Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting RTSP stream with Opencv and python

I know this could be the 100th question of this kind, but I dug up google and everything, and I could not find anything working.
I need to get an RTSP stream with opencv in python, and I'm out of ideas.
Here's what I tried so far:

  • Tried to stream with ffserver and ffmpeg but even when I got it working, I could see the stream only in the browser with very high latency, and not working in opencv
  • Tried to stream directly to udp with ffmpeg but again, no luck
  • Tried this script, but all I got was corrupted and unusable images.

Any ideas? I'm running on Mac OSX Sierra, I have compiled OpenCV 3.2.0 with ffmpeg support and I'm using Python 2.7.
My cam is a Sricam SP09 and my RTSP url is the following:

rtsp://973704:[email protected]:554/onvif1

like image 382
magicleon94 Avatar asked Mar 02 '26 15:03

magicleon94


1 Answers

I had the same problem. You might be able to solve it with some additional codes.

import os

os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp"

vcap = cv2.VideoCapture("rtsp://[IP_CAM_ADDRESS]", cv2.CAP_FFMPEG)

Hope to be helpful to somebody.

like image 82
hyung ook An Avatar answered Mar 05 '26 05:03

hyung ook An



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!