Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import os
|
4 |
-
import shutil
|
5 |
import zipfile
|
6 |
|
7 |
def extract_frames(video_path):
|
@@ -10,17 +9,19 @@ def extract_frames(video_path):
|
|
10 |
|
11 |
cap = cv2.VideoCapture(video_path)
|
12 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
13 |
-
frame_count = 0
|
14 |
extracted_images = []
|
|
|
15 |
|
16 |
while True:
|
17 |
success, frame = cap.read()
|
18 |
if not success:
|
19 |
break
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
frame_count += 1
|
25 |
|
26 |
cap.release()
|
@@ -37,7 +38,7 @@ gui = gr.Interface(
|
|
37 |
inputs=gr.Video(label="Upload Video"),
|
38 |
outputs=gr.File(label="Download Extracted Frames as ZIP"),
|
39 |
title="Video Frame Extractor",
|
40 |
-
description="Upload a video to extract
|
41 |
)
|
42 |
|
43 |
gui.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import os
|
|
|
4 |
import zipfile
|
5 |
|
6 |
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 % int(fps / 60) == 0: # Extract 60 frames per second
|
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)
|
24 |
+
|
25 |
frame_count += 1
|
26 |
|
27 |
cap.release()
|
|
|
38 |
inputs=gr.Video(label="Upload Video"),
|
39 |
outputs=gr.File(label="Download Extracted Frames as ZIP"),
|
40 |
title="Video Frame Extractor",
|
41 |
+
description="Upload a video to extract frames at 60 FPS and download as a ZIP file."
|
42 |
)
|
43 |
|
44 |
gui.launch()
|