import cv2

def open_rtsp_stream(rtsp_url):
    cap = cv2.VideoCapture(rtsp_url)

    if not cap.isOpened():
        print(f"Error: Unable to open RTSP stream at {rtsp_url}")
        return

    while True:
        ret, frame = cap.read()

        if not ret:
            print("Error: Failed to read frame from the RTSP stream")
            break

        cv2.imshow('RTSP Stream', frame)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()

if __name__ == "__main__":
    # 替换为你的RTSP视频流地址
    i=input("请输入:")
    rtsp_url = i

    open_rtsp_stream(rtsp_url)

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐