dvd-to-vcd ========== This script can be used to convert DVD titles to VCD images that can be written to CD-R. These VCDs can be played with standalone hardware players as well as with software players on PCs. SVCD mode is supported as well. Furthermore, you can also produce MPEG files suitable for playback on the Sharp Zaurus (a Linux-based PDA). Finally, the input file does not have to be a DVD, so you can also use this script to convert other formats (AVI etc.) to VCD format. This doesn't always work very well, though, depending on the input material. 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 a lot of external programs to do the hard work. Under a recent FreeBSD with a recent ports collection, you should install the following ports (or packages): mjpegtools-1.6.0_1 mplayer-0.90.0.10_1 (or mplayer-gtk-0.90.0.10_1) sob-2003-01-02 sox-12.17.3_1 toolame-0.2i The "sob" tool is not in the ports collection yet, but you can download it from here: http://www.secnetix.de/~olli/tarballs/sob.tar.gz Install it like this (as root): tar xzf sob.tar.gz cd sob make install The above-mentioned ports are enough to create the MPEG system streams. To produce the actual VCD images and write them to CD-R, you will also need these ports: vcdimager-0.7.12_1 cdrdao-1.1.7_1 I guess newer versions of those tools will work, too, but I have tested the whole thing with the mentioned versions only. Another important thing: You must have filedescriptor nodes under /dev/fd, otherwise this script won't work correctly. FreeBSD 4 has support for such nodes by default, so you needn't worry. However, in FreeBSD 5 you'll have to set that up first: Add a line like this to /etc/fstab: fdescfs /dev/fd fdescfs rw 0 0 Then enter the command "mount /dev/fd". 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-vcd" without any options. After a few hours, you will have two files: a ".bin" file and a ".cue" file, suitable to be written to a CD-R using the cdrdao tool. The default is to encode title number 1 on the DVD to VCDs, assuming 80 minutes per VCD, using the default language (audio track). There is a bunch of options to change the defaults: -type Specify the output MPEG type to create. The following types are currently supported: vcd -- Basic VCD (2.0). svcd -- SuperVCD (SVCD). Note that SVCDs have a higher bitrate, so you will need more CDs to store a movie. While you typically need two CD-Rs to store a movie in VCD mode, you will need three to four CD-Rs in SVCD mode. Also note that encoding SVCDs takes considerably longer (typically twice as long). zaurus -- MPEG1 file, optimized for playing on the Sharp Zaurus PDA in full- screen landscape mode (i.e. with 90 degrees rotated display). small -- Same as "zaurus", but smaller, for display in normal portrait mode in the standard MediaPlayer (width is 220 pixels). For each of those types, a bunch of standard parameters are provided (size, bitrate etc). Most of them can be changed, see the section "Wizard Options". -img If this option is specified, create VCD images when the MPEG is done. This will create .bin and *.cue files suitable to be written to CD-R with the "cdrdao" tool. The MPEG files are deleted afterwards. Otherwise, if this option is not specified, the processing stops after the MPEG files have been created. -title Encode DVD title . The default is title 1. You can only encode one title at a time. To put multiple (short) titles on the same VCD as separate tracks, you can encode them separately, and then let vcdimager create a VCD image with multiple tracks. -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. You can also use this option to encode a file which is not from a DVD at all, but something else (an AVI file or a Quicktime movie). The format has to be supported by mplayer, though. If mplayer can't play the file, then you cannot encode it. You might need to specify the -aspect option for non-DVD files. -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. You also might need this option if the input file is not a DVD, but something else (an AVI file or whatever). In such a case, mplayer might not be able to detect its aspect ratio reliably. -deinterlace Some DVD movies require de-interlacing. To find out if you need this, play the DVD normally with mplayer and watch the edges of objects that are moving. When you notice "comb" effects, you will need de-interlacing. Try to play with mplayer again, but use the "-vop pp=0x20000" option. It should fix the effects. The "-deinterlace" option of this script does the same. -cdr Specify CD-R size, in minutes (74 or 80). The default is 80. Normally, a full DVD movie will not fit on a single CD-R. Therefore, multiple VCD images will be created automatically, splitting the movie in a way so that no image will be larger than this value. You can also specify a smaller value. For example, to split a 90-minutes movie on two VCDs so that they have about the same size, use the option -cdr 45. Note, however, that the splitting occurs in the middle of a scene, which might be a bit annoying. Therefore, it is usually a better idea to use the -chapter option to split the movie manually, encoding every VCD separately. -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 number of the VCD is appended to the base name. WIZARD OPTIONS ============== For each of the supported output MPEG types, a bunch of standard parameters for encoding is provided, which should work fine in most cases. The following options enable you to change most of those parameters -- but beware: You should know exactly what you are doing. Careless using of these options might cause the resulting files to be unplayable on some (or all) hardware DVD/VCD players. The default is to produce VCD images (VCD 2.0, to be exact), with a standard bitrate of 1152 kbit/s for video and 224 kbit/s for audio. -audiohz Specify the playback sample rate for the audio stream, in Hz. The default is 44100, which is required for VCD and SVCD compatibility. For Zaurus MPEG files, you can reduce it to, say, 22050 (and also reduce the audio bitrate), in order to save a bit of space, if you don't care too much about the audio quality. Note that only several distinct sample rates are supported. If you specify an unsupported one, the script will tell you so and print a list of legal values. You can also specify the value 0, which means to use the same sample rate as the input data. For a DVD, this is usually 48000 HZ, which is invalid for VCD or SVCD! Also note that the script will abort if the sample rate of the input data is not one of the sample rates supported for MPEG1 audio layer II. -audiobr Bitrate for the audio stream in kbit/s. (The audio stream is always MPEG1, audio layer II.) For VCD and SVCD compatibility it must be 224. For Zaurus MPEG files, the default is lower (128). Note that only several distinct bitrates are supported. If you specify an illegal one, the script will tell you so and print a list of legal values. -videobr Bitrate for the video stream in kbit/s. For VCD, this must be 1152, and for SVCD it may not exceed 2376 (but might be less). Otherwise you're pretty free to choose any value. The smaller it is, the smaller the resulting MPEG file will get, but it will also be of poorer quality. If you enable variable bitrate with the -varbrq option (see below), this value does not specify the real bitrate, but the MAXIMUM (peak) bitrate. -varbrq Enable variable bitrate mode and set the quantization level. 12 is a good value to start for . Smaller values (10 or 8) might improve the quality somewhat, but require a higher bitrate for compression. You might try to increase the value (for example 15) in order to squeeze a movie on three or even two SVCDs that would other- wise require four, at the expense of a certain quality loss. If you enable variable bitrate, note that the -videobr option (see above) specifies the MAXIMUM (peak) bitrate. Note that standad VCDs and SVCDs do not allow variable bitrate for the video stream (contrary to popular belief), but many standalone DVD/VCD players support it, at least for SVCDs (possibly not for VCDs). For Zaurus MPEG files, this option is by default enabled (the Zaurus MediaPlayer supports variable bitrate) with =15, but it can be disabled with -varbrq 0. There is no good reason to do so, though. -bands This option specifies what to do if the input material is in 16:9 display format. If you specify "-bands y", black bands will always be added at the top and at the bottom, and the resulting video will be encoded for 4:3 display format. This is the default for VCDs because they do not support 16:9 display format. If you specify "-bands n", then no bands will be added, and it is assumed that the output device will be capable of scaling the video correctly for anamorphic 16:9 format. This is the default for SVCDs. It is also the default for Zaurus files. (They won't be anamorphic, though, because square pixels are assumed, and the Media- Player will add bands itself. You needn't worry about this). For SVCDs: If your DVD player does not detect 16:9 format correctly, and you cannot convince your TV set to scale it to 16:9, then you should use "-bands y" to enforce 4:3 encoding. This will cost some more bits (and/or less quality), though. For VCDs: If you _can_ switch your TV to scale from 4:3 to 16:9, you can take that to your advantage by using "-bands n". This will improve quality. However, be aware that the resulting VCDs are not standards-compliant and will be displayed distorted when played the normal way. Of course, this whole thing applies only if the input material is in 16:9 format. If it isn't, then this option is ignored. -width Specify the width (in pixels) of the MPEG file. Do not change the default value for VCD and SVCD creation. For "zaurus" files, it is 320 pixels, and for "small" zaurus files, it is 220 pixels (the default width of MediaPlayer if not in fullscreen mode). Must be a multiple of 4. -height Specify the height (in pixels) of the MPEG file. Do not change the default value for VCD and SVCD creation. Normally you should not need to use this option, because the default will be calculated for you, based on various parameters (type, width, aspect ratio, etc.). -mpeg Specify the MPEG video version (1 or 2). The default is 1 for VCD and 2 for SVCD. Do not change. For Zaurus files, the default is also 1, because the standard MediaPlayer supports only MPEG1. MISCELLANEOUS TOPICS ==================== How many CD-Rs do I need to store a DVD movie? It depends on the length of a movie. The VCD bitrate is exactly the same of a standard (single-speed) audio CD. That means that a 80-minutes CD-R has space for about 80 minutes of VCD video. Therefore, for a full movie, which is usually 100 minutes or longer, you will need two CD-Rs. Note that SVCDs have a higher bitrate (up to twice as much if you stick to the standard), so you will need more CD-Rs to store the movie. How much free hard disk space do I need? About twice the space of the VCD images. As a rule of thumb, VCDs take 10 MB per minute, and SVCDs up to twice that much (depends on the bitrate). Example: If you encode a 2h movie to two VCDs of 60 minutes each, the VCD images will take 2 * 600 MB, and the script will need another 2 * 600 MB for temporary data, so the total space required is 2.4 GB. How long will it take? It depends on a lot of things: The kind of movie, your processor, whether you're encoding to VCD or SVCD, and in the latter case it also depends on the bitrate etc. Rule of thumb: On a 1 GHz machine, the VCD encoding will take roughly four times the playing time. That is, encoding a 90-minutes movie will take about six hours. Encoding to SVCD is even slower: it will take about twice that time. Encoding MPEG files for the Zaurus is noticeably faster. Of course, a faster CPU helps a lot. Also, if you have a multi-processor (SMP) system, it will help a lot, because several parts of the encoding can run in parallel. On the other hand, a fast disk drive will NOT help, because the I/O speed does not matter much. The encoding process is CPU-bound. Can I store DVD menues on VCDs? Sorry, that's not supported. Can I store multiple (small) titles on a VCD? Yes. Just encode all of the titles separately (make sure that they don't overwrite each other, i.e. use the -o option if necessary), and then use vcdimager manually. For example, to create a VCD with two tracks, containing the titles 1 and 2 of a DVD: dvd-to-vcd -title 1 -o title-one dvd-to-vcd -title 2 -o title-two vcdimager title-one1.mpg title-two1.mpg 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 onto several CDs? There are two possibilities. First, you could let the script take care of it automatically, by using the -cdr option to specify the CD-R size in minutes. The default is 80, which means that multiple images will be created to fit on 80-minutes CD-Rs. However, the disadvantage is that the splitting usually occurs in the middle of a scene, which might be a bit disturbing. Therefore, it is probably a better idea to use the -chapter option to split the movie manually, encoding every VCD separately. That second method might require 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 (or one third) of the movie, and note the chapter number. Then run the dvd-to-vcd script for every part, using the -chapter option specifying the chapter intervals that you found out with mplayer. Guessing the correct splitting space is not easy if you use variable bitrate (-varbrq option). In that case it is probably better to let the encoder decide where to split. See the -cdr option. END ===