#!/usr/bin/env python
-import commands, optparse, subprocess, sys, os, tempfile, shutil
+import commands
+import optparse
+import subprocess
+import sys
+import os
+import tempfile
+import shutil
class MencoderCommand(object):
codec2opts = {
self.profile = profile
self.opts = opts
- def insertOptions(self, cmd):
- def tryOpt(opt, var):
+ def insert_options(self, cmd):
+ def try_opt(opt, var):
if var is not None:
cmd.append(opt)
cmd.append(var)
if self.opts.deinterlace:
cmd += ["-vf-add", "pp=ci"]
- tryOpt("-ss", self.opts.startpos)
- tryOpt("-endpos", self.opts.endpos)
- tryOpt("-dvd-device", self.opts.dvd)
- tryOpt("-chapter", self.opts.chapter)
- tryOpt("-aid", self.opts.audioid)
- tryOpt("-sid", self.opts.subtitleid)
- tryOpt("-vf-add", self.opts.vfilters)
- tryOpt("-af", self.opts.afilters)
-
- def substValues(self, cmd):
+ try_opt("-ss", self.opts.startpos)
+ try_opt("-endpos", self.opts.endpos)
+ try_opt("-dvd-device", self.opts.dvd)
+ try_opt("-chapter", self.opts.chapter)
+ try_opt("-aid", self.opts.audioid)
+ try_opt("-sid", self.opts.subtitleid)
+ try_opt("-vf-add", self.opts.vfilters)
+ try_opt("-af", self.opts.afilters)
+
+ def subst_values(self, cmd, vpass):
subst = {
"vbitrate": self.opts.vbitrate,
"abitrate": self.opts.abitrate,
"input": self.opts.input,
"output": self.opts.output,
+ "vpass": vpass,
}
return [x % subst for x in cmd]
p = self.profile
cmd = []
cmd += ["mencoder", "%(input)s", "-o", "/dev/null"]
- self.insertOptions(cmd)
- cmd += ["-ovc", p.vcodec, self.codec2opts[p.vcodec], "pass=1:"+p.vopts]
+ self.insert_options(cmd)
+ cmd += ["-ovc", p.vcodec, self.codec2opts[p.vcodec], p.vopts]
cmd += ["-oac", "copy"]
- cmd = self.substValues(cmd)
+ cmd = self.subst_values(cmd, vpass=1)
return cmd
def pass2(self):
p = self.profile
cmd = []
cmd += ["mencoder", "%(input)s", "-o", "%(output)s"]
- self.insertOptions(cmd)
- cmd += ["-ovc", p.vcodec, self.codec2opts[p.vcodec], "pass=2:"+p.vopts]
+ self.insert_options(cmd)
+ cmd += ["-ovc", p.vcodec, self.codec2opts[p.vcodec], p.vopts]
cmd += ["-oac", p.acodec, self.codec2opts[p.acodec], p.aopts]
if self.opts.episode_name:
cmd += ["-info", "name='%s'" % self.opts.episode_name]
cmd += self.profile.extra
- cmd = self.substValues(cmd)
+ cmd = self.subst_values(cmd, vpass=2)
return cmd
class Profile(object):
Profile(
CommandClass=MencoderCommand,
vcodec="x264",
- vopts="bitrate=%(vbitrate)d:me=umh:partitions=all:trellis=1:subq=7:bframes=1:direct_pred=auto",
+ vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:me=umh:partitions=all:trellis=1:subq=7:bframes=1:direct_pred=auto",
acodec="faac",
aopts="br=%(abitrate)d:mpeg=4:object=2",
),
Profile(
CommandClass=MencoderCommand,
vcodec="xvid",
- vopts="bitrate=%(vbitrate)d:vhq=4:autoaspect",
+ vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:vhq=4:autoaspect",
acodec="mp3lame",
aopts="abr:br=%(abitrate)d",
extra=["-ffourcc", "DX50"],
),
+
"ipodxvid" :
Profile(
CommandClass=MencoderCommand,
vcodec="xvid",
- vopts="bitrate=%(vbitrate)d:vhq=4:autoaspect:max_bframes=0",
+ vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:vhq=4:autoaspect:max_bframes=0",
acodec="faac",
aopts="br=%(abitrate)d:mpeg=4:object=2",
),
+
"ipod264" :
Profile(
CommandClass=MencoderCommand,
vcodec="x264",
- vopts="bitrate=%(vbitrate)d:vbv_maxrate=1500:vbv_bufsize=2000:nocabac:me=umh:partitions=all:trellis=1:subq=7:bframes=0:direct_pred=auto:level_idc=30:global_header:turbo",
+ vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:vbv_maxrate=1500:vbv_bufsize=2000:nocabac:me=umh:partitions=all:trellis=1:subq=7:bframes=0:direct_pred=auto:level_idc=30:global_header:turbo",
acodec="faac",
aopts="br=%(abitrate)d:mpeg=4:object=2:raw",
- extra=['-of', 'lavf', '-lavfopts', 'format=mp4', '-channels', '2', '-srate', '48000']
+ extra=["-of", "lavf", "-lavfopts", "format=mp4", "-channels", "2", "-srate", "48000"]
),
}
parser.print_usage()
sys.exit(1)
- if '://' not in input:
+ if "://" not in input:
opts.input = os.path.join(os.getcwd(), input)
else:
if opts.dvd:
try:
profile = profiles[opts.profile_name]
except KeyError:
- print >>sys.stderr, "Profile '%s' not found!" % profile_name
+ print >>sys.stderr, "Profile '%s' not found!" % opts.profile_name
sys.exit(1)
tempdir = tempfile.mkdtemp()
if run(cmd.pass1(), opts.dump) == 0 or opts.dump:
run(cmd.pass2(), opts.dump)
finally:
- os.chdir('/')
+ os.chdir("/")
shutil.rmtree(tempdir)
if __name__ == "__main__":