#!/usr/bin/python import os, sys #test for incorrect usage usage_str = "Correct usage: mov2theora [--rotate=cw/ccw] [--nosound]" if ((len(sys.argv) < 2) or (len(sys.argv) > 4)): print usage_str sys.exit(3) if (sys.argv[1] == "--help"): print usage_str sys.exit(4) args = sys.argv[:] del args[1] #remove target directory from arguments being evaluated for x in args: if (x.count("mov2theora") > 0): rotate = 0 sound = True elif (x == "--rotate=cw"): rotate = 1 elif (x == "--rotate=ccw"): rotate = 2 elif (x == "--nosound"): sound=False else: print "Error: Incorrect usage" print usage_str sys.exit(5) #omit trailing / in target directory if (sys.argv[1][len(sys.argv[1])-1] == '/'): sys.argv[1] = sys.argv[1][0:len(sys.argv[1])-1] #one time actions files = os.listdir(sys.argv[1]) #for every file in target directory for x in files: #ignore non-mov files if ((x[len(x)-4:len(x)] != '.mov') and (x[len(x)-4:len(x)] != '.MOV')): continue; loc = sys.argv[1] + "/" + x if (os.path.isfile(loc) == False): print loc, " - Not a file" continue; #transcode files to avi target = sys.argv[1] + "/" + x[0:len(x)-4] + ".avi" str1 = "ffmpeg -i " + loc + " -acodec pcm_u8 -b 5000k " + target print str1 os.system(str1) #rotate file cw or ccw #CW: mencoder -vf rotate=1 -ovc lavc -oac copy mov00328.mpg -o ronaldo.avi #CCW: mencoder -vf rotate=2 -o OUTPUT.AVI -oac copy -ovc lavc INPUT.AVI target2 = target[0:len(target)-4] + "2" + ".avi" str2 = "" if (rotate == 1): str2 = "mencoder -vf rotate=1 -ovc lavc -oac copy " + target + " -o r" + target2 print str2 if (rotate == 2): str2 = "mencoder -vf rotate=2 -ovc lavc -oac copy " + target + " -o " + target2 print str2 os.system(str2) #encode file as ogg theora str3 = "ffmpeg2theora " if (sound == False): str3 += "--nosound " if (rotate == 0): str3 += target else: str3 += target2 + " -o " + target[0:len(target)-4] + ".ogg" print str3 os.system(str3) #delete temporary file(s) if (rotate == 0): str4 = "rm -rf " + target else: str4 = "rm -rf " + target + " " + target2 print str4 os.system(str4)