Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
| 3 |
-
import pandas as pd
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
def extract_frames(video_path
|
| 7 |
output_folder = "extracted_frames"
|
| 8 |
os.makedirs(output_folder, exist_ok=True)
|
| 9 |
|
| 10 |
-
# Read timestamps from CSV
|
| 11 |
-
df = pd.read_csv(csv_path)
|
| 12 |
-
|
| 13 |
cap = cv2.VideoCapture(video_path)
|
| 14 |
-
|
| 15 |
-
|
| 16 |
extracted_images = []
|
| 17 |
|
| 18 |
-
|
| 19 |
-
timestamp = row['start'] # Using 'start' column for frame extraction
|
| 20 |
-
frame_number = int(timestamp * fps)
|
| 21 |
-
cap.set(cv2.CAP_PROP_POS_FRAMES, frame_number)
|
| 22 |
success, frame = cap.read()
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
cap.release()
|
| 30 |
return extracted_images
|
| 31 |
|
| 32 |
gui = gr.Interface(
|
| 33 |
fn=extract_frames,
|
| 34 |
-
inputs=
|
| 35 |
-
gr.Video(label="Upload Video"),
|
| 36 |
-
gr.File(label="Upload CSV with timestamps")
|
| 37 |
-
],
|
| 38 |
outputs=gr.Gallery(label="Extracted Frames"),
|
| 39 |
-
title="Frame Extractor
|
| 40 |
-
description="Upload a video
|
| 41 |
)
|
| 42 |
|
| 43 |
-
gui.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
def extract_frames(video_path):
|
| 6 |
output_folder = "extracted_frames"
|
| 7 |
os.makedirs(output_folder, exist_ok=True)
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
cap = cv2.VideoCapture(video_path)
|
| 10 |
+
frame_count = 0
|
|
|
|
| 11 |
extracted_images = []
|
| 12 |
|
| 13 |
+
while True:
|
|
|
|
|
|
|
|
|
|
| 14 |
success, frame = cap.read()
|
| 15 |
+
if not success:
|
| 16 |
+
break
|
| 17 |
|
| 18 |
+
image_path = os.path.join(output_folder, f"frame_{frame_count}.jpg")
|
| 19 |
+
cv2.imwrite(image_path, frame)
|
| 20 |
+
extracted_images.append(image_path)
|
| 21 |
+
frame_count += 1
|
| 22 |
|
| 23 |
cap.release()
|
| 24 |
return extracted_images
|
| 25 |
|
| 26 |
gui = gr.Interface(
|
| 27 |
fn=extract_frames,
|
| 28 |
+
inputs=gr.Video(label="Upload Video"),
|
|
|
|
|
|
|
|
|
|
| 29 |
outputs=gr.Gallery(label="Extracted Frames"),
|
| 30 |
+
title="Video Frame Extractor",
|
| 31 |
+
description="Upload a video to extract all frames sequentially."
|
| 32 |
)
|
| 33 |
|
| 34 |
+
gui.launch()
|