直接上代码:
import cv2
# 替换为正确的RTSP链接
rtsp_url = 'rtsp://admin:abcd12345@192.168.1.64:554/h264/ch1/main/av_stream'
cap = cv2.VideoCapture(rtsp_url)
if not cap.isOpened():
print("无法打开视频流,检查RTSP URL和凭证")
else:
while True:
ret, frame = cap.read()
if not ret:
print("无法读取视频帧,流可能已结束")
break
cv2.imshow('RTSP Stream', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()