old-www/LDP/LG/issue83/stoddard.html

290 lines
14 KiB
HTML

<!--startcut ==============================================-->
<!-- *** BEGIN HTML header *** -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<title>DVD Authoring LG #83</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!-- *** END HTML header *** -->
<!-- *** BEGIN navbar *** -->
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="sandeep.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue83/stoddard.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../lg_faq.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="thangaraju.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
<!-- *** END navbar *** -->
<!--endcut ============================================================-->
<TABLE BORDER><TR><TD WIDTH="200">
<A HREF="http://www.linuxgazette.com/">
<IMG ALT="LINUX GAZETTE" SRC="../gx/2002/lglogo_200x41.png"
WIDTH="200" HEIGHT="41" border="0"></A>
<BR CLEAR="all">
<SMALL>...<I>making Linux just a little more fun!</I></SMALL>
</TD><TD WIDTH="380">
<center>
<BIG><BIG><STRONG><FONT COLOR="maroon">DVD Authoring</FONT></STRONG></BIG></BIG><BR>
<STRONG>By <A HREF="../authors/stoddard.html">Chris Stoddard</A></STRONG></BIG>
</TD></TR>
</TABLE>
<P>
<!-- END header -->
<p>
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.
</p>
<h2>Table of Contents</h2>
<ul TYPE="">
<li>1. Introduction
<li>2. Hardware Required
<li>3. Software Required
<li>4. Recording, encoding and burning the video
<li>5. Fixing audio sync problems
<li>6. Final Note
</ul>
<h2>Introduction</h2>
<p>
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.
</p>
<h2>Hardware Required:</h2>
<p>
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.
</p>
<ul TYPE="">
<li>Video Capture device: I am using a Hauppauge WinTV PCI card, TV tuner cards are cheap and easy to come by, and are well supported by Linux. There are more expensive solutions which will get you better video quality, but support under Linux varies widely. <a HREF="http://www.linuxgazette.com/issue62/silva.html">Video Applications on Your Linux Box</a>
<li>DVD+RW or DVD-RW drive: I am using an old Ricoh MP5120A DVD+RW drive I purchased refurbished for $150. Luckily these drives install exactly the same way as a standard CDRW drive. You also need to be able to play DVD's on you system. Please be sure your stand alone DVD player supports the format of your burner. <a HREF="http://www.linuxgazette.com/issue81/durodola.html">Playing DVDs on Linux</a> and <a HREF="http://linuxgazette.com/issue57/stoddard.html">CD-Writing with an ATAPI CDR Mini-HOWTO</a>
<li>Fast CPU and a huge hard drive: I am personally using an Athlon 1600XP, 384 MB of RAM and a 40 GB hard Drive. I probably wouldn't even attempt this with less than 1 Ghz CPU and 20 GB of free hard drive space.
</ul>
<h2>Software Required:</h2>
<p>
Each of these packages has their own install process, please follow the instructions for each individual package.
</p>
<ul TYPE="">
<li>xawtv comes with streamer, which we will use for recording the video: <a HREF="http://bytesex.org/xawtv/">xawtv</a>
<li>mjpeg-tools is used for encoding the recorded video into a DVD compatible format: <a HREF="http://mjpeg.sourceforge.net/">mjpeg-tools</a>
<li>dvdauthor is the key piece of software, without it, we would not be able to do this. This package generates the IFO files required by DVD player. There is no automatic install for this program, simply run make, then copy the binaries to /usr/local/bin: <a HREF="http://sourceforge.net/project/showfiles.php?group_id=59028">dvdauthor</a>
<li>dvdrtools is a fork of cdrtools which we will use to build the iso and write to newer DVD-RW drives: <a HREF="http://www.freesoftware.fsf.org/dvdrtools/">dvdrtools</a>
<li>dvd+rw tools is used to burn to older DVD+RW format, this is only necessary if you have a first generation DVD+RW drive. If you have a newer DVD-RW drive this package is not needed: <a HREF="http://fy.chalmers.se/~appro/linux/DVD+RW/">dvd+rw tools</a>
</ul>
<p>
dvd+rw tools has no Makefile. You can build the binaries doing this:
</p>
<pre>
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
</pre>
<h2>Recording, encoding and burning the video:</h2>
<p>
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:
</p>
<pre>
streamer -n ntsc -t 60:00 -s 720x480 -r 30 -o stream.avi -f mjpeg -F stereo -c /dev/video0
</pre>
<p>
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.
</p>
<p>
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:
</p>
<pre>
lav2wav +p stream.avi | mp2enc -V -o audio.mp2
</pre>
<p>
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:
</p>
<pre>
lav2yuv +p stream.avi | mpeg2enc -n n -f 8 -s -r 16 -o video.m1v
</pre>
<p>
Now we need to join the two encoded files. Be sure to use the -f 8 switch for DVD compatible video:
</p>
<pre>
mplex -f 8 audio.mp2 video.m1v -o complete.mpg
</pre>
<p>
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:
</p>
<pre>
mkdir dvd
mkdir dvd/VIDEO_TS
</pre>
<p>
Next we need an Table of Content IFO file, type:
</p>
<pre>
tocgen > dvd/VIDEO_TS/VIDEO_TS.IFO
</pre>
<p>
Now we want to copy our encoded video file into the structure and give it the correct permissions, type:
</p>
<pre>
cp complete.mpg dvd/VIDEO_TS/VTS_01_1.VOB
chmod u+w dvd/VIDEO_TS/*.VOB
</pre>
<p>
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:
</p>
<pre>
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)
</pre>
<p>
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:
</p>
<pre>
mkisofs -dvd-video -udf -o dvd.iso dvd/
</pre>
<p>
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:
</p>
<pre>
dvd+rw-format -f /dev/srcd0
growisofs -Z /dev/srcd0=dvd.iso
</pre>
<p>
If you are using a newer DVD-RW, no formating is necessary, dvdrecord will do the job:
</p>
<pre>
dvdrecord -dao speed=2 dev=0,0,0 dvd.iso
</pre>
<h2>Fixing audio sync problems</h2>
<p>
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:
</p>
<pre>
hdparm -c 1 -d 1 /dev/hda
</pre>
Next, load the bttv driver with the gbuffers=10 option:
<pre>
modprobe bttv gbuffers=10
</pre>
<p>
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.
</p>
<h2>Final Notes:</h2>
<p>
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.
</p>
<A HREF="misc/stoddard/make-dvd.sh.txt">Text version of make-dvd.sh</A>
<pre>
-----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-----
</pre>
<!-- *** BEGIN copyright *** -->
<hr>
<CENTER><SMALL><STRONG>
Copyright &copy; 2002, Chris Stoddard.
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 83 of <i>Linux Gazette</i>, October 2002</H5>
</STRONG></SMALL></CENTER>
<!-- *** END copyright *** -->
<HR>
<!--startcut ==========================================================-->
<CENTER>
<!-- *** BEGIN navbar *** -->
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="sandeep.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue83/stoddard.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../lg_faq.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="thangaraju.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
<!-- *** END navbar *** -->
</CENTER>
</BODY></HTML>
<!--endcut ============================================================-->