Skip to content

Instantly share code, notes, and snippets.

@schleumer
Created October 1, 2019 00:31
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 schleumer/894756c71276435ee5cd4d7e1ac2a30b to your computer and use it in GitHub Desktop.
Save schleumer/894756c71276435ee5cd4d7e1ac2a30b to your computer and use it in GitHub Desktop.
import glob2
import os
import re
from shutil import copyfile
fileregex = r'.*\.(avi|mp4|mkv)$'
srtregex = r'.*\.(srt)$'
def ffmpeg(filename):
file = os.path.abspath(filename)
if os.path.isfile(file) and re.match(fileregex, filename):
relfile = os.path.relpath(filename, os.path.abspath('./Source'))
newfilename = re.sub(r'\.(avi|mp4|mkv)$', '.mp4', relfile)
newfile = os.path.abspath(os.path.join(os.path.abspath("./Target"), newfilename))
newdir = os.path.dirname(newfile)
if not os.path.exists(newdir):
os.makedirs(newdir)
if not os.path.exists(newfile):
os.system('ffmpeg -i "' + file + '" -codec:v libx264 -vf "scale=-2:480" "' + newfile + '"')
pass
elif re.match(srtregex, filename):
relfile = os.path.relpath(filename, os.path.abspath('./Source'))
newfile = os.path.abspath(os.path.join(os.path.abspath("./Target"), relfile))
newdir = os.path.dirname(newfile)
if not os.path.exists(newdir):
os.makedirs(newdir)
copyfile(file, newfile)
else:
print(filename)
for filename in glob2.glob('./Source/**/*'):
ffmpeg(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment