TIP DVD: Rip, Shrink, and Burn

From Gentoo Linux Wiki

Jump to: navigation, search
This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other

Contents

[edit] About this Script

This script was designed to rip, shrink, and burn DVD backup copies (hence the title). It was designed to streamline an already complex process of extracting information from a DVD, reencode those files to fit on a 4.5 gigabyte DVD, create an ISO image of those files that complies with DVD player specifications, and finally to burn the ISO image onto a DVD disk. I designed this script to streamline the process of backing up DVDs while preserving menus. Feel free to add to the discussion and bugs tab. Try not to add anything to the script unless you have thoroughly tested your modifications.

[edit] Features

  • Autodetect whether blank or complete dvd is present in optical drive.
  • Autodetect if source and destination optical drives are the same.
  • Option for eject when finished.
  • Allows for use with multiple configurations.
  • Some error detection when user is required to intervine.
  • Autodetection if shrinking/rencoding is required.

[edit] Disadvantages (Anti-features)

Relies on DVD Shrink and Wine to reencode the DVD files. Because of this some user intervention is required on DVDs that are larger than 4.5 gigabytes. DVD Shrink, although fast, has some issues with quality on larger files. DVD Shrink also has some reported issues with backing up menus correctly. I would like to find a Linux tool that is equivalent or better than DVD Shrink to do this process.

[edit] To Do

  • Find a replacement for DVD Shrink that will preserve menus. (update:see k9copy for this)
  • If DVD Shrink cannot be removed, automate its use (http://www.dvdshrink.info/chetwood/ or 'Autoit' as a possibility).
  • Make script better organized with use of functions.
  • Autodetection of mkisofs ifo errors when the source disc is corrupt.
  • Make script less of a script and more of a unified program.

[edit] Requirements

Many of the requirements can be attained by doing a search for them. Gentoo provides ebuilds using the names that are listed.

[edit] The Script

File: theScript.sh
#!/bin/bash
# rsburn.sh
# Rip Shrink and Burn.
# This script will extract, resize, and burn a dvd.
# Most of the material here was borrowed from: 
# http://forums.gentoo.org/viewtopic.php?t=71032

# Requirements:
# -dvdbackup
# -growisofs (dvd+rw-tools)
# -libdvdcss
# -wine
# -DVD Shrink (http://www.dvdshrink.info)

# Other requirements:
# -Adequate hard drive space (18 Gig?).
# -DVD burner.

# Todo:
# - Find a replacement for DVD Shrink that will preserve menus.
# - If DVD Shrink cannot be removed, automate it's
# use (http://www.dvdshrink.info/chetwood/  or 'Autoit' as a possibility).

# Changes:
# 12-12-2004 - edited script
# - To allow some error checking with DVD Shrink files.
# - Allowed more communication to user as script is processing to aid in debuging if problems arise.
# - Simplified some commands (origionally quick and dirty solutions, changes seem more appropriate).
# - Reorganized system variables for easy viewing/editing
# - Autodetection of both destination and source dvd drives are the same.  Eject and ask for blank DVD as needed. 


	# Set your variables to match what your system requires.  Mine 
	# is probably simpler than most.
	dvdsource=/dev/hda	#Source DVD drive for reading.
	dvddest=/dev/dvd	#Destination DVD drive for writing.
	ejectwhendone=y		#Do you want the destination and source dvds to autoeject when finished burning?
	deleteiso=y		#Delete the completed iso image when done.
	tmpdir=/tmp		#Default temp directory, you may want to stick it somewhere else. 
	winecdir="$HOME/.cxoffice/dotwine/fake_windows"		#A location easy to find while in DVD Shrink,
				# and a location to refer to when this script burns the dvd.  To keep things 
				# simple make sure this is c:\ in wine.
	winebin="$HOME/cxoffice/bin/wine --check --cx-app"	#Wine binary, location, and extra parameters.
				# I am using crossoveroffice, others may just use wine.  
	#dvdshrinkexe="C://Program Files//Pinnacle//InstantCDDVD//InstantCopy//ICopy.exe"
	dvdshrinkexe="C://Program Files//DVD Shrink//DVD Shrink 3.2.exe"  #'DVD Shrink.exe' binary path
				# as wine sees it (or Pinnacle InstantCopy).  Origionally had
				# winebin and dvdshrinkexe in one  command but wine did not see
				# the location of dvdshrinkexe so I split them up. 


# Make sure that we start clean
rm -rf $tmpdir/rsburn-tmp

# Create temporary workspace.
mkdir $tmpdir/rsburn-tmp
while [ "$(dvd+rw-mediainfo $dvdsource | grep 'Disc status' | cut -c 25-33)" != "complete" ] 
	do
	eject $dvdsource
	clear
	echo "Complete DVD Source not found."
	echo "Insert a DVD that you wish to rip and burn or"
	echo
	echo "Press enter to continue or Ctrl-C to quit."
	read user_reply	 
	done 

# Check to see that there is a usable title available on the dvd and then
# save it.  I had problems with some dvds having no title and then
# dvdbackup would complain.  Keep in mind 'tile' may be a typo in the dvdbackup
# source.  It is possible it should have been title.  If updates to dvdbackup
# are made or you are using a different version, you may need to change this.
echo -e "\033[1mExtracting DVD title, . . .\033[0m"
title=$(dvdbackup  -i $dvdsource -I | grep tile | cut -c 44-65)
if [ "$title" = "DVD_VIDEO" -o $title="" -o $title=" " ]  # if $title is null or DVD_VIDEO
	then
	title="dvdbackup"
	echo "No title found.  Using $title as the title."
	else
	echo Title found, using $title as the title.
	title="$title"
	fi

# Extract the files from the dvd
echo -e "\033[1mExtracting DVD files, . . .\033[0m"
dvdbackup -M -i $dvdsource -o $tmpdir/rsburn-tmp/ -n $title

# This is done twice, which is reduntant.  I did this to allow the user an oportunity to switch disks
# sooner without holding up or wasting time.
echo -e "\033[1mChecking if DVD destination has a blank dvd, . . .\033[0m"
if [ "$(dvd+rw-mediainfo $dvddest | grep 'Disc status' | cut -c 25-33)" != "blank" ]
	then
	eject $dvddest
	echo 
	echo "Insert a blank dvd."
	echo
	fi

#Get DVD size, so we can save time later.
echo -e "\033[1mGetting DVD size, . . .\033[0m"
size=$(du -chb $tmpdir/rsburn-tmp/$title | grep total | cut -c 1-5)
echo "Extracted files are $size megabytes."
# Re-author files as needed and make iso.

if [ "$size" -gt "47000" ]
	then
	until [ -d $winecdir/$title ]
		do
		echo
		echo "You will need to re-author your DVD files to fit on a 4.7 gigabyte disk."
		echo "Goto $tmpdir/rsburn-tmp/$title and Re-author the dvd with DVD Shrink."
		echo
		echo "Save the re-authered files in:" 
		echo "(cut and paste to avoid mis-type errors)"
		echo -e '\E[32;40mC:\\$title'; tput sgr0
		
		$winebin $dvdshrinkexe
				
		if [ -d $winecdir/$title ]
			then
			echo "$winecdir/$title found, . . ."
			else
			echo
			echo "$winecdir/$title not found or does not exist."
			echo "Don't be angry, . . ." 
			echo
			echo "Please check and review all settings, including:"
			echo "- Is 'winecdir' set correctly in this bash script?"
			echo "- 'winecdir' is also 'c:\' according to wine."
			echo
			echo "Check and rename directory as needed."
			echo "Press enter to continue or Ctrl-C to quit."
			read user_reply
			fi
		done
	echo -e "\033[1mCreating re-authored image, . . .\033[0m"
	mkisofs -dvd-video -v -o $tmpdir/$title.iso $winecdir/$title
	else
	echo -e "\033[1mCreating image, no re-authoring required, . . .\033[0m"
	mkisofs -dvd-video -v -o $tmpdir/$title.iso $tmpdir/rsburn-tmp/$title
	fi

# Check to see that dvd is blank.  If not eject and ask for blank dvd.  This is the second time
# checking for a blank dvd.  I did this to allow the user an oportunity to switch disks
# sooner without holding up or wasting time.
echo -e "\033[1mChecking if DVD destination has a blank dvd, . . .\033[0m"
while [ "$(dvd+rw-mediainfo $dvddest | grep 'Disc status' | cut -c 25-33)" != "blank" ]
	do
	eject $dvddest
	echo 
	echo "Insert a blank dvd."
	echo
	echo "Press enter to continue or Ctrl-C to quit."
	read user_reply	  
	done
	
# Burn the iso.
echo -e "\033[1mBurning image, . . .\033[0m"
growisofs -dvd-compat -Z $dvddest=$tmpdir/$title.iso

# Cleanup.
echo -e "\033[1mCleaining up, . . .\033[0m"
if [ $deleteiso = "y" ]
	then 
	rm $tmpdir/$title.iso
	fi

rm -rf $tmpdir/rsburn-tmp

if [ -d $winecdir/$title ]
	then
	rm -rf $winecdir/$title
	fi

if [ $ejectwhendone = "y" ]
	then 
	eject $dvddest
	if [ "$dvddest" != "$dvdsource" ]
		then
		eject $dvdsource
		fi
	fi

echo
echo Your DVD backup is finished.  Have a good day.
echo

[edit] Other Tools

Great automated program that picks the largest feature, rips, and then burns.
Great collection of tools.
Great gui, no nonsense, and intuitive.
K9Copy is a small utility which allows the copy of DVD on Linux.
Can copy with menus - just like dvdshrink
Another DVD9 to DVD5 utility (Gnome-based).
Can convert many video formats to dvd spec video (requires mplayer)
Incredibly easy to use, nice cropping feature

[edit] Troubleshooting

  • Make sure DVD Shrink and wine root directories are configured correctly.
  • Goto http://forums.gentoo.org/viewtopic.php?t=71032 for help on some of the tools used here.
  • Goto LinuxQuestions.org > LinuxAnswers > DVD9 to DVD5 guide this may provide an alternative to DVD shrink etc

[edit] Resources

Personal tools