Skip to content

Instantly share code, notes, and snippets.

@badjano
Last active December 6, 2021 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badjano/0a7c95048c6fc45b4c06e380dbbca25a to your computer and use it in GitHub Desktop.
Save badjano/0a7c95048c6fc45b4c06e380dbbca25a to your computer and use it in GitHub Desktop.
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]
Tk().withdraw()
title = "Please select input folder"
print(title)
input_folder = askdirectory(title=title)
assert input_folder
title = title.replace("input", "output")
print(title)
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{Colors.orange(in_file)}\nto:\t\t\t{Colors.orange(new_path)}")
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