dvd-to-divx =========== This script can be used to convert DVD titles to DivX (MPEG4) AVI files. The script has specifically been written to run on BSD (particularly FreeBSD), but it should be usable on other UNIX systems, too, and possibly also on Linux. COPYRIGHT, LICENSE AND DISCLAIMER ================================= Copyright (C) 2002/2003 by Oliver Fromme, Germany All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The code may not be be redistributed under any version of the GNU public license (GPL or LGPL), in whole or in part. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Note that it is your responsibility to obey copyright licenses and other legal prerequisites. Basically that means that you must use this script for legal purposes only, which is usually restricted to personal backup copies and similar things. If you are not sure that your using of this script is legal and authorized, then do not use it. SUPPORTED PLATFORMS =================== I have developped and tested this script on FreeBSD 4.7 with a bunch of PAL DVDs. I have not tested any NTSC DVDs, but in theory it should work as well. If it does not work, it would be most helpful to send me such a DVD so I can test it myself. Basically, if mplayer works on your platform, and your /bin/sh is not an ancient AT&T beast, then this script will work as well. If mplayer does not playback DVDs on your machine, then this script will not work either. If your /bin/sh doesn't cooperate, then use ksh, zsh or bash to execute the script. FreeBSD's /bin/sh works fine, as well as zsh in sh-emulation-mode. PREREQUISITES ============= This script uses mencoder which is part of the mplayer software suite. Under a recent FreeBSD with a recent ports collection, you should install the following port (or packages): mplayer-0.90.0.10_1 (or mplayer-gtk-0.90.0.10_1) I guess newer versions will work, too, but I have tested it with the mentioned versions only. SYNTAX AND USAGE ================ In the most simple case, insert a video DVD into your DVD-ROM drive, change to a directory that contains a few Gbytes of free space, and enter the command "dvd-to-divx" without any options. After a few hours, you will have one ".avi" file which nicely fits on a 700 Mbyte CD-R. The default is to encode title number 1 on the DVD to DivX (MPEG4) AVI, assuming a maximum size of 700 Mbytes, using the default language (audio track). There is a bunch of options to change the defaults: -videobr Maximum video bitrate in kbit/s (default is 1500). The actual bitrate might be lower, in order to fit the AVI file into the size specified by the -mb option (see below). -mb Maximum Mbytes of the encoded stream (default is 700). The average video bitrate will be calculated so that the AVI file won't be larger than the given number of Mbytes. Actually it can be much smaller if the maximum bitrate specified by the -videobr option (see above) is already small enough. -title Encode DVD title . The default is title 1. You can only encode one title at a time. -chapter Encode chapter(s) . The default is to encode all chapters of the selected title. You can either specify a single chapter, or a range of chapters (e.g. 10-15). When specifying a range, you can omit the first or the last number, so "-20" is the same as "1-20", and "12-" will encode from chapter 12 to the last one of that title. -file Encode this file instead of reading from DVD. The file should be created using mplayer's -dumpstream option, for example: mplayer -dumpstream -dvd 1 -chapter 1-8 This will reduce the stress on your DVD- ROM drive considerably, because mplayer -dumpstream takes only a few minutes, but encoding directly from DVD will keep your DVD-ROM drive running for several hours. On the other hand, you will need a few Gbytes of free disk space for the file. -lang Specifiy the language code for audio. This is usually a two-letter code, e.g. "en" for English or "de" for German. You can also specify multiple ones, separated by comma: "de,en" means to use the German soundtrack, and if that's not available, fall back to the English one. Be sure to specify the right language! It's very annoying to waste some hours of processing time and then find out that the movie was encoded with Finnish or Chinese audio or whatever ... -aspect Force input aspect ratio (16:9 or 4:3) if mplayer doesn't detect it correctly. Normally you don't need this option, as the correct aspect ratio will be detected automatically. However, under rare circumstances, mplayer seems to exhibit a bug and fails to detect 16:9 correctly. I have found one DVD so far where this happens. In that case, use this option to enforce the right aspect ratio. -width Set the width of the DivX/AVI in pixels. The height will be calculated automatically, depending on the aspect ratio. The default is 640 for 16:9 and 560 for 4:3, which leads to sizes 640x360 and 560x420, respectively. -crop Crop the movie to the given aspect ratio, removing black bands. Improves quality. Useful if the DVD movie has a target aspect ratio of 16:9, but is actually smaller. Common values are 2.35 and 1.85, see the backside of the DVD box. DO NOT use this option unless the movie really has the specified aspect ratio -- otherwise you cut off parts of the movie. In particular, additional features and trailers on the DVD might be larger than the main movie, so use with care. -o Specify the base name for output files. The default is to use the DVD title number or, if the -file option is used, the input file name. The extension ".avi" is appendend to the base name. MISCELLANEOUS TOPICS ==================== How many CD-Rs do I need to store a DVD movie? One. :-) But seriously ... By default, the script will create exactly one AVI file that will be no larger than the size specified with the -mb option (default: 700 MB). Of course, that means that the quality will be worse for long movies, because the bitrate will be reduced so that the given filesize is reached. In that case, you should consider splitting the movie in half, so you can put it on two CD-Rs. To do that, find the chapters which are about in the middle of the movie, and then run this script twice, using the -chapter option appropriately. However, if you do not intend to put the AVI files on CD-R at all, but store them on harddisk or somewhere else with sufficient space, then you can also specify some larger value for the size, such as "-mb 1200", to create one large file. Note that the bitrate will never exceed the maximum specified with the -videobr option, so the actual file might be smaller. How much free hard disk space do I need? The space of the AVI file that will be created, plus a bit for temporary data, but this isn't much. The AVI size plus 25% should be plenty. How long will it take? It depends on a lot of things: The kind of movie, your processor, the bitrate, width and height etc. Rule of thumb: On a 1 GHz machine, a 90-minutes movie will take roughly four hours, using the default values for the various parameters. Can I store DVD menues in the AVIs? Sorry, that's not supported. Can I encode from a file, instead of from DVD? Yes. In fact, that's a very good idea, because it will reduce the stress on your DVD-ROM drive. But you will need several GB of additional temporary disk space for the DVD data. See the description of the -file option for detailed instructions. How can I split a DVD movie into several AVI files? See the first question ("How many CD-Rs ..."). Basically, it requires a bit of trial and error to find out the best chapter numbers for splitting. Use mplayer with OSD time display and skip to the scene where the time is about half of the movie, and note the chapter number. Then run the dvd-to-divx script for every part, using the -chapter option specifying the chapter intervals that you found out with mplayer. For example: dvd-to-divx -title 1 -chapter 1-20 -o part1 dvd-to-divx -title 1 -chapter 21-40 -o part2 What's the -crop option good for? This requires a bit of explanation first. DVDs movies are encoded for 4:3 or 16:9 display. Your DVD player and/or your TV set can handle both cases, so you don't have to worry about it, normally. For example, if you only have a 4:3 TV set, then your DVD player will add black bands at the top and at the bottom if the movie is encoded at 16:9. So far, so good. But some DVD movies actually have an aspect ration of 1.85:1 or 2.35:1. But the DVD standard does not support these, so the movies are encoded at 16:9 (which is about 1.78:1), with black bands added at the top and bottom. These bands are already on the DVD, wasting space. Your DVD player is not aware of them, neither is "mplayer". Of course, you can encode such movies with the default options, just as if it was a normal 16:9 movie. That will work fine. However, the black bands will also be in the resulting AVI, wasting space and bits. Now the -crop option comes into play. The black bands will be removed, which saves space in the AVI file that can be used to encode the actual movie at higher quality (or smaller file size). Also, encoding will be faster. For example, when you specify "-crop 2.35", you tell the script that the actual movie has an aspect ratio of 2.35:1, centered inside a frame of 16:9, and that everything outside of that area can be removed. There is no way to reliably verify this, so the script will trust you and cut those bands off, whether they're black or not! How do I find the right value for the -crop option? Look at the backside of the DVD box, where all of the data is written: Region code, languages, subtitles, audio format etc. It also (usually) mentions the picture format. If it says "4:3", do NOT use -crop. If it says "16:9" _only_, do NOT use -crop. If it says something like "2.35:1" or "1:2.35", possibly in addition to "16:9", then you can use "-crop 2.35" for the main movie. However, if you encode additional titles from the DVD (such as trailers, interviews, making-of, or other special features), the aspect ration usually does not apply to them, so do not use the -crop option for those, unless you are sure that it applies! It is usually a good idea to encode one chapter first (probably a chapter which is reasonably short), and verify that the cropping worked correctly, i.e. no part of the movie was accidentally cut off at the top or bottom. END ===