Search This Blog

2010-10-17

Installing HandBrakeCLI & Converting Video Ubuntu 10.04


The easiest way to install the HandBrakeCLI tool is to add ppas. It makes it much easier than compiling your own and will allow updating of the application through apt.

The first step to installation is to fix the "add-apt-repository: command not found" error by installing it:
sudo apt-get install python-software-properties

The next step is to add the app repository using handbrakes ppa:
sudo apt-add-repository ppa:stebbins/handbrake-snapshots

Finally, install handbrake:
sudo apt-get update
sudo apt-get install handbrake-cli

This should install the ppa as well as add the GPG keys.
Now handbrake cli tool should be installed.

Running Handbrake:
Run HandBrakeCLI --help for syntax help
Note: Make sure you use the correct case as this cli tool is case sensitive

Trans-coding video automatically to iPod Touch/iPhone automatically.

Script:
#!/bin/bash
#
# Change this to specify a different handbrake preset. You can list them by running: "HandBrakeCLI $
#
PRESET="iPhone & iPod Touch"
if [ -z "$1" ] ; then
TRANSCODEDIR="(directory to trans-code)"
else
TRANSCODEDIR="$1"
fi
#finds all files recursively in folders and converts them to mp4
find "$TRANSCODEDIR"/* -type f -exec bash -c 'HandBrakeCLI -i "$1" -o "${1%\.*}".mp4 --preset="$PRE$

#move data from trans-code dir to different folders
cd (transcode-directory)
#move .mp4 to the directory above
mv *.mp4 ../
#move the rest of the files to the original folder so it doesn't convert again
mv *.* (directory to keep originals)


Now place this script in /etc/cron.hourly and make sure it is executable to run this script hourly.

Note: You might have to edit the /etc/crontab file and add the line
MAILTO=""
at the top of your crontab

There is an issue in Ubuntu with cronjobs which generate a lot of output. Cron tries to mail output to the user, but since there is no MTA (mail transfer agent) installed by default on Ubuntu desktop this output has nowhere to and when output is more than a certain buffer threshold the result is the command failing. Setting MAILTO to "" effectively turns off the mailing of output behaviour.

References:
https://edge.launchpad.net/~stebbins/+archive/handbrake-snapshots - Installing handbrake cli
http://www.surlyjake.com/shell-scripting/script-to-run-handbrake-recursively-through-a-folder-tree/ - Script baseline for automatic conversion
http://ubuntuforums.org/showthread.php?t=1117283 - MAILTO="" solution
http://www.htmlbasix.com/crontab.shtml - crontab wizard
http://forum.handbrake.fr/viewtopic.php?f=13&t=16555 - Installing ppa using /etc/apt/sources.list
http://ubuntuforums.org/archive/index.php/t-960627.html - Using find command to search for file extensions for video conversion script

No comments:

Post a Comment