clip-merger / app.py
deepsync's picture
Update app.py
87eb09c verified
raw
history blame contribute delete
No virus
1.1 kB
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()