Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Union, Tuple
|
| 5 |
+
|
| 6 |
+
def frame_capture(video_path: str) -> Tuple[str, None]:
|
| 7 |
+
# Function to extract frames
|
| 8 |
+
vidObj = cv2.VideoCapture(video_path)
|
| 9 |
+
|
| 10 |
+
# Used as counter variable
|
| 11 |
+
count = 0
|
| 12 |
+
frames = []
|
| 13 |
+
|
| 14 |
+
# checks whether frames were extracted
|
| 15 |
+
success = 1
|
| 16 |
+
|
| 17 |
+
while success:
|
| 18 |
+
# vidObj object calls read
|
| 19 |
+
# function to extract frames
|
| 20 |
+
success, image = vidObj.read()
|
| 21 |
+
|
| 22 |
+
# Append the frame to the list
|
| 23 |
+
if success:
|
| 24 |
+
frames.append(image)
|
| 25 |
+
count += 1
|
| 26 |
+
|
| 27 |
+
return frames, None
|
| 28 |
+
|
| 29 |
+
def extract_frames(video: str) -> Tuple[str, None]:
|
| 30 |
+
frames, _ = frame_capture(video)
|
| 31 |
+
return frames, None
|
| 32 |
+
|
| 33 |
+
# Define the Gradio interface
|
| 34 |
+
video_input = gr.Video(type='mp4', label="Upload Video", behavior={"type": "local", "renameTo": "*.mp4"})
|
| 35 |
+
output_frames = gr.Image(label='Frame', type='pil')
|
| 36 |
+
|
| 37 |
+
# Create the Gradio app
|
| 38 |
+
gr.Interface(fn=extract_frames, inputs=video_input, outputs=output_frames, title='Video Frame Extractor').launch()
|