The function below is written by me in an app that lets you merge 2 or more video clips together, so I used a text box in the GUI, it asks you how many clips you want to merge, and will do it for you accordingly, however, it looks really messy and it is so repetitive.
def merge_vid():
number_of_videos = box.get()
if number_of_videos <= "1":
messagebox.showwarning(title="Warning", message="Please specify how many videos you want to merge.")
elif number_of_videos == "2":
clip1 = VideoFileClip(f"{open_location()}.mp4")
clip2 = VideoFileClip(f"{open_location()}.mp4")
final_clip = concatenate_videoclips([clip1, clip2])
final_clip.write_videofile('Final.mp4', codec="libx264")
elif number_of_videos == "3":
clip1 = VideoFileClip(f"{open_location()}.mp4")
clip2 = VideoFileClip(f"{open_location()}.mp4")
clip3 = VideoFileClip(f"{open_location()}.mp4")
final_clip = concatenate_videoclips([clip1, clip2, clip3])
final_clip.write_videofile('Final.mp4', codec="libx264")
elif number_of_videos == "4":
clip1 = VideoFileClip(f"{open_location()}.mp4")
clip2 = VideoFileClip(f"{open_location()}.mp4")
clip3 = VideoFileClip(f"{open_location()}.mp4")
clip4 = VideoFileClip(f"{open_location()}.mp4")
final_clip = concatenate_videoclips([clip1, clip2, clip3, clip4])
final_clip.write_videofile('Final.mp4', codec="libx264")
Here's the entire code:
import tkinter
from moviepy.editor import *
from tkinter import *
from tkinter import messagebox
from tkinter import ttk
from tkinter import filedialog
import threading
import requests
import os
from tkinter.filedialog import askopenfilename
def space():
space = Label(text="", bg="black")
space.pack()
def open_location():
global filename_splitted
filename = askopenfilename()
filename_ext = os.path.splitext(filename)
filename_splitted = str(filename_ext).split('/')[4].split(".")[0].split(',')[0].split("'")[0]
filename_ext_split = filename_ext[1][1:]
if len(filename) > 1 and filename_ext_split == "mp4":
path_url.config(text=filename_splitted, fg="green")
else:
messagebox.showwarning(title="oops", message="No video given!")
path_url.config(text="Please specify a file (mp4)!", fg="red")
return filename_splitted
def merge_vid():
number_of_videos = box.get()
video_title = title_box.get()
if number_of_videos <= "1":
messagebox.showwarning(title="Warning", message="Please specify how many videos you want to merge.")
elif video_title == "":
messagebox.showwarning(title="Warning", message="Please give your clip a title..")
elif number_of_videos == "2":
clip1 = VideoFileClip(f"{open_location()}.mp4")
clip2 = VideoFileClip(f"{open_location()}.mp4")
final_clip = concatenate_videoclips([clip1, clip2])
final_clip.write_videofile(f'{video_title}.mp4', codec="libx264")
elif number_of_videos == "3":
clip1 = VideoFileClip(f"{open_location()}.mp4")
clip2 = VideoFileClip(f"{open_location()}.mp4")
clip3 = VideoFileClip(f"{open_location()}.mp4")
final_clip = concatenate_videoclips([clip1, clip2, clip3])
final_clip.write_videofile('Final.mp4', codec="libx264")
elif number_of_videos == "4":
clip1 = VideoFileClip(f"{open_location()}.mp4")
clip2 = VideoFileClip(f"{open_location()}.mp4")
clip3 = VideoFileClip(f"{open_location()}.mp4")
clip4 = VideoFileClip(f"{open_location()}.mp4")
final_clip = concatenate_videoclips([clip1, clip2, clip3, clip4])
final_clip.write_videofile('Final.mp4', codec="libx264")
def put_music():
# audio = AudioFileClip("Music.mp3")
# video1 = VideoFileClip("Final.mp4")
# final = video1.set_audio(audio)
# final.write_videofile("output.mp4")
pass
root = Tk()
space()
space()
# root.iconbitmap("yt.ico")
root.title("Video Editor")
root.geometry("350x350")
root.columnconfigure(0, weight=1)
root.config(bg="black")
# space()
# path_btn = Button(root, width=11, height=2, bg="#CC1B25", fg="white", text="Select Video", command=open_location)
# path_btn.pack()
space()
space()
space()
label = Label(root, text="How many videos do you want to merge:", bg="black", fg="white", font=("jost", 9, "bold"))
label.pack()
EntryVar = StringVar()
box = Entry(root, width=7, textvariable=EntryVar)
box.pack()
space()
title = Label(root, text="Name your merged video clip:", bg="black", fg="white", font=("jost", 9, "bold"))
title.pack()
EntryVar = StringVar()
title_box = Entry(root, width=17, textvariable=EntryVar)
title_box.pack()
space()
merge_btn = Button(root, width=27, height=3, bg="green", fg="white", text="Choose and Merge Videos", command=merge_vid)
merge_btn.pack()
space()
space()
# start_merge_btn = Button(root, width=27, height=3, bg="green", fg="white", text="Start Merge", command=start_merge)
# start_merge_btn.pack()
path_url = Label(root, text="", fg="red", bg="black", font=("jost", 9, "bold"))
path_url.pack()
root.mainloop()
moviepy
module and UI "FileChooser" functionopen_location()
is defined. \$\endgroup\$.exe
from an anonymous dropbox account seems very sketchy and is not something I'll be running. It's more safe and commonplace to require that users have ffmpeg beforehand, or prompt them to install it through a trusted package manager. \$\endgroup\$