pythonopencvauthenticationrtspip-camera

How to authenticate to IP camera using OpenCV


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)

Solution

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