Doubleupai commited on
Commit
783ef89
·
verified ·
1 Parent(s): acf770e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +90 -5
app.py CHANGED
@@ -1,5 +1,90 @@
1
- gradio>=3.0
2
- moviepy>=1.0.3
3
- numpy>=1.21.0
4
- imageio>=2.9.0
5
- imageio-ffmpeg>=0.4.7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip, concatenate_videoclips, vfx, afx
3
+
4
+ def process_video(video_path, tool, text=None, start_time=0, end_time=None, speed=1.0, volume=1.0, color=(255, 255, 255), fontsize=50):
5
+ clip = VideoFileClip(video_path)
6
+
7
+ if tool == "Trim":
8
+ clip = clip.subclip(start_time, end_time)
9
+ elif tool == "Speed up":
10
+ clip = clip.fx(vfx.speedx, speed)
11
+ elif tool == "Slow down":
12
+ clip = clip.fx(vfx.speedx, 1/speed)
13
+ elif tool == "Add text":
14
+ txt_clip = TextClip(text, fontsize=fontsize, color=color)
15
+ txt_clip = txt_clip.set_position('center').set_duration(clip.duration)
16
+ clip = CompositeVideoClip([clip, txt_clip])
17
+ elif tool == "Volume up":
18
+ clip = clip.fx(afx.volumex, volume)
19
+ elif tool == "Volume down":
20
+ clip = clip.fx(afx.volumex, 1/volume)
21
+ elif tool == "Black and White":
22
+ clip = clip.fx(vfx.blackwhite)
23
+ elif tool == "Invert colors":
24
+ clip = clip.fx(vfx.invert_colors)
25
+ elif tool == "Mirror":
26
+ clip = clip.fx(vfx.mirror_x)
27
+ elif tool == "Flip vertically":
28
+ clip = clip.fx(vfx.mirror_y)
29
+ elif tool == "Rotate":
30
+ clip = clip.fx(vfx.rotate, 90)
31
+ elif tool == "Fade in":
32
+ clip = clip.fx(vfx.fadein, 2)
33
+ elif tool == "Fade out":
34
+ clip = clip.fx(vfx.fadeout, 2)
35
+ elif tool == "Crop":
36
+ clip = clip.crop(x1=100, y1=100, x2=400, y2=400)
37
+ elif tool == "Resize":
38
+ clip = clip.resize(height=360)
39
+ elif tool == "Loop":
40
+ clip = concatenate_videoclips([clip, clip])
41
+ elif tool == "Reverse":
42
+ clip = clip.fx(vfx.time_mirror)
43
+ elif tool == "Add audio":
44
+ audio_clip = afx.audio_loop(clip.audio, duration=clip.duration)
45
+ clip = clip.set_audio(audio_clip)
46
+ elif tool == "Remove audio":
47
+ clip = clip.without_audio()
48
+
49
+ output_path = "output.mp4"
50
+ clip.write_videofile(output_path, codec="libx264")
51
+ return output_path
52
+
53
+ tools = [
54
+ "Trim", "Speed up", "Slow down", "Add text", "Volume up",
55
+ "Volume down", "Black and White", "Invert colors", "Mirror",
56
+ "Flip vertically", "Rotate", "Fade in", "Fade out", "Crop",
57
+ "Resize", "Loop", "Reverse", "Add audio", "Remove audio"
58
+ ]
59
+
60
+ interface = gr.Interface(
61
+ fn=process_video,
62
+ inputs=[
63
+ gr.Video(label="Input Video"),
64
+ gr.Dropdown(label="Tool", choices=tools),
65
+ gr.Textbox(label="Text", visible=False),
66
+ gr.Number(label="Start Time (s)", visible=False),
67
+ gr.Number(label="End Time (s)", visible=False),
68
+ gr.Number(label="Speed", visible=False),
69
+ gr.Number(label="Volume", visible=False),
70
+ gr.ColorPicker(label="Text Color", visible=False),
71
+ gr.Number(label="Font Size", visible=False)
72
+ ],
73
+ outputs=gr.Video(label="Output Video"),
74
+ live=False,
75
+ title="MoviePy Video Editor",
76
+ description="Edit your video using various tools from MoviePy."
77
+ )
78
+
79
+ def update_interface(tool):
80
+ return [
81
+ gr.Textbox(visible=tool == "Add text"),
82
+ gr.Number(visible=tool in ["Trim", "Speed up", "Slow down"]),
83
+ gr.Number(visible=tool in ["Trim"]),
84
+ gr.Number(visible=tool in ["Speed up", "Slow down"]),
85
+ gr.Number(visible=tool in ["Volume up", "Volume down"]),
86
+ gr.ColorPicker(visible=tool == "Add text"),
87
+ gr.Number(visible=tool == "Add text")
88
+ ]
89
+
90
+ interface.launch()