【发布时间】:2020-03-18 20:01:04
【问题描述】:
我正在尝试使用 OpenCV 和 Python 使用 RTSP URI 连接到 IP 摄像机(大华)。我在下面添加了一个示例代码(用户名、密码和 ip 在单独的变量中提供),结果为[rtsp @ 0x55cc3715c600] method OPTIONS failed: 401 Unauthorized。使用 VLC,我可以连接,但是只有在单独的对话框中输入密码后,即使 URI 中已经提供了密码。
我应该如何继续?
address = f'rtsp://{username}:{password}@{ip}'
cap = cv2.VideoCapture(address)
【问题讨论】:
-
从我的 IP 摄像机中,我只需像这样格式化 RTSP URI 并将其放入
cv2.VideoCapture()。我也在使用大华相机,但 RTSP 链接因相机而异。这是我的一个例子rtsp://username:password@192.168.1.25/axis-media/media.amp。如果链接在 VLC 中有效,它应该在 OpenCV 中有效 -
在 VLC 中,如果收到的密码不正确,我只会在单独的对话框中提示输入密码。尝试将地址硬编码为应有的地址,看看它是否仍然会给您带来问题。
-
此外,如果您使用 gstreamer 编译 opencv,您可以使用任何 gstreamer 管道,这是我使用的一个:
vc = cv2.VideoCapture(' rtspsrc location=rtsp://user:password@192.168.1.25:8554/play1.sdp ! decodebin ! videoconvert ! appsink ')您应该能够使用 gst-launch 测试该管道是否在 opencv 之外工作,如下所示:gst-launch-1.0 rtspsrc location=rtsp://user:password@192.168.1.25:8554/play1.sdp ! decodebin ! videoconvert ! autovideosink -
rtsp://username:password@192.168.1.25是我使用的格式,但是它会导致VLC中的提示,我必须再次输入密码。也许它与密码名称中的特殊字符有关:%? -
使用
gst-launch-1.0命令也会导致Unauthorized (401)错误。
标签: python opencv authentication rtsp ip-camera