Upload 5 files
Browse files- README.md +3 -12
- app.py +11 -7
- backend/video_processor.py +5 -2
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -9,16 +9,7 @@ app_file: app.py
|
|
| 9 |
pinned: true
|
| 10 |
---
|
| 11 |
|
| 12 |
-
# NHAI DAMS Phase 1: Video to Frame
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
### Features:
|
| 17 |
-
- Supports `.mp4` files
|
| 18 |
-
- Saves extracted frames to `frames/<video_name>/`
|
| 19 |
-
- Works on Gradio 4.24+ with `type="filepath"` support
|
| 20 |
-
|
| 21 |
-
### How to Use:
|
| 22 |
-
1. Upload your video
|
| 23 |
-
2. Click "Start Frame Extraction"
|
| 24 |
-
3. View output path and frame count
|
|
|
|
| 9 |
pinned: true
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# NHAI DAMS Phase 1: Video to Frame Extractor
|
| 13 |
|
| 14 |
+
Upload a `.mp4` video and extract frames every 1 second into the `/frames/<video_name>/` folder.
|
| 15 |
+
Tested with Gradio 4.24.0 using only valid schema-safe return types.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -2,16 +2,20 @@ import gradio as gr
|
|
| 2 |
from backend.video_processor import extract_frames
|
| 3 |
|
| 4 |
def process_video(video_path):
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
with gr.Blocks() as demo:
|
| 9 |
-
gr.Markdown("# 🎥 NHAI DAMS Phase 1: Video to Frame Extractor")
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
demo.launch()
|
|
|
|
| 2 |
from backend.video_processor import extract_frames
|
| 3 |
|
| 4 |
def process_video(video_path):
|
| 5 |
+
try:
|
| 6 |
+
saved, folder = extract_frames(video_path)
|
| 7 |
+
return f"✅ {saved} frames extracted and saved to folder: {folder}"
|
| 8 |
+
except Exception as e:
|
| 9 |
+
return f"❌ Error during frame extraction: {str(e)}"
|
| 10 |
|
| 11 |
with gr.Blocks() as demo:
|
| 12 |
+
gr.Markdown("## 🎥 NHAI DAMS Phase 1: Video to Frame Extractor")
|
| 13 |
|
| 14 |
+
with gr.Row():
|
| 15 |
+
video_input = gr.File(label="Upload Drone Video (.mp4)", type="filepath")
|
| 16 |
+
output = gr.Textbox(label="Frame Extraction Status", lines=4)
|
| 17 |
|
| 18 |
+
extract_button = gr.Button("Start Extraction")
|
| 19 |
+
extract_button.click(fn=process_video, inputs=[video_input], outputs=[output])
|
| 20 |
|
| 21 |
demo.launch()
|
backend/video_processor.py
CHANGED
|
@@ -8,6 +8,9 @@ def extract_frames(video_path, output_dir='frames', every_n_sec=1):
|
|
| 8 |
os.makedirs(save_path, exist_ok=True)
|
| 9 |
|
| 10 |
cap = cv2.VideoCapture(video_path)
|
|
|
|
|
|
|
|
|
|
| 11 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 12 |
interval = max(1, int(fps * every_n_sec))
|
| 13 |
frame_idx = 0
|
|
@@ -18,8 +21,8 @@ def extract_frames(video_path, output_dir='frames', every_n_sec=1):
|
|
| 18 |
if not ret:
|
| 19 |
break
|
| 20 |
if frame_idx % interval == 0:
|
| 21 |
-
|
| 22 |
-
cv2.imwrite(
|
| 23 |
saved += 1
|
| 24 |
frame_idx += 1
|
| 25 |
|
|
|
|
| 8 |
os.makedirs(save_path, exist_ok=True)
|
| 9 |
|
| 10 |
cap = cv2.VideoCapture(video_path)
|
| 11 |
+
if not cap.isOpened():
|
| 12 |
+
raise ValueError("Failed to open video.")
|
| 13 |
+
|
| 14 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 15 |
interval = max(1, int(fps * every_n_sec))
|
| 16 |
frame_idx = 0
|
|
|
|
| 21 |
if not ret:
|
| 22 |
break
|
| 23 |
if frame_idx % interval == 0:
|
| 24 |
+
filename = os.path.join(save_path, f"frame_{saved:04d}.jpg")
|
| 25 |
+
cv2.imwrite(filename, frame)
|
| 26 |
saved += 1
|
| 27 |
frame_idx += 1
|
| 28 |
|
requirements.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
gradio==4.
|
| 2 |
opencv-python
|
|
|
|
| 1 |
+
gradio==4.24.0
|
| 2 |
opencv-python
|