#!/usr/bin/env python import os, sys from subprocess import call if len(sys.argv) == 1: print "Usage: python main.py folder1/ folder2/" sys.exit(0) else: os.chdir(sys.argv[1]) files = os.listdir('.') newFiles = [] for file in files: file = file.split('.') file[len(file) - 1] = 'mp4' newFiles.append(str.join('.', file)) for i, file in enumerate(files): call('/usr/bin/HandBrakeCLI -f av_mp4 -O -e x264 -E av_aac -vfr -P -U -i ' + file + ' -o ' + newFiles[i], shell=True) print file + ' done.' print 'All done.'