Skip to content

Instantly share code, notes, and snippets.

@OrganicIrradiation
Created February 8, 2015 13:48
Show Gist options
  • Save OrganicIrradiation/9343ca746807a71693c9 to your computer and use it in GitHub Desktop.
Save OrganicIrradiation/9343ca746807a71693c9 to your computer and use it in GitHub Desktop.
hb_batchconvertvideos
import os
import time
import subprocess
import sys
fileList = []
rootdir = raw_input("Root Dir: ")
for root, subFolders, files in os.walk(rootdir):
for file in files:
theFile = os.path.join(root,file)
fileName, fileExtension = os.path.splitext(theFile)
if fileExtension.lower() in ('.avi', '.divx', '.flv', '.m4v', '.mkv', '.mov', '.mpg', '.mpeg', '.wmv'):
print 'Adding',theFile
fileList.append(theFile)
runstr = '"C:Program FilesHandbrakeHandBrakeCLI.exe" -i "{0}" -o "{1}" --preset="Normal" --two-pass --turbo'
print '=======--------======='
while fileList:
inFile = fileList.pop()
fileName, fileExtension = os.path.splitext(inFile)
outFile = fileName+'.mp4'
print 'Processing',inFile
returncode = subprocess.call(runstr.format(inFile,outFile))
time.sleep(5)
print 'Removing',inFile
os.remove(inFile)
@mahboc
Copy link

mahboc commented Jul 10, 2018

Some OS might need to edit line 26 to be:
returncode = subprocess.call(runstr.format(inFile,outFile), shell=True)

and in Python 3 raw_input () is just input()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment