SuriRaja commited on
Commit
e774b88
·
verified ·
1 Parent(s): 8470e33

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +19 -0
utils.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ from PIL import Image
3
+
4
+ def extract_frames(video_path, interval=60, max_frames=5):
5
+ cap = cv2.VideoCapture(video_path)
6
+ frames = []
7
+ idx = 0
8
+ count = 0
9
+ while cap.isOpened() and count < max_frames:
10
+ ret, frame = cap.read()
11
+ if not ret:
12
+ break
13
+ if idx % interval == 0:
14
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
15
+ frames.append(Image.fromarray(frame_rgb))
16
+ count += 1
17
+ idx += 1
18
+ cap.release()
19
+ return frames