Skip to content

Instantly share code, notes, and snippets.

@thepatrick
Created December 12, 2018 09:15
Show Gist options
  • Save thepatrick/d2e56c394fb9cd1a99abe97fb9c44ac5 to your computer and use it in GitHub Desktop.
Save thepatrick/d2e56c394fb9cd1a99abe97fb9c44ac5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
function usage {
echo -e "\nusage: $0 [src_dir] [dest_dir] [tmp_dir]\n"
exit 1
}
if [[ $# != 3 || $@ == "--help" ]]
then
usage
exit 0
fi
src_dir=$1
output_dir=$2
tmp_dir=$3
mkdir -p "${output_dir}"
args=("${src_dir}" -name *.mkv)
find "${args[@]}" | tr '\n' '\0' | xargs -0 ls -rt | (
while read src_file; do
file_name=`basename "${src_file}" ".mkv"`
tmp_src_file="${tmp_dir}/${file_name}.mkv"
tmp_dest_file="${tmp_dir}/${file_name}.m4v"
echo `date` "Copying ${src_file} to ${tmp_src_file}"
cp "${src_file}" "${tmp_src_file}"
echo `date` "Starting handbrake"
dest_file="${output_dir}/${file_name}.m4v"
HandbrakeCLI --input "${tmp_src_file}" --output "${tmp_dest_file}" --preset "Apple 1080p60 Surround" < /dev/null
echo `date` "Copying ${tmp_dest_file} to ${dest_file}"
cp "${tmp_dest_file}" "${dest_file}"
echo `date` "Cleaningup ${tmp_dest_file}"
rm "${tmp_dest_file}"
echo `date` "Cleaningup ${tmp_src_file}"
rm "${tmp_src_file}"
done
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment