import commands
import optparse
+import shlex
import subprocess
import sys
import os
class FatalException(Exception):
pass
+def mkarg(arg):
+ quoted_arg = commands.mkarg(arg)
+ arg = quoted_arg[2:-1]
+ if len(shlex.split(arg)) == 1:
+ return arg
+ else:
+ return quoted_arg[1:]
+
class Command(object):
def __init__(self, profile, opts):
self.profile = profile
return
if subprocess.Popen(["which", cmd], stdout=open("/dev/null", "w")).wait() != 0:
raise FatalException("Command '%s' is required" % cmd)
+
+ def check_no_file(self, path):
+ if os.path.exists(path):
+ raise FatalException("Output file '%s' exists." % path)
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)
def check(self):
self.check_command("mencoder")
self.check_command("MP4Box")
+ self.check_no_file(self.opts.output + ".mp4")
def run(self):
p = self.profile
self.do_exec(["rm", "-f", video, audio, input])
+
+class MKVMerge(Command):
+ def check(self):
+ self.check_command("mkvmerge")
+ self.check_no_file(self.opts.output + ".mkv")
+
+ def run(self):
+ input = self.opts.output + ".avi" # From Mencoder command
+ output = self.opts.output + ".mkv"
+ self.do_exec(["mkvmerge", "-o", output, input])
+ self.do_exec(["rm", "-f", input])
+
+
+
class Mencoder(Command):
codec2opts = {
"lavc": "-lavcopts",
cmd.append(opt)
cmd.append(var)
if self.opts.deinterlace:
- cmd += ["-vf-add", "pp=ci"]
+ cmd += ["-vf-add", "pp=lb"]
try_opt("-ss", self.opts.startpos)
try_opt("-endpos", self.opts.endpos)
try_opt("-dvd-device", self.opts.dvd)
def check(self):
self.check_command("mencoder")
+ self.check_no_file(self.opts.output + ".avi")
def run(self):
self.do_exec(self.pass1())
aopts="br=%(abitrate)d:mpeg=4:object=2",
),
+ "x264" :
+ 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",
+ acodec="mp3lame",
+ aopts="abr:br=%(abitrate)d",
+ ),
+
"xvid" :
Profile(
commands=[Mencoder],
aopts="br=%(abitrate)d:mpeg=4:object=2",
extra=["-vf-add", "scale=320:-10"],
),
+
+ "n97xvid" :
+ Profile(
+ commands=[Mencoder, MP4Box],
+ default_opts={
+ "vbitrate": 1000,
+ "abitrate": 96,
+ },
+ vcodec="xvid",
+ vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:vhq=4:autoaspect:max_bframes=0",
+ acodec="faac",
+ aopts="br=%(abitrate)d:mpeg=4:object=2",
+ extra=["-vf-add", "scale=640:-10"],
+ ),
+
+ "n97x264" :
+ Profile(
+ commands=[Mencoder, MP4Box],
+ default_opts={
+ "vbitrate": 1000,
+ "abitrate": 96,
+ },
+ vcodec="x264",
+ vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:vbv_maxrate=2000:vbv_bufsize=2000:nocabac:me=umh:partitions=all:trellis=1:subq=7:bframes=0:direct_pred=auto:level_idc=20",
+ acodec="faac",
+ aopts="br=%(abitrate)d:mpeg=4:object=2",
+ extra=["-vf-add", "scale=640:-10"],
+ ),
}