Spaces:
Runtime error
Runtime error
| import cv2 | |
| from PIL import Image | |
| def extract_frames(video_path, interval=60, max_frames=5): | |
| cap = cv2.VideoCapture(video_path) | |
| frames = [] | |
| idx = 0 | |
| count = 0 | |
| while cap.isOpened() and count < max_frames: | |
| ret, frame = cap.read() | |
| if not ret: | |
| break | |
| if idx % interval == 0: | |
| frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
| frames.append(Image.fromarray(frame_rgb)) | |
| count += 1 | |
| idx += 1 | |
| cap.release() | |
| return frames |