Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -1,20 +1,16 @@
|
|
| 1 |
import cv2
|
| 2 |
|
| 3 |
-
def extract_frames(video_path,
|
| 4 |
cap = cv2.VideoCapture(video_path)
|
| 5 |
-
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 6 |
-
frame_interval = int(fps * interval_sec)
|
| 7 |
-
|
| 8 |
frames = []
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
while cap.isOpened():
|
| 12 |
ret, frame = cap.read()
|
| 13 |
if not ret:
|
| 14 |
break
|
| 15 |
-
if
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
cap.release()
|
| 20 |
return frames
|
|
|
|
| 1 |
import cv2
|
| 2 |
|
| 3 |
+
def extract_frames(video_path, max_frames=10, skip=10):
|
| 4 |
cap = cv2.VideoCapture(video_path)
|
|
|
|
|
|
|
|
|
|
| 5 |
frames = []
|
| 6 |
+
count = 0
|
| 7 |
+
while cap.isOpened() and len(frames) < max_frames:
|
|
|
|
| 8 |
ret, frame = cap.read()
|
| 9 |
if not ret:
|
| 10 |
break
|
| 11 |
+
if count % skip == 0:
|
| 12 |
+
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 13 |
+
frames.append(frame_rgb)
|
| 14 |
+
count += 1
|
| 15 |
cap.release()
|
| 16 |
return frames
|