Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Converts all video from a folder to much smaller ones in another folder
import os
from glob import glob
from moviepy.editor import *
from tkinter import Tk
from tkinter.filedialog import askdirectory
from include.colors import Colors
def get_filename(file_path):
return file_path.split(os.sep)[-1]
title = "Please select input folder"
input_folder = askdirectory(title=title)
assert input_folder
title = title.replace("input", "output")
output_folder = askdirectory(title=title)
assert output_folder
out_files = glob(f"{output_folder}\\*")
out_filenames = [get_filename(a) for a in out_files]
for in_file in glob(f"{input_folder}\\*"):
filename = get_filename(in_file)
if filename not in out_filenames:
new_path = os.sep.join([output_folder, filename])
print(f"Will write:\t{}\nto:\t\t\t{}")
video = VideoFileClip(in_file)
video.write_videofile(new_path, bitrate="500k", verbose=False, threads=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment