]> code.delx.au - transcoding/commitdiff
Initial checkin
authorJames Bunton <jamesbunton@fastmail.fm>
Sun, 16 Mar 2008 09:20:14 +0000 (20:20 +1100)
committerJames Bunton <jamesbunton@fastmail.fm>
Sun, 16 Mar 2008 09:20:14 +0000 (20:20 +1100)
batchtoh264.sh [new file with mode: 0755]
toh264.py [new file with mode: 0755]
tomkv.sh [new file with mode: 0755]
tomp4.sh [new file with mode: 0755]

diff --git a/batchtoh264.sh b/batchtoh264.sh
new file mode 100755 (executable)
index 0000000..659d375
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+# inputdesc specification:
+#
+# general options
+# output_file\tinput_file\tspecific_options
+# output_file\tinput_file\tspecific_options
+#
+# Example inputdesc
+# --filters pp=ci,crop=704:576:10:0,scale=768:576,denoise3d,harddup
+# 1x01.avi     dvd://1 --dvd DISC1
+# 1x02.avi     dvd://1 --dvd DISC2
+
+
+input="$1"
+if [ -z "$input" ]; then
+       echo "Usage: $0 inputdesc"
+       exit 1
+fi
+
+# Read the general options
+options="$(head -n 1 "$input")"
+
+# Read each file description
+tail -n +2 "$input" | while read line; do
+       out=$(echo "$line" | cut -d '   ' -f 1)
+       in=$(echo "$line" | cut -d '    ' -f 2)
+       specopts=$(echo "$line" | cut -d '      ' -f 3)
+       nice -n 10 toh264.py $options $specopts "$in" "$out"
+done
+
diff --git a/toh264.py b/toh264.py
new file mode 100755 (executable)
index 0000000..fc5ab1c
--- /dev/null
+++ b/toh264.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+import optparse, subprocess, sys
+
+cmd = [
+       "mencoder", "%(input)s", "-o", "%(output)s",
+       "-ffourcc", "DX50",
+       "-vf", "%(filters)s",
+       "-ovc", "x264", "-x264encopts", "pass=%(pass)d:turbo:bitrate=%(vbitrate)d:bframes=0:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300",
+       "-oac", "faac", "-faacopts", "br=%(abitrate)d:mpeg=4:object=2", "-channels", "2", "-srate", "48000",
+]
+
+parser = optparse.OptionParser(usage="%prog [options] input output")
+parser.add_option("--dvd", action="store", dest="dvd")
+parser.add_option("--filters", action="store", dest="filters", default="denoise3d")
+parser.add_option("--vbitrate", action="store", dest="vbitrate", type="int", default=600)
+parser.add_option("--abitrate", action="store", dest="abitrate", type="int", default=192)
+parser.add_option("--dump", action="store_true", dest="dump")
+try:
+       opts, (input, output) = parser.parse_args(sys.argv[1:])
+except:
+       parser.print_usage()
+       sys.exit(1)
+
+# Start/stop time?
+# Custom dvd device?
+if opts.dvd:
+       cmd.insert(1, opts.dvd)
+       cmd.insert(1, "-dvd-device")
+
+# Default options
+subst = {
+       "vbitrate": opts.vbitrate,
+       "abitrate": opts.abitrate,
+       "filters": opts.filters,
+       "input": input,
+}
+
+def run(args):
+       if opts.dump:
+               print " ".join(args)
+       else:
+               subprocess.Popen(args).wait()
+
+# Pass 1
+subst["pass"] = 1
+subst["output"] = "/dev/null"
+run([x % subst for x in cmd])
+
+# Pass 2
+subst["pass"] = 2
+subst["output"] = output
+run([x % subst for x in cmd])
+
diff --git a/tomkv.sh b/tomkv.sh
new file mode 100755 (executable)
index 0000000..db6ceed
--- /dev/null
+++ b/tomkv.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+input="$1"
+output="$2"
+if [ -z "$input" -o -z "$output" ]; then
+       echo "Usage: $0 infile outfile"
+       exit 1
+fi
+
+mplayer "$input" -dumpvideo -dumpfile tmp.video &&
+mplayer "$input" -dumpaudio -dumpfile tmp.audio &&
+mkvmerge -o "$output" tmp.video tmp.audio &&
+rm -f tmp.video tmp.audio &&
+echo 'Done!'
+
diff --git a/tomp4.sh b/tomp4.sh
new file mode 100755 (executable)
index 0000000..c4877ec
--- /dev/null
+++ b/tomp4.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+input="$1"
+output="$2"
+if [ -z "$input" -o -z "$output" ]; then
+       echo "Usage: $0 infile outfile"
+       exit 1
+fi
+
+mplayer "$input" -dumpvideo -dumpfile tmp.h264 &&
+mplayer "$input" -dumpaudio -dumpfile tmp.aac &&
+mp4creator -create=tmp.h264 -H -rate=25 "$output" &&
+mp4creator -create=tmp.aac -H -I -rate=25 -optimize "$output" &&
+rm -f tmp.aac tmp.h264 &&
+echo 'Done!'
+