Skip to content

Instantly share code, notes, and snippets.

@Jpunt
Last active January 1, 2016 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jpunt/8194971 to your computer and use it in GitHub Desktop.
Save Jpunt/8194971 to your computer and use it in GitHub Desktop.
A tiny bit of ZSH and Handbrake-magic to encode DVD's into mp4's
#!/usr/bin/env zsh
#
# Turns ISO-files and VIDEO_TS-directories from $encode_path into decent H264-encoded mp4's (audio/subtitle-tracks are included).
#
# Requirements:
# - ZSH
# - HandBrakeCLI
encode_path=~/Desktop/Encode
handbrake_path=/usr/bin/HandBrakeCLI
function encode () {
echo "---------------------------"
from=$1
to=$2
echo "Encode \"$from\" to \"$to\""
if [ -f $to ]
then
echo "Encoded file already exists"
else
$handbrake_path -i "$from" -o "$to" --main-feature --min-duration 1800 --audio 1,2,3,4,5 --subtitle 1,2,3,4,5 --crop 0:0:0:0 --preset 'High Profile' --x264-tune film
fi
}
set -o extended_glob
iso_files=($encode_path/**/*.(#i)iso(N))
video_ts_dirs=($encode_path/**/VIDEO_TS(N))
for iso_file in "${iso_files[@]}"
do
encode $iso_file ${iso_file/.(#i)iso/.mp4}
done
for video_ts_dir in "${video_ts_dirs[@]}"
do
encode $video_ts_dir ${video_ts_dir/\/VIDEO_TS/.mp4}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment