--- /dev/null
+#!/bin/bash
+
+# Command line options
+INPUT=$1
+OUTPUT_DIR=$2
+
+# Recommended min quality for 1080p HD = 22
+# Quality 17 ~ 30% of the original size
+# Quality 18 ~ 25% of the original size
+# Quality 20 ~ 15% of the original size
+QUALITY=18
+
+if [ -z "$INPUT" ]; then
+ echo "Usage: $0 input outputdir"
+ exit 1
+fi
+
+if [ -z "$OUTPUT_DIR" ]; then
+ OUTPUT_DIR="."
+fi
+
+FILENAME=`basename "${INPUT%.*}"`
+OUTPUT="$OUTPUT_DIR/$FILENAME.mkv"
+
+# We want our audio to be pass-through, so detect what the audio of the input is encoded with, and tell handbrake to make the output match
+AUDIO_CODEC=`avconv -i "$INPUT" 2>&1 | grep "Audio" | sed -r -e 's/.*?Audio: (\S+),.*?/\1/'`
+if [ -z "$AUDIO_CODEC" ]; then
+ echo "-E- Unable to determine audio codec to use for the input video: $INPUT"
+ exit 1
+fi
+AUDIO_ENC="copy:$AUDIO_CODEC"
+
+echo "-> Converting \"$INPUT\" to 1080p compressed \"$OUTPUT\" file using audio codec $AUDIO_CODEC"
+
+if [[ -e "$OUTPUT" ]]; then
+ echo "-E- Output file $OUTPUT already exists. Aborting..."
+ exit 1
+fi
+
+HandBrakeCLI -i "$INPUT" -o "$OUTPUT" -f mkv --denoise="weak" -e x264 -q $QUALITY -x b-adapt=2:rc-lookahead=50 -v 2 -E $AUDIO_ENC -a 1 -6 dpl2 --strict-anamorphic --crop 0:0:0:0 --preset="High Profile"
+