Last active
July 18, 2023 15:13
-
-
Save ralphcrisostomo/56fc395b1646bd55aeeb2eb442043887 to your computer and use it in GitHub Desktop.
Batch convert videos with HandBrake CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Batch convert videos with HandBrake CLI | |
# By Ralph Crisostomo - 2016.04.17 | |
# | |
# Usage : | |
# 'sudo ./handbrake.sh /source /destination' | |
# | |
# Reference : | |
# https://forum.handbrake.fr/viewtopic.php?f=6&t=19426 | |
# https://gist.github.com/czj/1263872 | |
# https://trac.handbrake.fr/wiki/BuiltInPresets#universal | |
# | |
SOURCE=$1 | |
DESTINATION=$2 | |
# Universal | |
# ref: https://trac.handbrake.fr/wiki/BuiltInPresets#universal | |
# | |
PRESET="--encoder x264 f --quality 20.0 --rate 15 --pfr --audio 1,1 --aencoder faac,copy:ac3 --ab 160,160 -6 dpl2,none --arate Au to,Auto --drc 0.0,0.0 --audio-copy-mask aac,ac3,dtshd,dts,mp3 --audio-fallback ffac3 --format mp4 --maxWidth 720 --maxHeight 576 --loose-anamorphic --modulus 2 --markers --x264-preset fast --h264-profile baseline --h264-level 3.0 --optimize --subtitle 1 --subtitle-burned" | |
while IFS= read -d '' -r ITEM | |
do | |
echo $ITEM | |
FILE=${ITEM##*/} | |
EXT=${ITEM##*.} | |
EXT=$(echo $EXT | tr "[:upper:]" "[:lower:]") | |
OUTPUT="$DESTINATION/${FILE%.*}.$EXT" | |
# Create directory | |
[[ -d $DESTINATION ]] || mkdir -p $DESTINATION | |
echo "" | HandBrakeCLI -i "$ITEM" -o "$OUTPUT" $PRESET | |
done< <(find "$SOURCE" \( -iname '*.mp4' -or -iname '*.avi' -or -iname '*.mkv' -or -iname '*.mts' \) -print0) |
Need quotes around $DESTINATION for folders with spaces
[[ -d "$DESTINATION" ]] || mkdir -p "$DESTINATION"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks @thiDucTran, that's really helpful for me.