16

I have a remote camera streaming through rtsp protocol and am trying to access it in OpenCV 2.13.1 using python with following code.

camera = cv2.VideoCapture("rtsp://admin:<port>@<ip>/xyz/video.smp")

However, when I do that I get the following warning

WARNING: Couldn't read movie file rtsp://admin:<port>@<ip>/xyz/video.smp

I have also tried doing this:

camera = cv2.VideoCapture.open("rtsp://admin:<port>@<ip>/xyz/video.smp")

but when I do this I get this error:

`AttributeError: 'builtin_function_or_method' object has no attribute` 'open'

I did searched quite a bit about this problem but couldn't get the idea that works for me. Any help would be appreciated.

4
  • example with rtsp streams which works for me on Python 2. Try this streams - maybe it is problem with some codecs. Commented Nov 29, 2016 at 21:20
  • No unfortunately it didnt worked for me although I am also using python 2 Commented Nov 29, 2016 at 21:31
  • so maybe you have problem with some codecs or something else. I have problem with cv2 in Python 3 - it doesn't read stream event from camera :/ I will try to install it from source code maybe it changes something. pyimagesearch.com/tag/install Commented Nov 30, 2016 at 12:58
  • Possible duplicate of RTSP stream and OpenCV (Python) Commented Oct 24, 2019 at 5:09

2 Answers 2

23

Credit from RTSP stream and OpenCV (Python):

vcap = cv.VideoCapture("rtsp://192.168.1.2:8080/out.h264")
while(1):
    ret, frame = vcap.read()
    cv.imshow('VIDEO', frame)
    cv.waitKey(1)
Sign up to request clarification or add additional context in comments.

4 Comments

is there a library that can view these frames in a browser? (e.g. send it using websocket to the client, then decode it using some JS library?)
There is a [jsmpeg] (github.com/phoboslab/jsmpeg) to view the live stream on the browser. But first, you need ffmpeg to send the stream to the relay server.
for streaming you can easiliy build an mjpeg and stream to browser (blog.miguelgrinberg.com/post/video-streaming-with-flask)
@ierdna you could also look at using ImageZMQ along with the StreamingResponse API from Starlette.io
1

I had the same problem. My python scrip reading rtsp stream worked only some times and in some computers and I don't figured out why. My solution was initializing the stream from the camera and create a new http stream with VLC. Then, my opencv script reads from "http://127.0.0.1" that is the stream created by the VLC. It's not the best solutoin, but worked out for me.

I made a script inside a .bat file to keep simple to initialize the VLC with the correct configurations. The comando line to do it is:

"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" rtsp://10.0.0.1 input_stream --ipv4-timeout=600000 --sout #transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:http{mux=ffmpeg{mux=flv},dst=:8080/} :no-sout-all :sout-keep

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.