Burn a DVD using Shell Script

This has only been tested on Ubuntu 9.10

This works great for me and saves me having to use the usual GUI DVD backup applications. The best part about running this script is that it is very fast and you can watch the DVD while it is burning.

The end result is a 1080p avi file (obviously if you are not burning a HD DVD then the code that forces this resolution will default back to a “no less favorable resolution” than the donor disk). Feel free to read the man pages and post something better if you can.

Please note, you have to edit the lines that are prefixed with #conf

Any comments, additions and improvements are welcome. This is just something I did on the weekend and it is free, of course :)

#!/bin/bash

burn_dvd()
{
echo "Creating temp directory at $temp_directory"
if [ -d $temp_directory ]
 then
 rm -rf $temp_directory
fi
mkdir $temp_directory
echo "Creating backup of DVD $name, copying files to $temp_directory"
dvdbackup --verbose --mirror --input=$device --name=$name --output=$temp_directory
sleep 10
}

convert_to_avi()
{
number=1
for dir in $(find $temp_directory -type d -name VIDEO_TS); do
 for file in $(find $dir  -type f -name $file_name); do
 echo "processing file number $number $file"
 ffmpeg -i $file -s hd1080 -sameq $temp_directory/$number.avi
 echo "file number $number is complete"
 (( number++ ))
 done
number=1
done
}

merge_avi()
{
for avi in $(find $temp_directory -type f -name *.avi); do
 echo "Merging $avi with master file $final_location/$name.avi
 avimerge -o  $final_location/$name.avi -i $avi
done
rm -rf $temp_directory
}
#Please note this is only tested on Ubuntu 9.10, you will need to install the following packages
#sudo apt-get install transcode transcode-utils ffmpeg dvdbackup
#Please note you will have to fill out the following configuration marked #conf
#conf name of the movie/tv show
name=please_change_me
#conf temp directory that you have permissions to write to (will be created temporarily and then removed)
temp_directory=please_change_me
#conf DVD device
device=/dev/sr0
#conf name of the VOB files (this should be left as is unless you know better :)
file_name=VTS*.VOB
#conf The directory where you want the final file saved
final_location=please_change_me

burn_dvd
convert_to_avi
merge_avi
Advertisements

One thought on “Burn a DVD using Shell Script

  1. I am concerned about the way that Linux reads a directory eg…
    10.avi 11.avi 12.avi 13.avi 14.avi 15.avi 1.avi 2.avi 3.avi 4.avi 5.avi 6.avi 7.avi 8.avi 9.avi
    Your movie might end up with each chapter out of order…
    If you like a Quentin Tarantino time lapse feel to the movie this may be ok :)
    But I think we would all prefer the movie to be in the right order :)
    Still testing, sorry for any inconvenience.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s