Spaces:
Sleeping
Sleeping
영상 프레임 추출 스크립트
Browse files
utils.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
|
| 3 |
+
def extract_frames(video_path, interval_sec=2):
|
| 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 |
+
idx = 0
|
| 10 |
+
|
| 11 |
+
while cap.isOpened():
|
| 12 |
+
ret, frame = cap.read()
|
| 13 |
+
if not ret:
|
| 14 |
+
break
|
| 15 |
+
if idx % frame_interval == 0:
|
| 16 |
+
frames.append(frame)
|
| 17 |
+
idx += 1
|
| 18 |
+
|
| 19 |
+
cap.release()
|
| 20 |
+
return frames
|