Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,43 @@
|
|
|
|
1 |
import cv2
|
|
|
2 |
import os
|
3 |
-
import glob
|
4 |
|
5 |
-
def
|
|
|
6 |
os.makedirs(output_folder, exist_ok=True)
|
7 |
-
video_files = glob.glob(os.path.join(input_folder, "*.mp4")) # Modify if using other formats
|
8 |
|
9 |
-
|
|
|
10 |
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
success, frame = cap.read()
|
14 |
|
15 |
-
|
16 |
-
image_path = os.path.join(output_folder, f"{
|
17 |
cv2.imwrite(image_path, frame)
|
18 |
-
|
19 |
-
success, frame = cap.read()
|
20 |
-
|
21 |
-
cap.release()
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
input_folder = "videos" # Change this to the path where your videos are stored
|
27 |
-
output_folder = "output_images"
|
28 |
-
extract_frames_from_videos(input_folder, output_folder)
|
|
|
1 |
+
import gradio as gr
|
2 |
import cv2
|
3 |
+
import pandas as pd
|
4 |
import os
|
|
|
5 |
|
6 |
+
def extract_frames(video_path, csv_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 |
+
fps = cap.get(cv2.CAP_PROP_FPS)
|
15 |
+
|
16 |
+
extracted_images = []
|
17 |
+
|
18 |
+
for index, row in df.iterrows():
|
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 |
+
if success:
|
25 |
+
image_path = os.path.join(output_folder, f"frame_{index}.jpg")
|
26 |
cv2.imwrite(image_path, frame)
|
27 |
+
extracted_images.append(image_path)
|
|
|
|
|
|
|
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 from Video",
|
40 |
+
description="Upload a video and a CSV file with timestamps to extract specific frames."
|
41 |
+
)
|
42 |
|
43 |
+
gui.launch()
|
|
|
|
|
|