3

I'm trying to connect to an IP Camera (Dahua) using OpenCV and Python using an RTSP URI. I added a sample code below (with the username, password and ip provided in separate variables), which results in [rtsp @ 0x55cc3715c600] method OPTIONS failed: 401 Unauthorized. Using VLC, I'm able to connect, however only after entering the password in a separate dialog even though the password was already provided in the URI.

How should I continue?

address = f'rtsp://{username}:{password}@{ip}'
cap = cv2.VideoCapture(address)
sPY4CN
  • 61
  • 1
  • 5
  • From my IP camera, I simply format the RTSP URI like this and throw it into `cv2.VideoCapture()`. I'm also using a Dahua camera but the RTSP link will vary from camera to camera. Here's an example of mine `rtsp://username:password@192.168.1.25/axis-media/media.amp`. If the link works in VLC it should work in OpenCV – nathancy Nov 22 '19 at 20:44
  • In VLC I am only prompted in a separate dialog for the password if the received password is incorrect. Try hardcoding the address to what it should be and see if it still gives you problems. – shortcipher3 Nov 23 '19 at 05:19
  • Also if you compile opencv with gstreamer you can use any gstreamer pipeline, here is one I use: `vc = cv2.VideoCapture(' rtspsrc location=rtsp://user:password@192.168.1.25:8554/play1.sdp ! decodebin ! videoconvert ! appsink ')` You should be able to test that this pipeline works outside of opencv with gst-launch as follows: `gst-launch-1.0 rtspsrc location=rtsp://user:password@192.168.1.25:8554/play1.sdp ! decodebin ! videoconvert ! autovideosink` – shortcipher3 Nov 23 '19 at 05:19
  • ```rtsp://username:password@192.168.1.25``` Is the format I use, however, it leads to the prompt in VLC, where I have to enter the password again. Perhaps it has something to do with special characters in the password name: ```%``` ? – sPY4CN Nov 23 '19 at 15:33
  • Using the ```gst-launch-1.0``` command also results in an ```Unauthorized (401)``` error. – sPY4CN Nov 23 '19 at 15:40

2 Answers2

3

Found the problem, it had to do with the password having a special character (%), which should be percent encoded (%25).

sPY4CN
  • 61
  • 1
  • 5
0

If your password contains characters like !"#$%&'()*+,-./:;<=>?@[\]^_{|}~, then the problem may be with cv2.VideoCapture().

You may try to use imutils library to solve this problem. That works for me.

from imutils.video import VideoStream
cap = VideoStream(video_src).start()
frame = cap.read()
Tpoc311
  • 1
  • 1