Spaces:
Runtime error
Runtime error
Kvikontent
commited on
Commit
•
dbcf8ab
1
Parent(s):
8897375
Update app.py
Browse files
app.py
CHANGED
@@ -1,59 +1,72 @@
|
|
1 |
import gradio as gr
|
2 |
-
from moviepy.editor import
|
3 |
-
from
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
#
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
#
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip
|
3 |
+
from moviepy.video.fx.all import speedx, rotate, multiply_brightness, colorx
|
4 |
+
from moviepy.video.fx.all import lum_contrast
|
5 |
+
|
6 |
+
def video_editor(input_video, start_time, end_time, playback_speed, create_gif,
|
7 |
+
rotation_degrees, watermark_text, brightness_factor,
|
8 |
+
contrast, saturation):
|
9 |
+
|
10 |
+
# Load video
|
11 |
+
clip = VideoFileClip(input_video).subclip(start_time, end_time)
|
12 |
+
|
13 |
+
# Change playback speed if applicable
|
14 |
+
if playback_speed != 1:
|
15 |
+
clip = speedx(clip, factor=playback_speed)
|
16 |
+
|
17 |
+
# Rotate the video if applicable
|
18 |
+
if rotation_degrees != 0:
|
19 |
+
clip = rotate(clip, rotation_degrees)
|
20 |
+
|
21 |
+
# Adjust brightness if applicable
|
22 |
+
if brightness_factor != 1:
|
23 |
+
clip = multiply_brightness(clip, brightness_factor)
|
24 |
+
|
25 |
+
# Adjust contrast if applicable
|
26 |
+
if contrast != 1:
|
27 |
+
clip = lum_contrast(clip, contrast=contrast - 1)
|
28 |
+
|
29 |
+
# Adjust color saturation if applicable
|
30 |
+
if saturation != 1:
|
31 |
+
clip = colorx(clip, factor=saturation)
|
32 |
+
|
33 |
+
# Add text watermark if applicable
|
34 |
+
if watermark_text:
|
35 |
+
txt_clip = TextClip(watermark_text, fontsize=24, color='white', bg_color='black')
|
36 |
+
txt_clip = txt_clip.set_position(('right', 'bottom')).set_duration(clip.duration)
|
37 |
+
clip = CompositeVideoClip([clip, txt_clip])
|
38 |
+
|
39 |
+
# Define output paths
|
40 |
+
output_video_path = "edited_video.mp4"
|
41 |
+
output_gif_path = "edited_video.gif"
|
42 |
+
|
43 |
+
if not create_gif:
|
44 |
+
# Write video file with the edits
|
45 |
+
clip.write_videofile(output_video_path, codec="libx264", audio_codec="aac")
|
46 |
+
return output_video_path
|
47 |
+
else:
|
48 |
+
# Write GIF file with the edits
|
49 |
+
clip.write_gif(output_gif_path)
|
50 |
+
return output_gif_path
|
51 |
+
|
52 |
+
iface = gr.Interface(
|
53 |
+
fn=video_editor,
|
54 |
+
inputs=[
|
55 |
+
gr.Video(source="upload", type="file", label="Input Video"),
|
56 |
+
gr.Textbox(value="00:00:00", label="Start Time (HH:MM:SS)"),
|
57 |
+
gr.Textbox(value="00:00:10", label="End Time (HH:MM:SS)"),
|
58 |
+
gr.Slider(minimum=0.25, maximum=4.0, value=1, step=0.25, label="Playback Speed"),
|
59 |
+
gr.Checkbox(label="Create GIF instead of video", value=False),
|
60 |
+
gr.Slider(minimum=0, maximum=360, value=0, step=90, label="Rotation (Degrees)"),
|
61 |
+
gr.Textbox(value="", label="Watermark Text"),
|
62 |
+
gr.Slider(minimum=0.5, maximum=2.0, value=1, step=0.1, label="Brightness Factor"),
|
63 |
+
gr.Slider(minimum=0.1, maximum=2.0, value=1, step=0.1, label="Contrast"),
|
64 |
+
gr.Slider(minimum=0, maximum=2.0, value=1, step=0.1, label="Saturation")
|
65 |
+
],
|
66 |
+
outputs=gr.Video(label="Output Video/GIF"),
|
67 |
+
examples=[
|
68 |
+
["sample_video.mp4", "00:00:02", "00:00:05", 1, False, 0, "", 1, 1, 1],
|
69 |
+
]
|
70 |
+
)
|
71 |
+
|
72 |
+
iface.launch()
|