Spaces:
Sleeping
Sleeping
Update detector/frame_sampler.py
Browse files
detector/frame_sampler.py
CHANGED
|
@@ -4,6 +4,11 @@ import os
|
|
| 4 |
def extract_keyframes(video, output_dir, target_frames=50):
|
| 5 |
cap = cv2.VideoCapture(video)
|
| 6 |
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
frame_step = max(1, total_frames // target_frames)
|
| 8 |
|
| 9 |
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
| 4 |
def extract_keyframes(video, output_dir, target_frames=50):
|
| 5 |
cap = cv2.VideoCapture(video)
|
| 6 |
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 7 |
+
|
| 8 |
+
if total_frames <= 0:
|
| 9 |
+
cap.release()
|
| 10 |
+
return []
|
| 11 |
+
|
| 12 |
frame_step = max(1, total_frames // target_frames)
|
| 13 |
|
| 14 |
os.makedirs(output_dir, exist_ok=True)
|