软件openCV基于openCV的视频查看器HolioFox2023-12-062024-09-23123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import osimport cv2# 视频文件夹路径folder_path = 'D:/Users/video'# 获取文件夹中的所有视频文件video_files = [os.path.join(folder_path, file) for file in os.listdir(folder_path) if file.lower().endswith(('.mp4', '.avi', '.mkv'))]# 创建一个视频播放窗口cv2.namedWindow('Video Player', cv2.WINDOW_NORMAL)# 初始化视频索引current_index = 0total_videos = len(video_files)while True: # 读取当前索引处的视频文件 video_path = video_files[current_index] video = cv2.VideoCapture(video_path) while video.isOpened(): # 读取视频帧 ret, frame = video.read() if not ret: break # 显示视频帧 cv2.imshow('Video Player', frame) # 按下 'q' 键退出当前视频 if cv2.waitKey(1) & 0xFF == ord('q'): break # 释放当前视频的资源 video.release() # 等待用户按键 key = cv2.waitKey(0) # 根据按键进行操作 if key == ord('a'): # 按下 'a' 键退出播放器 break elif key == ord('s'): # 按下 's' 键播放下一个视频 current_index = (current_index + 1) % total_videos elif key == ord('d'): # 按下 'd' 键播放上一个视频 current_index = (current_index - 1) % total_videos# 关闭窗口cv2.destroyAllWindows()