#!/bin/sh

PRESET=slower

INPUT="$1"
OUTPUT="$1"."$PRESET".mkv


if [ ! -f "$INPUT" ]; then
    echo "Must specify an input file"
    exit
fi

if [ -f "$OUTPUT" ]; then
    echo "Output file $OUTPUT already exists?"
    exit
fi

time ffmpeg -y -i "$INPUT" -c:v libx264 -preset "$PRESET" -crf 18 -c:a copy "$OUTPUT"

# https://trac.ffmpeg.org/wiki/Encode/H.264#FAQ
# https://trac.ffmpeg.org/wiki/Encode/MPEG-4
# http://rodrigopolo.com/ffmpeg/cheats.php
# http://stackoverflow.com/questions/3561715/using-ffmpeg-to-encode-a-high-quality-video

# Original:
#-rw-r--r--+ 1 nocturne  staff  930548876 Aug 15 09:15 testvideo.mp4

# Produced with "-preset veryslow" in 80m34.604s
## 7.8% improvement over "slower"
#-rw-r--r--+ 1 nocturne  staff  421661021 Aug 15 11:09 testvideo.mp4.2pass.mkv

# Produced with "-preset slower" in 36m46.100s
## 4.6% improvement over "medium"
#-rw-r--r--+ 1 nocturne  staff  457373835 Aug 15 11:49 testvideo.mp4.slower.mkv

# Produced with "-preset slow" in 36m20.127s
## 2.2% improvement over "medium"
#-rw-r--r--+ 1 nocturne  staff  468797157 Aug 15 12:49 testvideo.mp4.slow.mkv

# Produced with "-preset medium" in 10m28.189s
#-rw-r--r--+ 1 nocturne  staff  479348545 Aug 15 13:17 testvideo.mp4.medium.mkv
