Mass Conversion of different video files with handbreak-CLI

Flattr this!

I am currently converting all my videos to a fixed format using handbrake. If you have a lot of videos to convert, the UI version of handbrake is not always the best solution. Handbrake offers a CLI, sometimes you it needs to be installed separately.

It has a lot of options ( ). So the best is to go with your preferred preset.
I want to encode all video files in a given folder to the preset “universal”.
So i wrote a short bash script, to to the work:

# Folder Setup

if [ ! -f $DONE_FOLDER  ] ; then mkdir -p $DONE_FOLDER; fi
if [ ! -f $OUT_FOLDER  ] ; then mkdir -p $OUT_FOLDER; fi

#All Extensions of the input files
EXTS=( mp4 flv )
#Find Handbrake CLI
HB=`which HandBrakeCLI`

for ext in ${EXTS[@]}; do
	echo "for $ext"
	for FILENAME in `ls $IN_FOLDER/*.$ext`; do
		#echo $FILENAME
		$HB -i $FILENAME  -o $OUT_FOLDER/`basename "$FILENAME" .$ext`.mp4  --preset="Universal"

Another use-case might the conversion of some videos to flv for a web playback (or the other way round flv->mp4 for playback on iOS Devices)

Leave a Reply

%d bloggers like this: