Share

Mass Conversion of different video files with handbreak-CLI

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 ( https://trac.handbrake.fr/wiki/CLIGuide ). 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:


#!/bin/bash
# Folder Setup
OUT_FOLDER=/home/media/out
IN_FOLDER=/home/media/in
DONE_FOLDER=$OUT_FOLDER/videos_done

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"
		mv $FILENAME $DONE_FOLDER/`basename "$FILENAME"`
	done
done

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)

You may also like...

Leave a Reply