]> code.delx.au - transcoding/commitdiff
Fixed N97 profile
authorJames Bunton <jamesbunton@fastmail.fm>
Thu, 22 Jul 2010 10:14:16 +0000 (20:14 +1000)
committerJames Bunton <jamesbunton@fastmail.fm>
Thu, 22 Jul 2010 10:14:16 +0000 (20:14 +1000)
 - MP4Box command should now work with video of any framerate
 - Renamed some of the profiles

encode.py

index bac7ce3f19afe275fe51ce7db2533c1207956461..fceca4184fe79d9e40f7bf2b554c0f23b9b5e39f 100755 (executable)
--- a/encode.py
+++ b/encode.py
@@ -67,15 +67,37 @@ class MP4Box(Command):
 
        def run(self):
                p = self.profile
-               video = "video.%s" % self.codec2exts[p.vcodec]
-               audio = "audio.%s" % self.codec2exts[p.acodec]
                input = self.opts.output + ".avi" # From Mencoder command
                output = self.opts.output + ".mp4"
+
+               # Check FPS
+               fps = "???"
+               if not self.opts.dump:
+                       process = subprocess.Popen(
+                               ["mplayer", "-frames", "0", "-identify", input],
+                               stdout=subprocess.PIPE,
+                               stderr=subprocess.PIPE,
+                       )
+                       for line in process.stdout:
+                               try:
+                                       key, value = line.split("=")
+                               except ValueError:
+                                       continue
+                               if key == "ID_VIDEO_FPS":
+                                       fps = value
+
+               # Strip out video & audio
+               video = "video.%s" % self.codec2exts[p.vcodec]
+               audio = "audio.%s" % self.codec2exts[p.acodec]
                mencoder = ["mencoder", input, "-ovc", "copy", "-oac", "copy", "-of"]
                self.do_exec(["rm", "-f", output])
                self.do_exec(mencoder + ["rawvideo", "-o", video])
                self.do_exec(mencoder + ["rawaudio", "-o", audio])
-               self.do_exec(["MP4Box", "-add", video, "-add", audio, output])
+
+               # Mux them back together
+               self.do_exec(["MP4Box", "-add", video, "-add", audio, "-fps", fps, output])
+
+               # Clean up temp files
                self.do_exec(["rm", "-f", video, audio, input])
 
 
@@ -95,7 +117,6 @@ class MKVMerge(Command):
 
 class Mencoder(Command):
        codec2opts = {
-               "lavc": "-lavcopts",
                "xvid": "-xvidencopts",
                "x264": "-x264encopts",
                "faac": "-faacopts",
@@ -121,7 +142,7 @@ class Mencoder(Command):
                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)
+               try_opt("-af-add", self.opts.afilters)
 
        def subst_values(self, cmd, vpass):
                subst = {
@@ -151,7 +172,9 @@ class Mencoder(Command):
                cmd += ["mencoder", "%(input)s", "-o", "%(output)s"]
                self.insert_options(cmd)
                cmd += ["-ovc", p.vcodec, self.codec2opts[p.vcodec], p.vopts]
-               cmd += ["-oac", p.acodec, self.codec2opts[p.acodec], p.aopts]
+               cmd += ["-oac", p.acodec]
+               if "aopts" in p:
+                       cmd += [self.codec2opts[p.acodec], p.aopts]
                if self.opts.episode_name:
                        cmd += ["-info", "name='%s'" % self.opts.episode_name]
                cmd += self.profile.extra2 + self.profile.extra
@@ -185,16 +208,6 @@ class Profile(object):
 
 
 profiles = {
-       "qt7" :
-       Profile(
-               commands=[Mencoder, MP4Box],
-               vcodec="x264",
-               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",
-               extra=["-vf-add", "harddup"],
-       ),
-
        "x264" :
        Profile(
                commands=[Mencoder, MKVMerge],
@@ -215,46 +228,42 @@ profiles = {
                extra2=["-ffourcc", "DX50"],
        ),
 
-       "ipodxvid" :
+       "apple-quicktime" :
        Profile(
                commands=[Mencoder, MP4Box],
-               vcodec="xvid",
-               vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:vhq=4:autoaspect:max_bframes=0",
+               vcodec="x264",
+               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",
-               extra=["-vf-add", "scale=480:-10,harddup"],
+               extra=["-vf-add", "harddup"],
        ),
 
-       "ipodx264" :
+       "ipod-xvid" :
        Profile(
                commands=[Mencoder, MP4Box],
-               vcodec="x264",
-               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:turbo",
+               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=480:-10,harddup"],
-               extra2=["-channels", "2", "-srate", "48000"],
        ),
 
-       "nokiax264" :
+       "ipod-x264" :
        Profile(
                commands=[Mencoder, MP4Box],
-               default_opts={
-                       "vbitrate": 256,
-                       "abitrate": 96,
-               },
                vcodec="x264",
-               vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:nocabac:me=umh:partitions=all:trellis=1:subq=7:bframes=0:direct_pred=auto",
+               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:turbo",
                acodec="faac",
                aopts="br=%(abitrate)d:mpeg=4:object=2",
-               extra=["-vf-add", "scale=320:-10,harddup"],
+               extra=["-vf-add", "scale=480:-10,harddup"],
+               extra2=["-channels", "2", "-srate", "48000"],
        ),
 
-       "n97xvid" :
+       "nokia-n97" :
        Profile(
                commands=[Mencoder, MP4Box],
                default_opts={
-                       "vbitrate": 1000,
+                       "vbitrate": 800,
                        "abitrate": 96,
                },
                vcodec="xvid",
@@ -263,20 +272,6 @@ profiles = {
                aopts="br=%(abitrate)d:mpeg=4:object=2",
                extra=["-vf-add", "scale=640:-10,harddup"],
        ),
-
-       "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,harddup"],
-       ),
 }