#!/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 25 ~ 75% of the original size (for 1080p/60fps content) # Quality 26 ~ 60% of the original size (for 1080p/60fps content) # Quality 27 ~ 50% of the original size (for 1080p/60fps content) 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 # --deblock # --decomb # --denoise="weak" # deblock=1,1 # subme=10:trellis=2 # 1080i #QUALITY=18 #HandBrakeCLI -i "$INPUT" -o "$OUTPUT" -f mkv --denoise="weak" -e x264 -q $QUALITY -x b-adapt=2:rc-lookahead=120 -v 2 -E $AUDIO_ENC -a 1 -6 dpl2 --strict-anamorphic --crop 0:0:0:0 --preset="High Profile" --decomb # 1080p QUALITY=25 HandBrakeCLI -i "$INPUT" -o "$OUTPUT" -f mkv --denoise="weak" --deblock -e x264 -q $QUALITY -x b-adapt=2:rc-lookahead=120:deblock=1,1:subme=10:trellis=2 -v 2 -E $AUDIO_ENC -a 1 -6 dpl2 --auto-anamorphic --crop 0:0:0:0 --preset="Very Fast 1080p30" --decomb