File size: 1,102 Bytes
b3f2673
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87eb09c
 
 
 
b3f2673
 
 
 
6377b99
b3f2673
 
 
1
2
3
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
import os
from uuid import uuid4
import gradio as gr
from moviepy.editor import VideoFileClip, concatenate_videoclips

def concatenate(video_clip_paths, output_path, method="compose"):
    clips = [VideoFileClip(c) for c in video_clip_paths]
    if method == "reduce":
        min_height = min([c.h for c in clips])
        min_width = min([c.w for c in clips])
        clips = [c.resize(newsize=(min_width, min_height)) for c in clips]
        final_clip = concatenate_videoclips(clips)
    elif method == "compose":
        final_clip = concatenate_videoclips(clips, method="compose")
    final_clip.write_videofile(output_path)

def merge(dubbed_video, end_video):
    outpath = f"{uuid4()}.mp4"
    video_clip_paths = [dubbed_video, end_video]
    concatenate(video_clip_paths, outpath)
    return outpath

input_video_file = gr.Video(label="Upload video")
end_video_file = gr.Video(label="End video", value="end.mp4")

interface = gr.Interface(merge, [input_video_file, end_video_file], gr.Video(label="Output Video"), title="Merge Videos")

if __name__=="__main__":
    interface.queue().launch()