import logging from time import sleep import cv2 print(cv2.__version__) def open_video(video_id): cap = cv2.VideoCapture(video_id) if not cap.isOpened(): logging.info("无法打开摄像头") return cap class VideoProcessor: capture: cv2.VideoCapture rtsp_url ="rtsp://admin:123456abc@192.168.1.64:554/h264/ch1/main/av_stream" print("开始读取2") capture=open_video(2) vp = VideoProcessor() vp.capture = capture fps = vp.capture .get(cv2.CAP_PROP_FPS) width = int(vp.capture .get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(vp.capture .get(cv2.CAP_PROP_FRAME_HEIGHT)) print(f"fps={fps}") print("width={width}, height={height}".format(width=width, height=height)) cv2.namedWindow('frame') i = 0 while True: ret, frame = vp.capture .read() if ret: print("-->") cv2.imshow("frame", frame) i=i+1 if i>10: break # 写入帧到输出文件 # out.write(frame) else: logging.info("无法读取图像帧") break if cv2.waitKey(1) & 0xFF == ord('q'): # 按'q'退出循环 break print("释放2") vp.capture.release() cv2.destroyAllWindows() print("开始读取0") sleep(2) vp.capture = open_video(0) # # 定义视频编 = open_video(0)码器和输出文件 # fourcc = cv2.VideoWriter_fourcc(*'mp4v') # out = cv2.VideoWriter('output.mp4', fourcc, fps, (width, height)) while True: ret, frame = vp.capture .read() if ret: cv2.imshow("frame", frame) # 写入帧到输出文件 # out.write(frame) else: logging.info("无法读取图像帧") if cv2.waitKey(1) & 0xFF == ord('q'): # 按'q'退出循环 break vp.capture.release() # out.release()