Category Archives: Uncategorized

Handbrake batch conversion using CLI shell script

I contributed to a Handbrake forum a while back. Thought you might find it useful too.

This is my evolving script for transcoding DVDs from MacTheRipper.

1) Save the file in a logical place (I keep it in the Movies Folder… same place I rip movies to). It will loop through all titles longer than X.

#!/bin/sh
# usage is ./thisScript.sh minimumDuration SomeDirContainingVIDEO_TS
# duration is set in minutes ("30" equals 30 minutes)
# specify the container directory for the VIDEO_TS directory
# example ./handbrake-longer-than.sh 30 24_SEASON6_D1
#set default path to HandBrakeCLI
PathToHandBrakeCLI=/some/path/to/HandBrakeCLI
if [ "${1}x" = "x" ]; then
echo "Minutes not provided"
exit
fi
if [ "${2}x" = "x" ]; then
echo "VIDEO_TS path not provided"
exit
fi
time=$1
export time
for i in $(find $2 -type d -name VIDEO_TS) ; do
for title in $($PathToHandBrakeCLI -t 0 -i $i -L 2>&1 | grep "has length" | sed 's/sec//' | sed 's/[()]//g' | awk '$8 > (60 * ENVIRON["time"]) { print $3 "-" $5 } ') ; do
#this names the title for the output file
titlenum=$(echo $title | cut -f 2 -d '-')
# you can change the preset or any other variables here
$PathToHandBrakeCLI -i $i -o ${2}-title${titlenum}-appletv.m4v --preset="AppleTV" -2 -T -P -t ${titlenum}
#output example: 24_SEASON6_D1-title1-appletv.m4v
done
 done

2) Within the script, set the path to your HandBrakeCLI app on line 9.

3) Don’t forget to run this before trying to execute it:
chmod 777 ./handbrake-longer-than.sh

4) Execute it like this:
./handbrake-longer-than.sh 30 24_SEASON6_D1

Where “30” is the shortest title you want to export and “24_SEASON6_D1” is the name of the folder containing your VIDEO_TS directory.

Sync iCal with Google Calendar

Products like Spanning Sync allow you to sync your iCal with your Google calendar. Now Google has a new service called “Google Calendar CalDAV” that allows you to do the same thing.

Details at: Enable Google Calendar in iCal

I tried it and it works very good. Everything sync’d within a couple of minutes (I have a LOT of entries). No problems so far.

Add a Virtual IP Address in Linux

nano /etc/sysconfig/network-scripts/ifcfg-eth0

Should look something like this


DEVICE=eth0
BOOTPROTO=static
BROADCAST=172.16.0.255
HWADDR=00:00:00:00:00:00
IPADDR=172.16.0.2
NETMASK=255.255.255.0
NETWORK=172.16.0.0
ONBOOT=yes

Duplicate that and open the new file

cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
nano /etc/sysconfig/network-scripts/ifcfg-eth0:0

Change device name, set new IP, remove reference to hardware


DEVICE=eth0:0
BOOTPROTO=static
BROADCAST=172.16.0.255
IPADDR=172.16.0.3
NETMASK=255.255.255.0
NETWORK=172.16.0.0
ONBOOT=yes

Pause a Linux Shell Script using Sleep

It’s easy to pause a shell script during execution. Just add:

sleep 10

(where 10 is the number of seconds you want the script to pause.)

Some code for testing would be…

#!/bin/sh
before="$(date +%s)"
echo $before
sleep 3
after="$(date +%s)"
echo $after
elapsed_seconds="$(expr $after - $before)"
echo Elapsed time for code block: $elapsed_seconds

Have other ideas? Please comment.