Spaces:
Sleeping
Sleeping
Delete utils
Browse files- utils/__init__.py +0 -0
- utils/frame_sampler.py +0 -30
utils/__init__.py
DELETED
|
File without changes
|
utils/frame_sampler.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
| 1 |
-
import cv2
|
| 2 |
-
import os
|
| 3 |
-
|
| 4 |
-
def extract_keyframes(video, output_dir, num_frames=30):
|
| 5 |
-
"""
|
| 6 |
-
Extract keyframes from a video file.
|
| 7 |
-
:param video: path to the uploaded video
|
| 8 |
-
:param output_dir: directory to save keyframes
|
| 9 |
-
:param num_frames: number of keyframes to extract
|
| 10 |
-
:return: list of file paths to the extracted keyframes
|
| 11 |
-
"""
|
| 12 |
-
video_path = video if isinstance(video, str) else video.name
|
| 13 |
-
cap = cv2.VideoCapture(video_path)
|
| 14 |
-
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
| 15 |
-
frame_interval = total_frames // num_frames
|
| 16 |
-
keyframes = []
|
| 17 |
-
|
| 18 |
-
if not os.path.exists(output_dir):
|
| 19 |
-
os.makedirs(output_dir)
|
| 20 |
-
|
| 21 |
-
for i in range(num_frames):
|
| 22 |
-
cap.set(cv2.CAP_PROP_POS_FRAMES, i * frame_interval)
|
| 23 |
-
ret, frame = cap.read()
|
| 24 |
-
if ret:
|
| 25 |
-
frame_path = os.path.join(output_dir, f"frame_{i+1}.jpg")
|
| 26 |
-
cv2.imwrite(frame_path, frame)
|
| 27 |
-
keyframes.append(frame_path)
|
| 28 |
-
|
| 29 |
-
cap.release()
|
| 30 |
-
return keyframes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|