Make a video that will boot and play directly from CD.
I love my son and try to give him what he needs in life. Sometimes I even give him what he wants, too. He has a nice bike that he uses quite a lot, and he is always out and about. Of course he has his own PC, which is online 24/7 while he constantly surfs for sports car images. (For some strange reason, the teachers at his primary school think he’s some sort of genius, as he’s always telling them that Windows sucks and the TCO is much less when using Linux.) At times I think I let him have too much: I have let him play games on a Windows machine. Then, of course, at age 11 he broke my collarbone, and all I did was lecture him on his propensity for causing “incidents.”
However, sometimes I put my foot down. One example involves my DVD collection. I don’t trust him with those little discs of plastic and dreams. We sometimes have debates about what he’s allowed to watch, and often he wants to take my DVDs to a friend’s house, which I absolutely forbid. What’s a father to do?
The answer is to make a self-booting CD copy of the DVD that he can watch on any PC. And that is where this hack comes in. It shows you how to reduce a DVD-length movie so it fits on a single CD—and to top it all off, it makes the CD bootable, so when you start a computer with the CD in the drive, it loads a very lightweight Linux OS with just enough software to play the movie on the CD.
Before diving into the guts of the hack, please keep in mind that I’m not suggesting you do anything illegal. I shudder to think that some evil person will impoverish an unassuming multinational corporation by depriving it of the opportunity to make a small profit off a piece of entertainment geared for the unwashed masses. That’s why the United States has such wonderful laws protecting companies’ rights. (Did I tell you that I live in Canada?) Instead, I implore you to use the following approach only for DVDs unencumbered by licensing issues.
Creating a movie involves a few software and hardware considerations:
Making these movie backup copies requires several distinct, free utilities, including:
LAME, the MP3 encoder
MPlayer, the premier movie player, which can also translate the DVD’s native encoding to AVI
transcode, a Linux text-console utility for video streams that includes a utility to break a large AVI file into smaller ones
eMoviX, a mini live Linux OS burned onto a CD, which permits the CD to boot and auto-magically play its files with MPlayer
mkisofs, which of course creates the ISO image
cdrecord, the ubiquitous CD-burning software
growisofs, for those people who have a DVD burner
This list looks pretty daunting, doesn’t it? Just look at all those utilities that you need to create your movie.
Actually, you can make things work with very little knowledge by using one more utility that ties all the above together: K3b [Hack #62] . K3b is a CD- and DVD-burning application for Linux systems. It is optimized for KDE, but it will run with other desktop environments and provides a comfortable user interface for performing most disc-burning tasks.
The basic process for creating this self-booting and playing miracle is:
Read the DVD and convert it into an AVI.
Break the completed AVI into files small enough to fit onto a CD.
Use K3b to create a new eMoviX project/CD for each AVI file.
Burn away.
Now let’s start putting the pieces together.
Of all the utilities, MPlayer is not only the most critical but also the trickiest to set up and use correctly. For more information on how to get and use MPlayer, check out [Hack #48] .
Ironically, for all MPlayer’s complication, you can create your AVI with this simple incantation from the command line:
$mencoder dvd:// -o
temp.avi
-ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=1800 -oac mp3lame -lameopts cbr:vol=3 -aid 128
Let’s break down the above command:
mencoder
specifies the
MPlayer command utility used to extract the video information from the DVD.
dvd://
identifies the
device from which the utility reads. You can also add a track
number to use a track other than the default, at dvd://1
.
-o temp.avi
is the name
of the AVI file to create.
-ovc lavc
will use the
libavcodec codec to compress the video
data.
-lavcopts
vcodec=mpeg4:vhq:vbitrate=1800
provides further
information to the libavcodec codec on
constructing the resulting file.
For the most part, you don’t have to worry about this
option. However, vbitrate=1800
is crucial to the screen
size of the movie. This particular setting, for example, sets
the whole screen for a 17-inch monitor. Reducing the number
reduces not only the screen size but also the file size! Halving
the number means you can fit 2 hours on one CD, rather than 1
hour. [Hack #60] explains
mencoder’s bitrate settings.
-lameopts cbr:vol=3
sets the bitrate method and the volume input for LAME’s sound
encoding.
-aid 128
chooses the
audio stream (language) to use. DVDs often have
more than one language sound track for a given recording. The
number 128
, for example, is
the industry’s identification number for the English
language.
Normally, you don’t need to worry about setting the audio
stream because it defaults to English. However, I personally often
use 129 for the French language sound track. I add the -alang fr
country identification switch,
too.
It’s a good idea to test the command first, because the encoding process will take several hours. The most common encoding mistake involves recording the sound improperly, and you’ll hate to find out you’ll have to repeat the wait. Doing a test recording is pretty simple. Add the following switches to the earlier command invocation:
-endpos 30 -ss 00:10:00
This will cause MPlayer to record for a period of 30 seconds at about 10 minutes into the DVD recording.
There’s often more than one track on a DVD. You might want to
record something other than the first track. The easiest solution is
to simply play the tracks until you find the one you’re interested
in. For example, mplayer
dvd://
plays the first track by default; mplayer dvd://1
plays the first track
explicitly; and mplayer
dvd://2
plays the second track explicitly.
There’s more than one command incantation to create an AVI. It’s all a question of experimenting with the different video and audio codecs. For example, you can restate the audio command so the audio stream is directly copied into the AVI without converting it to MP3:
$mencoder dvd://1 -endpos 30 -ss 00:10:00 -o
temp.avi
-ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=1800 -oac copy -aid 128
This incantation will normally result in a 1.4 GB AVI.
Play back the ripped recording by running mplayer:
$mplayer
temp.avi
The transcode suite of utilities is ideal for video-stream processing. That’s exactly what we want to use here. For more information on how to install and configure transcode check out [Hack #63] . Once you have installed transcode, you can run the tcprobe utility on your newly created temp.avi:
$tcprobe -i
temp.avi
[tcprobe] RIFF data, AVI video [avilib] V: 29.970 fps, codec=DIVX, frames=135989, width=720, height=480 [avilib] A: 48000 Hz, format=0x2000, bits=16, channels=2, bitrate=448 kbps, [avilib] 9076 chunks, 254128000 bytes, CBR [tcprobe] summary for temp.avi, (*) = not default, 0 = not detected import frame size: -g 720x480 [720x576] (*) frame rate: -f 29.970 [25.000] frc=4 (*) audio track: -a 0 [0] -e 48000,16,2 [48000,16,2] -n 0x2000 [0x2000] bitrate=448 kbps length: 135989 frames, frame_time=33 msec, duration=1:15:37.504
transcode includes a utility called avisplit for splitting AVI files into chunks of a specified maximum size. This example command breaks temp.avi into chunks no larger than 640 MB apiece (a perfect size for CDs):
$avisplit -s 640 -i
temp.avi
In this case, it creates two files, temp.avi-0000 and temp.avi-0001. Remember to check them out by playing little snippets at different points in the movie, say at the beginning and end of each file.
At this point you’re ready to create the self-booting movie ISO. It’ll take several utilities to do this, but using K3b makes it simple.
The first thing to do is to ensure that K3b sees all the requisite utilities, as seen in Figure 3-10. Launch the program, go to the Settings menu item, and click on the Configure option. You won’t need all the utilities listed here, but you’ll certainly require those listed at the beginning of this hack.
Figure 3-11 shows a snapshot of a new eMoviX project. Choose the eMoviX project that suits the medium to which you are burning. You may have a DVD burner, but be sure to select a CD project if the recording medium is a CD-R.
Using K3b is a fairly intuitive process. When you run the program, you’ll first see three panes. The top right one shows the files, defaulting to your home directory. From this pane you can navigate to the AVI files. Now drag and drop the first ISO image into the bottom pane. You can bring up the Burn window by clicking on the Burn icon, selecting Project → Burn from the menu, or pressing Ctrl-B to start the burn process. The Burn window, as shown in Figure 3-12, provides the opportunity to provide the information to include on your CD, as well as indicate how the movie should start and what should happen when it finishes. Take a minute to tab through the options: it’s pretty cool what eMoviX can do.
I don’t change much of anything except for the volume description and whether I want the system to eject the CD or shut down the system after the movie ends. When you’re satisfied with your options, click on the Burn button to begin the burn process.
That’s it, folks! Repeat the process for the next images until you have completed burning your CD movie.
Put the first CD in CD drive of any PC and boot the machine. The
CD uses ISOLinux to boot a small Linux kernel, run MPlayer, and start
up the movie file you have on the CD. When the movie ends on one CD of
a multi-CD video, replace it with the next CD, and type movix
in the console to start the next
movie.
I like using an image from the movie as my label for the CD jewel case. I use MPlayer to screen capture an image:
$ mplayer dvd:// -ss 00:10:00 -vo jpeg
This example command will begin screen capturing several frames per second, beginning 10 minutes into the movie. You will end up with a collection of numbered JPEG images in the directory where you invoked mplayer. Press Ctrl-C as soon as you’ve collected enough images to choose from.
Now load them into your favorite graphics package. I use display from the ImageMagick graphics suite because I can load them all with one command:
$ display *.jpg
Select the one you would like to use, print it, fold the paper, and you’re done.
—Robert Bernier