...making Linux just a little more fun!
By Chris Stoddard
This document provides the steps necessary to make a DVD which will play in a stand alone DVD player, using Linux and a DVD+RW or DVD-RW drive.
I am constantly amazed at how easy it is to accomplish things in Linux once someone works out the process. DVD Authoring is a good example of this, all the parts are in place, all the information is available and it is a relatively easy thing to do, but no where is there a single document showing how to accomplish it. Authoring DVD under Linux is still in its infancy, there are no tools for menus or any advanced features, for now all we can do is single straight DVD stream, which is enough for home videos and saving TV shows. I will not be discussing video editing here, I assume you will either be recording from TV or have a video tape you wish to transfer to a DVD.
I'm not going into much detail about installing the hardware, if you don't know how to install your hardware, I have provided links to articles for help.
Each of these packages has their own install process, please follow the instructions for each individual package.
dvd+rw tools has no Makefile. You can build the binaries doing this:
gcc dvd+rw-format.c mv a.out dvd+rw-format cp dvd+rw-format /usr/local/bin gcc growisofs.c mv a.out growisofs cp growisofs /usr/local/bin
Recording the video is the most important step, the size of the video and the frame rate must be right. The following command uses streamer, which comes with xawtv to record the video:
streamer -n ntsc -t 60:00 -s 720x480 -r 30 -o stream.avi -f mjpeg -F stereo -c /dev/video0
The -n switch is for format, if you use PAL, change ntsc to pal. The -t switch is record time in minutes. -s is the size of the video, in the USA, we use NTSC which requires the video to be 720x480 if you use PAL, change this to 720x576. -r is the frame rate, for NTSC use 30, for PAL use 24, -c is the video device, change it if need be. The rest of the switches should remain unchanged.
The next thing to do is to properly encode the audio and video into something a DVD player can read. The tools we need for this are from mjpeg-tools. This command line strips the audio out of our avi file and encodes it to mp2 audio. The -V switch actually is for VCD compatibility, but works for us here:
lav2wav +p stream.avi | mp2enc -V -o audio.mp2
Next we strip out the video and encode it to mpeg video. This part is what takes the longest, the faster your system is the better. The important switches here are -f 8, which ensures the video will be DVD compatible and -n n, which is for NTSC, if you are using PAL change it to -n p:
lav2yuv +p stream.avi | mpeg2enc -n n -f 8 -s -r 16 -o video.m1v
Now we need to join the two encoded files. Be sure to use the -f 8 switch for DVD compatible video:
mplex -f 8 audio.mp2 video.m1v -o complete.mpg
In order for our disc to be played in a stand alone DVD player, the directory structure HAS to be perfect, so please make sure you type the next several commands exactly as shown, in the order shown:
mkdir dvd mkdir dvd/VIDEO_TS
Next we need an Table of Content IFO file, type:
tocgen > dvd/VIDEO_TS/VIDEO_TS.IFO
Now we want to copy our encoded video file into the structure and give it the correct permissions, type:
cp complete.mpg dvd/VIDEO_TS/VTS_01_1.VOB chmod u+w dvd/VIDEO_TS/*.VOB
IFO and BUP files provide DVD players with information specific to the video file it is trying to play, ifogen looks at the video and extracts the information needed. To generate the needed files use this command line:
ifogen -f dvd/VIDEO_TS/VTS_01_1.VOB > dvd/VIDEO_TS/VTS_01_0.IFO (cd dvd/VIDEO_TS; for i in *.IFO; do cp $i `basename $i .IFO`.BUP; done)
Now we need to generate an iso image which can be burned to a DVD disc. Be sure you are using mkisofs version from dvdrtools, which supports the DVD files system:
mkisofs -dvd-video -udf -o dvd.iso dvd/
And, finally, we can burn our disc. If you are using an older first generation DVD+RW drive, the disc will need to be formated before the image can be burned, use the following commands, replacing srcd0 with the device name of your drive:
dvd+rw-format -f /dev/srcd0 growisofs -Z /dev/srcd0=dvd.iso
If you are using a newer DVD-RW, no formating is necessary, dvdrecord will do the job:
dvdrecord -dao speed=2 dev=0,0,0 dvd.iso
The most common problem with this process is audio sync. The first thing you should try is optimizing your hard drive with hdparm, turn on 32 bit I/O and DMA, it looks something like this:
hdparm -c 1 -d 1 /dev/hdaNext, load the bttv driver with the gbuffers=10 option:
modprobe bttv gbuffers=10
This should fix any audio sync problems, if it does not, you may need to use the -O n option when running mplex. This delays the video by n mSeconds. The problem with this is it is a trial and error process and often leaves the joined video file in a state that causes ifogen to segfault. It may also be possible to record the video at a lower size, say 352x240, then use yuvscaler from the mpjeg-tools to resize it to 720x480, but I have not tried this.
This process will not give you "Buy in the Store" DVD quality video, the quality will depend largely on the quality of your capture source, so you should use the best quality settings you can when recording anything on video tape you intend to burn to DVD. This process takes several hours, I use the shell script below to do the work for me, while I am at work or in bed sleeping. 100 minutes of video will require about 11 GB to record, 2 GB to encode and 1 GB for the iso image. Your mileage will vary.Text version of make-dvd.sh
-----make-dvd.sh----- #!/bin/sh # Cleans out any left over files and makes the necessary directories rm -r -f dvd video dvd.iso mkdir dvd mkdir dvd/VIDEO_TS mkdir video # Changes the channel on the TV tuner card v4lctl setstation 3 # Records the video stream streamer -n ntsc -t 60:00 -s 720x480 -r 30 -o video/stream.avi -f mjpeg -F stereo -c /dev/video0 # Encodes the video stream lav2wav +p video/stream.avi | mp2enc -V -o video/audio.mp2 lav2yuv +p video/stream.avi | mpeg2enc -n n -f 8 -s -r 16 -o video/video.m1v mplex -f 8 video/audio.mp2 video/video.m1v -o video/complete.mpg # Builds DVD image from the encoded video # This portion of the script was lifted directly from # the writedvd script which comes with the dvdauthor tools tocgen > dvd/VIDEO_TS/VIDEO_TS.IFO cp video/complete.mpg dvd/VIDEO_TS/VTS_01_1.VOB chmod u+w dvd/VIDEO_TS/*.VOB ifogen -f dvd/VIDEO_TS/VTS_01_1.VOB > dvd/VIDEO_TS/VTS_01_0.IFO (cd dvd/VIDEO_TS; for i in *.IFO; do cp $i `basename $i .IFO`.BUP; done) mkisofs -dvd-video -udf -o dvd.iso dvd/ # Burns the DVD for 1st Generation DVD+RW # Comment out the dvd+rw-format line if the disc is already formated and # contains no data. # Comment these two lines out if you are using a newer drive dvd+rw-format -f /dev/srcd0 growisofs -Z /dev/srcd0=dvd.iso # Burns DVD for more modern DVD formats like DVD-RW # Uncomment this line if you are using a newer drive #dvdrecord -dao speed=2 dev=0,0,0 dvd.iso -----make-dvd.sh-----