Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bitsandbooks/2dea23eb020e9a017ae1dfa382dffda6 to your computer and use it in GitHub Desktop.
Save bitsandbooks/2dea23eb020e9a017ae1dfa382dffda6 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment