X-Git-Url: https://code.delx.au/transcoding/blobdiff_plain/703ccfd29eef2cb5e5553842c9973590398b8760..9029d557cf4b0bdf0c25b45eb07d1bd043ced007:/encode.py diff --git a/encode.py b/encode.py index 28767bf..42e5816 100755 --- a/encode.py +++ b/encode.py @@ -1,16 +1,30 @@ #!/usr/bin/env python -import commands import optparse +import re import subprocess import sys import os -import tempfile import shutil +import tempfile class FatalException(Exception): pass +def mkarg(arg): + if re.match("^[a-zA-Z0-9\-\\.,/@_:=]*$", arg): + return arg + + if "'" not in arg: + return "'%s'" % arg + out = "\"" + for c in arg: + if c in "\\$\"`": + out += "\\" + out += c + out += "\"" + return out + class Command(object): def __init__(self, profile, opts): self.profile = profile @@ -33,7 +47,7 @@ class Command(object): def do_exec(self, args): if self.opts.dump: - print "".join(map(commands.mkarg, args))[1:] + print " ".join(map(mkarg, args)) else: if subprocess.Popen(args).wait() != 0: raise FatalException("Failure executing command: %s" % args) @@ -179,7 +193,7 @@ profiles = { Profile( commands=[Mencoder, MKVMerge], vcodec="x264", - vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:subq=6:frameref=6:me=umh:partitions=all:bframes=4:b_adapt:qcomp=0.7:keyint=250:threads=2", + vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:subq=6:frameref=6:me=umh:partitions=all:bframes=4:b_adapt:qcomp=0.7:keyint=250", acodec="mp3lame", aopts="abr:br=%(abitrate)d", ), @@ -337,7 +351,7 @@ def main(): command.run() except FatalException, e: - print >>sys.stderr, "Error:", e.message + print >>sys.stderr, "Error:", str(e) sys.exit(1) finally: