From: James Bunton Date: Sat, 6 Sep 2008 13:30:37 +0000 (+1000) Subject: Generified things. X-Git-Url: https://code.delx.au/transcoding/commitdiff_plain/405b4a133f62143a89b6382bfee244d80550b562 Generified things. --- diff --git a/encode.py b/encode.py index 67c3f19..7d24e10 100755 --- a/encode.py +++ b/encode.py @@ -2,16 +2,15 @@ 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 @@ -44,7 +43,7 @@ class Command(object): 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 @@ -54,24 +53,21 @@ class Command(object): 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", @@ -80,6 +76,7 @@ profiles = { "xvid" : Profile( + CommandClass=MencoderCommand, vcodec="xvid", vopts="bitrate=%(vbitrate)d:vhq=4:autoaspect", acodec="mp3lame", @@ -89,12 +86,14 @@ profiles = { } + + 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") @@ -110,7 +109,7 @@ def parse_args(): 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) @@ -128,11 +127,11 @@ def main(): 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)