Suburst commited on
Commit
9a1a12e
·
verified ·
1 Parent(s): cacabf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -1,7 +1,25 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="video", outputs="video")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import cv2
3
 
4
+ def process_video(video):
5
+ # 打开视频文件
6
+ cap = cv2.VideoCapture(video)
7
+ # 创建一个 VideoWriter 对象以保存处理后的视频
8
+ fourcc = cv2.VideoWriter_fourcc(*'mp4v')
9
+ out = cv2.VideoWriter('output.mp4', fourcc, 20.0, (int(cap.get(3)), int(cap.get(4))))
10
 
11
+ while cap.isOpened():
12
+ ret, frame = cap.read()
13
+ if not ret:
14
+ break
15
+ # 处理帧,例如将其转换为灰度
16
+ gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
17
+ # 将处理后的帧写入输出视频
18
+ out.write(cv2.cvtColor(gray_frame, cv2.COLOR_GRAY2BGR))
19
+
20
+ cap.release()
21
+ out.release()
22
+ return 'output.mp4'
23
+
24
+ demo = gr.Interface(fn=process_video, inputs="video", outputs="video")
25
+ demo.launch()