Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,15 +9,21 @@ def extract_frames(video_path):
|
|
9 |
|
10 |
cap = cv2.VideoCapture(video_path)
|
11 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
|
|
|
|
|
|
|
|
12 |
extracted_images = []
|
13 |
frame_count = 0
|
14 |
|
|
|
|
|
15 |
while True:
|
16 |
success, frame = cap.read()
|
17 |
if not success:
|
18 |
break
|
19 |
|
20 |
-
if frame_count %
|
21 |
image_path = os.path.join(output_folder, f"frame_{frame_count}.jpg")
|
22 |
cv2.imwrite(image_path, frame)
|
23 |
extracted_images.append(image_path)
|
@@ -26,6 +32,9 @@ def extract_frames(video_path):
|
|
26 |
|
27 |
cap.release()
|
28 |
|
|
|
|
|
|
|
29 |
zip_filename = "extracted_frames.zip"
|
30 |
with zipfile.ZipFile(zip_filename, 'w') as zipf:
|
31 |
for img in extracted_images:
|
|
|
9 |
|
10 |
cap = cv2.VideoCapture(video_path)
|
11 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
12 |
+
|
13 |
+
if fps == 0 or fps is None:
|
14 |
+
return "Error: Could not determine FPS of the video."
|
15 |
+
|
16 |
extracted_images = []
|
17 |
frame_count = 0
|
18 |
|
19 |
+
frame_interval = max(1, int(fps / 60)) # Avoid division by zero
|
20 |
+
|
21 |
while True:
|
22 |
success, frame = cap.read()
|
23 |
if not success:
|
24 |
break
|
25 |
|
26 |
+
if frame_count % frame_interval == 0: # Extract 60 frames per second
|
27 |
image_path = os.path.join(output_folder, f"frame_{frame_count}.jpg")
|
28 |
cv2.imwrite(image_path, frame)
|
29 |
extracted_images.append(image_path)
|
|
|
32 |
|
33 |
cap.release()
|
34 |
|
35 |
+
if not extracted_images:
|
36 |
+
return "Error: No frames extracted."
|
37 |
+
|
38 |
zip_filename = "extracted_frames.zip"
|
39 |
with zipfile.ZipFile(zip_filename, 'w') as zipf:
|
40 |
for img in extracted_images:
|