M HYPE SPLASH
// general

Handbrake batch convert script assistance to set output extension specified by the official presets

By Sarah Scott

With the help of numerous discussions on SE network and other places I finally managed to a working script that works well except the Matroska presets. I understand the problem is the script itself, since it specifies destination extension as MP4.

I am zero experienced with bash and couldn't figure out how to improve the script so instead of pre-setting the output extension, it will take extensions as specified by the official presets.

Most of the presets container is MP4 so it works for most presets except MKV. Here is an example of the script that works for MP4:

#!/bin/bash
# Configure these as needed
SRC=~/hbCLI/src
DEST=~/hbCLI/dest
DEST_EXT=mp4
HANDBRAKE_CLI=HandBrakeCLI
PRESET="Fast 480p30"
IFS=$(echo -en "\n\b")
# The script itself
for FILE in `ls $SRC`
do
filename=$(basename $FILE)
extension=${filename##*.}
filename=${filename%.*}
$HANDBRAKE_CLI -i $SRC/$FILE -o $DEST/$filename.$DEST_EXT --preset="$PRESET" --optimize --two-pass
done

However for Matroska presets I only need to change the line PRESET="Fast 480p30" to PRESET="H.264 MKV 480p30" but the output extension is still mp4 instead of mkv.

Additional request:
Not part of the question but if any of you could help me to improve the script further so the output is saved to DEST=~/hbCLI/dest/$PRESET instead of DEST=~/hbCLI/destmeaning the output will be saved into a folder with the preset name, if it doesn't exist- create the folder.

Thank you!

9 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy