How to Backup a DVD
If you happen to own a number of DVDs and wish to back them up, this article is for you. It has been constructed to aid the casual user with overcoming some of the tricky DVD issues that might crop up during fair-use archiving. This article specifically tries to tackle double layer DVD to single layer DVD (DVD9 to DVD5 formats). Why yet another article for DVD9 to DVD5 copying? As you will surely find out, some DVDs resist the scripts that are out there to do this. Although not streamlined, this article should successfully backup even the most tightly wound up DVDs on the market. If the easier tools work, use them. If they don't, try the following technique.
This process will not backup the menus, only the primary title.
We will require tcrequant (transcode package), mplex (mjpegtools package), dvdauthor (dvdauthor package), and mplayer (mplayer package) to successfully do this. If you don't have these tools add them via:
sudo apt-get install transcode mplayer dvdauthor mjpegtools
1. Dump the DVD Main Title to Individual Files
While there are numerous guides out there to deal with archiving a DVD, this one will use a tried and true technique which deals with all sorts of troublesome DVDs. These issues might include split timecodes and a plethora of other little dittys that will get in your way.
First, use a DVD player to locate the exact title location of our primary title. In the following example, we have deduced that the primary title is located at the sixteenth location.
mplayer -dumpaudio -dumpfile output.ac3 dvd://16 mplayer -dumpvideo -dumpfile output.m2v dvd://16
This will strip the main title into two separate files -- namely output.ac3 (the audio) and output.m2v (the video).
If the wrong audio track is offered, force mplayer to use the correct one by providing the -aid <AUDIO TRACK> parameter with the proper audio track number. The correct audio track can be identified by using mplayer -v which lists available audio tracks. These are not necessarily numbered sequentially.
Note that some protected dvds require dvdnav to read them correctly, which is not compiled in by default in the ubuntu package. To compile a deb do:
sudo apt-get build-dep mplayer sudo apt-get install libdvdnav-dev apt-get source mplayer cd mplayer-xxxx
... now edit debian/rules adding the flag --enable-dvdnav to one of the environment variables with the configure flags...
dpkg-buildpackage -sn -uc cd .. sudo apt-get install mplayer*.deb mencoder*.deb
mplayer -dumpaudio -dumpfile output.ac3 dvdnav://16 mplayer -dumpvideo -dumpfile output.m2v dvdnav://16
2. Requantize the Video to DVD5 Size
This is quite fast as we are not completely re-encoding the stream.
tcrequant -i output.m2v -o output_shrunk.m2v -f 1.5
The -f 1.5 here is the shrinkage factor, and is a pretty good guess for most DVDs. If you are very particular and want to maximize the disk use use the following formula to calculate the proper value.
FACTOR = (TOTAL_M2V_VIDEO_SIZE / (4700000000 - TOTAL_AC3_FILE_SIZE)) * 1.04
3. Combine the New Video with the Old Audio
Again, quite simple.
mplex -f 8 -o final_output.mpg output_shrunk.m2v output.ac3
The -f 8 here tells mplex to create a compliant DVD format stream.
If the above command works flawlessly, you probably didn't even need this guide in the first place. Test your audio sync in a player and see if it worked on the final output file. If the sync is out, you can adjust it by executing the above line with a -O option to offset the audio.
If, on the other hand, you get some error about %d not in the filename, read on...
3.1. Nasty DVDs
Usually most users end up getting frustrated at the above error and start Googling their way into insanity. Have faith however, the following should solve your problem! Although it isn't pretty, it will backup even the most stubborn DVDs out there.
3.1.1. Output to Multiple Files
Let's fix the above command so it will crank out several files. You might want to do this in a new directory as it may poop out many mpgs.
mplex -f 8 -o final_output%d.mpg output_shrunk.m2v output.ac3
The %d here tells mplex that it is now free to crank out as many split files as required by the video file.
126.96.36.199. Remove Blank MPGs
Here is where the nightmare starts. Once mplex is finished, you will need to browse through all of your final_output#.mpg files. Usually there are many that are very small black short mpgs. Play them in a media player to confirm. What you are looking for is your primary title files. Make a note of them all, and discard the rest of the files.
Because we are now dealing with a tricky (and probably copy protected) DVD, our audio will be completely out of sync. Ignore this for now.
3.1.2. Strip the Video Stream AGAIN
So now we have who knows how many mpgs containing our copy protected / tricky / poorly made DVD. Because mplex tried to sync the sound to the tricky sections that are now gone, we will need to rip our lovely main title out of the mix again. To do this, simply re-issue the mplayer command to strip the video. You will need to strip each video stream into individual m2v files. If someone knows how to clean this step up, please adjust the wiki accordingly.
mplayer -dumpvideo -dumpfile <OUTPUT_FILENAME_##.m2v> <INPUT_FILENAME##.MPG>
Now we should have a series of m2v files that contain only our primary title without all the garbage chunks that were causing grief before. You can now remove all of the older mpg files. You will only require the newest m2v files created above along with the original sound track.
3.1.3. Concatenate the Video Stream
Let's make the multiple files one again so we can sync up our singular sound file to the new title:
cat file1.m2v file2.m2v file3.m2v > final_title.m2v
The above assumes you re-named your output m2v files file1, file2, and file3. Put whatever your files are here in order.
3.1.4. Combine the Video with Audio AGAIN
Same as our earlier step:
mplex -f 8 -o final_output%d.mpg final_title.m2v output.ac3
Phew! That was a lot of work eh? To summarize what we have done:
- Stripped the video and audio out of our primary title to the hard disk.
- Shrunk the video to fit on a DVD5 format disk.
- Combined the audio and video together into multiple files because of problems.
- Re-stripped the video out of our primary title mpegs and discarded the problematic blanks.
- Re-combined the audio with the newly stripped video.
4. Make the DVD Structure
We will now use dvdauthor to create the proper DVD format in a directory.
4.1. Generate a Configuration File
First, we will need to create a config file for the dvdauthor. Put the following into your favourite text editor and change the appropriate names of the mpegs to match your output:
<dvdauthor> <vmgm /> <titleset> <titles> <pgc> <vob file="final_output1.mpg" chapters="0" /> <vob file="final_output2.mpg" /> </pgc> </titles> </titleset> </dvdauthor>
Save the file as dvdauthor.xml
4.2. Make the DVD Structure Itself
Pretty self explanatory:
dvdauthor -o dvddirectory -x dvdauthor.xml
Now you should have a proper DVD structure in your good old dvddirectory below where you have been working.
5. Make the ISO and Burn It
The following command will take the above directory and make an ISO image for you to mount and test before burning. Hope all went well...
mkisofs -dvd-video -o DVD.iso ./dvddirectory/
Wow. Long road. It should work for even the most nasty DVDs out there.
6. Burn It without ISO
growisofs -Z /dev/dvd -dvd-video dvddirectory/