Script to run handbrake on an entire folder
Handbrake is a fantastic tool for (among other uses), converting videos into mobile formats. It is extremely easy to use and can usually get a video properly converted in just a few clicks. To get Videos encoded for use on my phone, I use the “iPhone & iPod Touch” preset. It will convert your video to .mp4 as well as scall it down to a consumable size. This format will work on any smartphone I’ve seen.
My issue is that when converting a folder full of videos, I don’t want to have to use the gui to add a bunch of videos to the queue one by one. It’s a very clicky process. This simple bash script will walk handbrake through all the files in a selected folder:
#!/bin/bash
for file in "$1"/*
do
echo 'HandBrakeCLI -i "${file}" -o "${file}.mp4" --preset="iPhone & iPod Touch"""'
HandBrakeCLI -i "${file}" -o "${file}.mp4" --preset="iPhone & iPod Touch"""
done
Save that into a .sh file like “handbrakefolder.sh”
Now you can simply execute this script against a folder containing your video files. like this:
hostname% ls Videos
Video1.avi
Video2.avi
Video3.avi
hostname% ./handbrakefolder.sh Videos
...
...
...
hostname% ls Videos
Video1.avi
Video1.avi.mp4
Video2.avi
Video2.avi.mp4
Video3.avi
Video3.avi.mp4
