#!/bin/bash -e if [ -z "$1" -o -z "$2" ]; then echo "Usage: $0 sourcedir destdir" exit 1 fi sourcedir="$(cd "$1" && pwd)" destdir="$(cd "$2" && pwd)" cd "$sourcedir" find . -type f | while read infile; do if [ ! -r "$infile" ]; then echo "Missing file $infile" exit 1 fi outfile="${destdir}/$(echo "$infile" | sed 's/\.[a-zA-Z0-9]*$//').mp4" if [ -e "$outfile" ]; then echo "Skipping $infile" continue fi mkdir -p "$(dirname "$outfile")" HandBrakeCLI < /dev/null \ --format mp4 \ --encoder x264 \ --encopts cabac=0:ref=2:me=umh:bframes=0:weightp=0:8x8dct=0:trellis=0:subme=6 \ --markers \ --quality 21 \ --deinterlace \ --loose-anamorphic \ --crop 24:24:24:24 \ --aencoder faac \ --ab 160 \ --input "$infile" \ --output "$outfile" done