1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| import os import 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 = 0 total_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)
if cv2.waitKey(1) & 0xFF == ord('q'): break
video.release()
key = cv2.waitKey(0)
if key == ord('a'): break elif key == ord('s'): current_index = (current_index + 1) % total_videos elif key == ord('d'): current_index = (current_index - 1) % total_videos
cv2.destroyAllWindows()
|