#! /bin/bash

## DVD Creator Script
## Written by Sreejith K, sreejithemk@gmail.com
## Visit, http://sreejithemk.net
## Modified by Jos Collin

echo "############## DVD Creator ##########" ;
read -p "DVD Name : " dvdname ;
read -p "Video path : " path ;
read -p "Temp Dir (Use /tmp ): " temp ;
read -p "Writing Speed (eg. 40x): " speed ;

echo "Converting $path to MPG format....." ;
ffmpeg -i $path -target ntsc-dvd $temp/$dvdname.mpg ;
echo "Conversion completed." ;

echo "Creating DVD image....." ;
dvdauthor --title -o $temp/dvd -m -t -f $temp/$dvdname.mpg ;
echo "Image creation completed." ;

# I don't know why I have to execute the following line. growisofs is working only if I do this. If somebody find the reason please let me know.
# - Jos Collin
dvdauthor -o $temp/dvd/ -T

echo "Writing DVD....." ;
growisofs -dvd-compat -speed=$speed -Z /dev/dvd -dvd-video $temp/dvd/ ;

echo "DVD Burning completed." ;
echo "Ejecting DVD....." ;

echo "Cleaning the temp files .. .... " ;
rm -r $temp/dvd ;
rm $temp/$dvdname.mpg ;

echo "DVD Creation Completed....." ;
echo ;
echo "DVD Creator Script" ;
echo "Written by Sreejith K, sreejithemk@gmail.com" ;
echo "Visit, http://sreejithemk.net" ;
read key ;
