import commands, optparse, subprocess, sys
+class MencoderCommand(object):
+ codec2opts = {
+ "lavc": "-lavcopts",
+ "xvid": "-xvidencopts",
+ "x264": "-x264encopts",
+ "faac": "-faaccopts",
+ "mp3lame": "-lameopts",
+ }
-codec2opts = {
- "lavc": "-lavcopts",
- "xvid": "-xvidencopts",
- "x264": "-x264encopts",
- "faac": "-faaccopts",
- "mp3lame": "-lameopts",
-}
-
-class Command(object):
def __init__(self, profile, opts):
self.profile = profile
self.opts = opts
cmd = []
cmd += ["mencoder", "%(input)s", "-o", "/dev/null"]
self.insertOptions(cmd)
- cmd += ["-ovc", p.vcodec, codec2opts[p.vcodec], "pass=1:%s" % p.vopts]
+ cmd += ["-ovc", p.vcodec, self.codec2opts[p.vcodec], "pass=1:"+p.vopts]
cmd += ["-oac", "copy"]
cmd = self.substValues(cmd)
return cmd
cmd = []
cmd += ["mencoder", "%(input)s", "-o", "%(output)s"]
self.insertOptions(cmd)
- cmd += ["-ovc", p.vcodec, codec2opts[p.vcodec], "pass=2:%s" % p.vopts]
- cmd += ["-oac", p.acodec, codec2opts[p.acodec], p.aopts]
+ cmd += ["-ovc", p.vcodec, self.codec2opts[p.vcodec], "pass=2:"+p.vopts]
+ cmd += ["-oac", p.acodec, self.codec2opts[p.acodec], p.aopts]
cmd += self.profile.extra
cmd = self.substValues(cmd)
return cmd
class Profile(object):
- def __init__(self, vcodec, vopts, acodec, aopts, extra=[]):
- self.vcodec = vcodec
- self.vopts = vopts
- self.acodec = acodec
- self.aopts = aopts
- self.extra = extra
-
+ def __init__(self, CommandClass, **kwargs):
+ self.CommandClass = CommandClass
+ self.__dict__.update(kwargs)
profiles = {
"qt7" :
Profile(
+ CommandClass=MencoderCommand,
vcodec="x264",
vopts="bitrate=%(vbitrate)d:me=umh:partitions=all:trellis=1:subq=7:bframes=1:direct_pred=auto",
acodec="faac",
"xvid" :
Profile(
+ CommandClass=MencoderCommand,
vcodec="xvid",
vopts="bitrate=%(vbitrate)d:vhq=4:autoaspect",
acodec="mp3lame",
}
+
+
def parse_args():
for profile_name in profiles.keys():
if sys.argv[0].find(profile_name) >= 0:
break
else:
- profile_name = "qt7"
+ profile_name = "xvid"
parser = optparse.OptionParser(usage="%prog [options] input output")
parser.add_option("--dvd", action="store", dest="dvd")
parser.add_option("--dump", action="store_true", dest="dump")
try:
opts, (input, output) = parser.parse_args(sys.argv[1:])
- except:
+ except Exception:
parser.print_usage()
sys.exit(1)
opts = parse_args()
try:
profile = profiles[opts.profile_name]
- except:
+ except KeyError:
print >>sys.stderr, "Profile '%s' not found!" % profile_name
sys.exit(1)
- cmd = Command(profile, opts)
+ cmd = profile.CommandClass(profile, opts)
if run(cmd.pass1(), opts.dump) == 0 or opts.dump:
run(cmd.pass2(), opts.dump)