Linux DVD HOWTO Peter Jay Salzman, p@dirac.org v0.2.1 12 Oct 2000 A guide to getting your DVD to do something useful under Linux. ___________________________________________________________________________ Table of Contents 1. Introduction 1.1 Goal 1.2 New Versions 1.3 Copyright 1.4 Credits 2. Installation 2.1 Requirements 2.2 Kernel Requirements 2.2.1 DVD ioctl 2.2.1 Setting up MTRR 2.2.1.1 Finding the video card's base memory address 2.2.1.2 Finding the video card's RAM 2.2.1.3 Adding the MTRR 3. The Anatomy of a DVD 4. DeCSS 4.1 css-auth 4.2 Unlocking a DVD 5. DVD Playing Software 5.1 vlc 5.2 LiViD 5.2.1 Obtaining and Installing LiViD 5.2.2 Playing with LiVid 5.3 xine 5.4 xmovie 6. Squeezing Performance Out Of Your System 6.1. RAW-IO supported by the latest linux kernels. 7. Errata ___________________________________________________________________________ 1. Introduction 1.1. Goal This document describes how to configure and use your DVD drive under Linux 1.2. New Versions The newest version can be found at http://www.dirac.org/p/linux. You should always check here for the latest version, since this HOWTO is updated often. 1.3. Copyright This howto is copyright 2000 by Peter Jay Salzman , and is released under the GNU GPL, found at . 1.3. Credits Thanks to the LiViD, XMovie, xine and vlc developers, who have given their respective DVD player projects much of their time and work. Thanks to the EFF for helping Linux users in the legal fight to use DVD. Also, thanks to the Masters of Reverse Engineering for cracking CSS. Thanks also goes out to Nathan Rowlan for writing the DVD Playing HOWTO. 2. Installation 2.1. Requirements The following is a list of things you'll need: o XFree86 3.3.X or higher. o A DVD-ROM/RAM/RW drive supported by Linux; most of them are. o An implementation of DeCSS, if you want to watch commercial DVD's. o Software to play MPEG data. o A DVD. 2.2. Kernel Requirements You will need a kernel with: o Linux kernel >=2.2.14, but >=2.2.16 is recommended. o DVD ioctl o MTRR support (optional, but recommended) 2.2.1. DVD ioctl DVD ioctl has been in the kernel since 2.2.16, so if you have a kernel >= 2.2.16, congratulations, you're good to go; move on to the next section. If you have kernel 2.2.14 or 2.2.15, there are patches that'll give your kernel DVD ioctl. You can download the patches from http://www.kernel.dk. See the kernel HOWTO for details on how to patch and recompile a kernel. 2.2.2. Setting up MTRR's On Intel processors (Pentium Pro, Pentium II and later) the Memory Type Rage Registers (MTRR) is used to control CPU access to memory ranges. This allows for more efficient transfer of data over the AGP/PCI bus. You don't really need MTRR, it'll enhance your video performance. The Cyrix 6x86, 6x86MX and MII CPUs have Address Range Registers (AARs) which are used to emulate the MTRRs. The AMD K6-2 and K6-3 CPUSs have two MTRRs. The Centaur C6 (WinChip) has 8 MCRs, allowing write combining. These non-Intel MTRRs are supported by the Linux kernel. Matrox video card owners: If you have matroxfb compiled into the kernel, chances are that your MTRR's are already set up. You can skip this section. MTRR support has been in the kernel since 2.2.11. To find out if your kernel has MTRR support built in, type: ls /proc/mtrr If the file exists, you have MTRR built into the kernel, otherwise you'll need to recompile the kernel with MTRR support. You'll find this option under "Processor type and features". Now that you know your kernel has MTRR support, you now need to configure it. You'll need to know the base memory address of your video card, and how much video ram it has. The easiest way to do this is to use X with the -probeonly option. This creates a file named probe that contains the results of X's probe: # X -probeonly 2>probe 2.2.2.1 Finding the video card's base memory address The line having the needed information is somewhere in the middle of the file. Here are three examples of what you may see: belial: (--) SVGA: PCI: NVidia Riva TNT rev 4, Memory @ 0xe4000000, 0xe6000000 satan: (--) SVGA: PCI: 3Dfx Voodoo3 rev 1, Memory @ 0xe4000000, 0xe8000000, I/O @ 0x9000 navalle: (--) Mach64: PCI: Mach64 Rage LT Pro rev 220, Aperture @ 0x40000000, Registers @ 0x41000000, Block I/O @ 0x1000 Once you have located the line that resembles these, write down the last memory address. For my 3 computers, this would be 0xe6000000 for belial, 0xe8000000 for satan and 0x40000000 for navalle. 2.2.2.2 Finding the video card's RAM. Next you have know how much ram your video card has in hexidecimal. From the probe file you created in the previous step, look for lines refering to your video RAM. To be on the safe side, look for lines that start with (--), not with (**). The difference is that (--) means "information that was probed from hardware" and (**) is information you supply in the file XF86Config. You could be wrong, but hardware hardly ever lies. ;) belial: (--) SVGA: videoram: 16256k satan: For some reason, it doesn't display (--) Found 16 MB SDRAM navalle: (--) Mach64: Video RAM: 8192k These numbers would indicate 16MB, 16MB and 8MB respectively. You can find the hexidecimal number by using the following lookup table: 4MB -- 0x400000 8MB -- 0x800000 16MB -- 0x1000000 32MB -- 0x2000000 2.2.1.3. Adding the MTRR To add the MTRR for my three computers, I would type (as root): belial: echo "base=0xe6000000 size=0x1000000 type=write-combining" >| /proc/mtrr satan: echo "base=0xe8000000 size=0x1000000 type=write-combining" >| /proc/mtrr navalle: echo "base=0x40000000 size=0x800000 type=write-combining" >| /proc/mtrr but you'll substitute the base address for what you found in section 2.2.2.1 and the hexidecimal value of the videocard RAM found in 2.2.2.2. Now you should have MTRR set up, and just to make sure, type: # cat /proc/mtrr And you should get output that looks remotely similar to: belial: reg00: base=0x00000000 ( 0MB), size= 128MB: write-back, count=1 reg01: base=0xe6000000 (3680MB), size= 16MB: write-combining, count=1 satan: reg00: base=0x00000000 ( 0MB), size= 128MB: write-back, count=1 reg01: base=0xe8000000 (3712MB), size= 16MB: write-combining, count=1 navalle: reg00: base=0x00000000 ( 0MB), size= 128MB: write-back, count=1 reg01: base=0x40000000 (1024MB), size= 8MB: write-combining, count=1 The number of entries might be different from these, don't sweat it. 3. The Anatomy of a DVD You need to know a little bit about the files that reside on a dvd. Looking at a dvd's filesystem, the top level directory will always be: navalle# ls /cdrom/ audio_ts/ video_ts/ I've always seen the audio_ts/ directory empty. The video_ts directory, for example on Austin Powers, looks like: navalle:~# ls /cdrom/video_ts/ video_ts.bup vts_01_0.ifo vts_01_3.vob vts_02_0.vob vts_03_0.vob video_ts.ifo vts_01_0.vob vts_01_4.vob vts_02_1.vob vts_03_1.vob video_ts.vob vts_01_1.vob vts_02_0.bup vts_03_0.bup vts_01_0.bup vts_01_2.vob vts_02_0.ifo vts_03_0.ifo You'll generally find files with the .vob, .ifo, .aob and .bup files. There seems to be a number of "tracks"; in the above example, there are 3 "tracks": 01, 02 and 03. Track 01 contains the actual movie. The other tracks generally contain upcoming attractions and trailers. .aob and .vob are the DVD audio and video files respectively. The .vob files are in a specialized MPEG-2 format, with extra information for navigating and searching the DVD. This extra information will cause wierd behavior in non-DVD MPEG players. Most .vob files won't play when copied to your hard drive because they reference keys which are found on the DVD and which do not get copied when you simply copy the .vob file. .ifo files contain menus and other information about the audio and video. The vts_0?_0.ifo files contain the glue that keeps the individual tracks together. They're kind of like the control files for each track. I'm not sure of the role of video_ts.ifo. 4. DeCSS Commerical DVDs have a form of copy-protection called the Content Scrambling System (CSS). You'll know that a DVD is copy-protected if you get read errors while you try playing a DVD. Your only recourse is to use DeCSS, a program that unlocks the DVDs copy-protection. Note that this is currently illegal; what I describe below is purely hypothetical, and for educational purposes only. I have never used any implementation of DeCSS myself, and would never infringe on copyright laws. One very popular implementation of DeCSS is named css-auth. css-auth performs two functions: 1. Perform the CSS authentication protocol, allowing locked sectors on a DVD disc to be accessed. This "unlocks" a DVD. 2. Implements the CSS decryption algorithm so we can use the data stream to watch commercial DVD's. css-auth is not the only software that does this. Some DVD players, like like xmovie, does this on the fly so you don't have to worry about using css-auth, which is not trivial. These players are also in legal question. 4.1. css-auth The DeCSS implementation that many people use is css-auth. You can find it all over the internet. One site is http://www.cs.cmu.edu/~dst/DeCSS/. This site also has links to many other things of interest to people interested in the technical and legal aspects of DeCSS. I've found that you need glibc 2.2 to compile css-auth. If you get error messages that complain about undefined structs and constants like DVD_STRUCT_READ, the problem is that you have glibc 2.1, and /usr/include/linux/cdrom.h does not have dvd declarations. Debian's potato has glibc 2.1; woody has 2.2. 4.2 Unlocking a DVD using css-auth The css-auth programs related to the CSS authentication protocol are reset, tstdvd and dvdinfo. To unlock a DVD, perform the following steps. We'll assume that your dvd is /dev/hdd and that it mounts on /dvd. Firstly, reset all AGID's that the drive has given out. This can be useful when things go wrong. Be careful because you probably already have a program named reset on your system. Use the full pathname when using this function. ./reset /dev/hdd Secondly, use testdvd to unlock the disk by extracting the disk-key and saving it to ./disk-key. ./testdvd /dev/hdd Thirdly, mount the dvd as read-only with the UDF filesystem. mount -r -t udf /dev/hdd /dvd Fourthly, you can display some information on the physical and copyright pages. This includes the region limits on the disk, its encryption status and the authentication status. ./dvdinfo / Fifthly, read the title key for the chosen .vob file, saving it in pwd as title-key. ./tstdvd /dev/hdd /dvd/video_ts/vts_01_1.vob mv title-key title1-key The documentation says to repeat this for each .vob file you want to watch. From what I've seen, it's enough to do the first .vob file. From what I've seen, you simply need to do this once. Congratulations, you've now unlocked the DVD. 5. DVD Players This is all the software I know about that allows you to watch a DVD's MPEG contents. If you know of any others, please let me know. 5.1. vlc VideoLAN is a project of students from the Ecole Centrale Paris which aims to broadcast video on the campus, and provide the students with a MPEG2 software decoder. It supports streams from a satellite, a DVD or an MPEG2 compression card. VideoLAN is released under the GNU GPL. The vlc package is the client which you can watch DVD's on Linux (but you'll still need css-auth to watch most commercial DVD's). I've found that vlc has very excellent DVD framerate playback. Much smoother than xmovie. However, the user interface is pretty cranky. You can get vlc in deb, rpm and tarball format from http://www.videolan.org/. To get vlc to display using a particular library, use the --vout switch. So to use the ggi or sdl library, use: vlc --vout ggi or vlc --vout sdl Note that ggi will be slower than plain X. The main interest in ggi is to support a wider range of output devices. To get fullscreen, you can change your X resolution so that vlc is the same size as your screen. You can also use the SDL plugin (vlc --vout sdl) and use the --display fullscreen option. If you get messages like: spudec: unknown command 0x50 appearing a bunch of times, its' because a bug was introduced in the subtitle decoder. It is the next thing on the authors' TODO list. A work around would be to launch vlc with a non-existing subtitle channel, such as vlc -s 42 until the bug gets fixed. 5.2. LiViD Utilities You used to need 3 programs from the LiViD utilities: ac3dec, oms and mpeg2dec. The developers have changed this: you only need oms because the other two have been integrated into oms. 5.2.1 Obtaining and Installing LiViD You can get the LiViD utilities either from CVS or tarball. Here is how you would get the latest CVS snapshot. # mkdir ~/livid # cd ~/livid # export CVSROOT=:pserver:anonymous@cvs.linuxvideo.org:/cvs/livid # cvs login (Logging in to anonymous@cvs.linuxvideo.org) CVS password: There is no password for anonymous, just press enter. # cvs -z3 co -P oms LiViD is now on your hard drive. Next, you need to compile it. Make sure that you have /usr/local/lib somewhere in /etc/ld.so.conf (if not, add it and run ldconfig). Perform the following steps: # cd ~/livid/oms # ./autogen.sh # ./configure # make Now the necessary LiViD utilities should be installed. oms needs some special fifo pipes to be created for the DVD data to travel over. These can be made with the following commands (if they don't already exist): # mkfifo /tmp/video # mkfifo /tmp/audio Oms also needs /dev/dvd to be a symlink to where your DVD drive resides, such as /dev/hdb1 or /dev/scd0. If it is at /dev/cdrom, you would create the link by typing: # ln -s /dev/cdrom /dev/dvd It's undesirable to make a symlink to a symlink, because it adds unnecessary I/O. Replace /dev/cdrom with the correct device that your dvd drive is on. 5.3. xine xine is another mpeg1/2 VCD and DVD player project. You can check it out at http://xine.sourceforge.net. 5.4. xmovie xmovie by Adam Williams is quite a gem. If you're frustrated by things not working out, or the hoops you have to jump through involving catting files into css-auth and piping them into a viewer, then take a look at this package. It's good for immediate satisfaction. You can download xmovie from http://heroinewarrior.com in two forms: source and a binary rpm package. The author warns that compiling the source as of 18 December 2000 (version 1.5.3) is very difficult. I've verified that claim. However, installing the binary via the rpm poses no trouble at all. I was able to convert the rpm into a deb package via alien without a hitch. The deb package installed perfectly. There's a lot about xmovie which makes it a very attractive program to use for watching DVD's. First of all, xmovie knows about .ifo files, so you can feed it vts_01_0.ifo and it plays all of track 01. It has a file browser, so no more catting stuff from the command line. The binary version even performs DeCSS on the fly, so you don't even have to mess with css-auth. This player has an excellent sense of aesthetics about it. The author obviously put a lot of thought and care into designing this software. This gem also supports MPEG-1, MPEG-2, MP3 audio, MP2 audio, AC3 audio, and Quicktime movies with stereo sound! xmovie has some downsides. Only the binary version supports DeCSS, and it has to be run as root or suid to decrypt DVD's (you can still use css-cat). The framerate is very poor. The program skips frames to compensate. On a PII/400 with a Voodoo3, the quality was acceptable, but you definitely know that frames are getting dropped. There's an option to play all the frames, but instead of slowing everything down, what happens is that the video and audio get out of sync; the video starts to seriously lag behind the audio. Also, it unfortunately won't play Quicktime movies you download from the internet because those are compressed with Sorenson Vision. 6. Squeezing Performance Out Of Your System There are many ways to squeeze the best possible DVD performance out of your system. Some of these ideas are quite extreme, so investigate the ones you're comfortable with and ignore the ones that scare you. o Dont run KDE or GNOME. Use a light window manager like mwm or twm. Better yet, don't run any window manager--place your dvd playing commands in your .xinitrc file. o Stop all daemons and resident services you don't need. Better yet, go into single user mode and kill all unnecessary processes. o You can renice your dvd player to -20. This didn't work for me (it made video very jumpy), but it may work for you. If you're really feeling goofy, renice all the other processes to 20. o Set up your MTRR's correctly. o IDE device optimizations: Set read-ahead mode on, set IDE 32-bit I/O support, use DMA for transfers and load more than 1 sector per I/O interrupt. Assuming your DVD drive is /dev/hdd (secondary slave): /sbin/hdparm -a 1 -c 1 -u 1 -d 1 -m 16 /dev/hdd In the worst possible scenario, wrong settings with hdparm can hang your system or worse. This deserves a reading of the man page. Actually, when my system boots up, I run a script containing: /sbin/hdparm -a 1 -c 1 -u 1 -d 1 -m 16 /dev/hda /sbin/hdparm -a 1 -c 1 -u 1 -d 1 -m 16 /dev/hdb /sbin/hdparm -a 1 -c 1 -u 1 -d 1 -m 16 /dev/hdc /sbin/hdparm -a 1 -c 1 -u 1 -d 1 -m 16 /dev/hdd to speed up access to my hard drives as well. o Monolithic kernels are slower kernels. Build things as modules. 6.1. RAW-IO supported by the latest linux kernels. RAW I/O is supported, but if you don't have the correct interfaces, data will be read from the standard, buffered device. So if you want to use RAW IO (and you really should do that), you have to make: (if they don't exist) mknod /dev/rawctl c 162 0 mknod /dev/raw1 c 162 1 Also, you'd have to make them usable by the user running oms. This reduces CPU overhead by as much as 33%. 7. Errata I'm interested in keeping this howto up to date. Comments and suggestions are appreciated, and will be acted upon immediately. I can be reached at p@dirac.org. To join the livid mailing list, send an empty email to livid-dev-subscribe@linuxvideo.org To join the vlc mailing list, send an email to listar@via.ecp.fr with the word "subscribe vlc" in the body. To unsubscribe, send an email to listar@via.ecp.fr with "unsubscribe vlc" in the body.