]> code.delx.au - transcoding/commitdiff
Better batch encoder
authorJames Bunton <jamesbunton@fastmail.fm>
Wed, 19 Mar 2008 05:57:16 +0000 (16:57 +1100)
committerJames Bunton <jamesbunton@fastmail.fm>
Wed, 19 Mar 2008 05:57:16 +0000 (16:57 +1100)
batchencode.sh [deleted file]
batchrun.py [new file with mode: 0755]

diff --git a/batchencode.sh b/batchencode.sh
deleted file mode 100755 (executable)
index 2e849df..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/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
-
-
-encoder="$1"
-input="$2"
-if [ -z "$input" ]; then
-       echo "Usage: $0 toh264.py 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 "$encoder" $options $specopts "$in" "$out"
-done
-
diff --git a/batchrun.py b/batchrun.py
new file mode 100755 (executable)
index 0000000..b8596ac
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+import optparse, shlex, subprocess, sys
+
+def parseArgs():
+       parser = optparse.OptionParser(usage="%prog batchfile1 [batchfile2] ...")
+       opts, args = parser.parse_args(sys.argv[1:])
+       return args
+
+def run(args):
+       subprocess.Popen(args).wait()
+
+def batchProcess(fd):
+       opts = [[], []]
+       for line in fd:
+               args = shlex.split(line)
+               if line.startswith("\t\t"):
+                       run(opts[0] + opts[1] + args)
+               elif line.startswith("\t"):
+                       opts[1] = args
+               else:
+                       opts[0] = args
+
+def main():
+       args = parseArgs()
+       for name in args:
+               batchProcess(open(name))
+
+if __name__ == "__main__":
+       main()
+