Spaces:
Runtime error
Runtime error
init commit
Browse files- app.py +43 -0
- parrot.mp4 +0 -0
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
|
4 |
+
def process_video(input_video):
|
5 |
+
cap = cv2.VideoCapture(input_video)
|
6 |
+
|
7 |
+
output_path = "output.mp4"
|
8 |
+
|
9 |
+
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
10 |
+
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
11 |
+
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
12 |
+
|
13 |
+
video = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height))
|
14 |
+
|
15 |
+
iterating, frame = cap.read()
|
16 |
+
while iterating:
|
17 |
+
|
18 |
+
# flip frame vertically
|
19 |
+
frame = cv2.flip(frame, 0)
|
20 |
+
display_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
21 |
+
|
22 |
+
video.write(frame)
|
23 |
+
yield display_frame, None
|
24 |
+
|
25 |
+
iterating, frame = cap.read()
|
26 |
+
|
27 |
+
video.release()
|
28 |
+
yield display_frame, output_path
|
29 |
+
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
with gr.Row():
|
32 |
+
input_video = gr.Video(label="input")
|
33 |
+
processed_frames = gr.Image(label="last frame")
|
34 |
+
output_video = gr.Video(label="output")
|
35 |
+
|
36 |
+
with gr.Row():
|
37 |
+
examples = gr.Examples(["parrot.mp4"], inputs=input_video)
|
38 |
+
process_video_btn = gr.Button("process video")
|
39 |
+
|
40 |
+
process_video_btn.click(process_video, input_video, [processed_frames, output_video])
|
41 |
+
|
42 |
+
demo.queue()
|
43 |
+
demo.launch()
|
parrot.mp4
ADDED
Binary file (900 kB). View file
|
|