Spaces:
Running
on
Zero
Running
on
Zero
video file
Browse files
app.py
CHANGED
@@ -167,34 +167,17 @@ def print_image_info(img):
|
|
167 |
print(f"{key}: {value}")
|
168 |
|
169 |
def extract_frames(video_path):
|
170 |
-
|
171 |
-
Extract frames from a video file
|
172 |
-
|
173 |
-
Args:
|
174 |
-
video_path (str): Path to the video file
|
175 |
-
|
176 |
-
Returns:
|
177 |
-
list: List of frames as PIL Image objects
|
178 |
-
"""
|
179 |
-
frames = []
|
180 |
-
print(f"video path {video_path}")
|
181 |
cap = cv2.VideoCapture(video_path)
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
while True:
|
187 |
-
ret, frame = cap.read()
|
188 |
-
if not ret:
|
189 |
-
break
|
190 |
-
|
191 |
-
# Convert OpenCV BGR to RGB
|
192 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
cap.release()
|
199 |
return frames
|
200 |
|
|
|
167 |
print(f"{key}: {value}")
|
168 |
|
169 |
def extract_frames(video_path):
|
170 |
+
# Open the video file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
cap = cv2.VideoCapture(video_path)
|
172 |
+
frames = []
|
173 |
+
success, frame = cap.read()
|
174 |
+
while success:
|
175 |
+
# Convert frame from BGR (OpenCV default) to RGB
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
177 |
+
# Convert the numpy array (frame) to a PIL Image
|
178 |
+
pil_frame = Image.fromarray(frame_rgb)
|
179 |
+
frames.append(pil_frame)
|
180 |
+
success, frame = cap.read()
|
|
|
181 |
cap.release()
|
182 |
return frames
|
183 |
|