File size: 517 Bytes
e774b88 630b453 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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 |