Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from uuid import uuid4
|
3 |
+
import gradio as gr
|
4 |
+
from moviepy.editor import VideoFileClip, concatenate_videoclips
|
5 |
+
from tempfile import TemporaryDirectory
|
6 |
+
|
7 |
+
def concatenate(video_clip_paths, output_path, method="compose"):
|
8 |
+
clips = [VideoFileClip(c) for c in video_clip_paths]
|
9 |
+
if method == "reduce":
|
10 |
+
min_height = min([c.h for c in clips])
|
11 |
+
min_width = min([c.w for c in clips])
|
12 |
+
clips = [c.resize(newsize=(min_width, min_height)) for c in clips]
|
13 |
+
final_clip = concatenate_videoclips(clips)
|
14 |
+
elif method == "compose":
|
15 |
+
final_clip = concatenate_videoclips(clips, method="compose")
|
16 |
+
final_clip.write_videofile(output_path)
|
17 |
+
|
18 |
+
def merge(dubbed_video, end_video):
|
19 |
+
with TemporaryDirectory() as dir:
|
20 |
+
outpath = os.path.join(dir, f"{uuid4()}.mp4")
|
21 |
+
video_clip_paths = [dubbed_video, end_video]
|
22 |
+
concatenate(video_clip_paths, outpath)
|
23 |
+
return outpath
|
24 |
+
|
25 |
+
input_video_file = gr.Video(label="Upload video")
|
26 |
+
end_video_file = gr.Video(label="End video", value="end.mp4")
|
27 |
+
|
28 |
+
interface = gr.Interface(merge, [input_video_file, end_video_file], gr.Video("Output Video"), title="Merge Videos")
|
29 |
+
|
30 |
+
if __name__=="__main__":
|
31 |
+
interface.queue().launch()
|