Skip to content

Instantly share code, notes, and snippets.

@spolo96
Last active September 22, 2022 16:52
Show Gist options
  • Save spolo96/47eea188508b5cb4f8a2b4cf9150c1dc to your computer and use it in GitHub Desktop.
Save spolo96/47eea188508b5cb4f8a2b4cf9150c1dc to your computer and use it in GitHub Desktop.
A script to automatically traverse each folder containing daily videos (presumably, daily gaming videos) in order to concatenate them into a single video for each folder in order to properly share each video to Youtube, Instagram, Facebook etc.
# Automatic Video Compressor (All Folders Version)
# Script to Traverse Folders and create videos separately.
# Imports
import os
from natsort import natsorted
import glob
import ffmpeg # Remember to install ffmpeg in your PC!
from datetime import date, timedelta
from tqdm import tqdm
from moviepy.editor import *
today = date.today()
# Get Date in NVidia GeForce Experience Format (Year.Month.Day) E.g: 2022.04.03
pattern = today.strftime("%Y.%m.%d")
# The root directory should be your path where you have a folder for each group of videos.
rootDir = '.'
for dirName, subdirList, fileList in os.walk(rootDir):
print('Found directory: %s' % dirName)
videos_to_create = []
for fname in fileList:
print('\t%s' % fname)
if fname.endswith('.mp4'):
videos_to_create.append(fname)
filtered = filter(lambda element: pattern in element, videos_to_create)
videos_to_create = list(filtered)
if len(videos_to_create) > 0:
print("I should create a BIG video using the contents of: ")
print(videos_to_create)
os.chdir(dirName)
# Procedure to create videos.
videoclips = [VideoFileClip(i) for i in videos_to_create]
final_video = concatenate_videoclips(videoclips)
output_video_name = "Automatic "+videos_to_create[0].split(pattern)[0]+pattern+" videos" # Create Output Name to differentiate videos
# writing the video into a file / saving the combined video
final_video.write_videofile(output_video_name+".mp4")
# End of procedure to create videos.
os.chdir('../')
print("Automatic Video Concatenation (For all Folders) Complete")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment