Next Previous Contents

5. Making an SVCD

SVCD encoding is much harder than divx encoding. The codec is inferior (mpeg2 instead of mpeg4), meaning that a higher bitrate is required to attain the same quality. Most movies, which fit quite comfortably on one CD using divx, require two CDs for acceptable quality using SVCD. The 16:9 aspect ratio most commonly used by movies, although required by the SVCD spec, is not implemented in the vast majority of DVD players, so you have to letterbox the video to 4:3 in order to make it play in most DVD players. Finally, most film source material is originally 24 frames per second, and special measures must be taken to prepare such video streams for display on the ~60 fields/sec NTSC television standard.

The major advantage of the SVCD format is that it will play on most standalone DVD players (see for compatibility lists), as well as on your computer.

Still interested in creating SVCDs? The first thing to do is to rip the .vob files off the DVD and (if subtitling) obtain and prepare a timed script for mplayer. Since these steps are unchanged, I refer you to the previous sections instead of repeating the information here.

5.1 Encoding the audio

The SVCD format uses mpeg audio, but the specification only permits layer 1 or layer 2 audio. Layer 3 audio, such as used in mp3s, is not supported. So we have to encode the audio using a layer 2 encoder such as TooLAME.

Another complication is that most DVDs contain 48 kHz audio, but the SVCD specification mandates 44.1 kHz audio. So it is also necessary to downsample the audio to 44.1 kHz.

Putting it all together, the process looks something like:

mplayer -ao pcm -aofile audio.48.wav -vo null -hardframedrop filename.vob
sox audio.48.wav -r 44100 audio.wav resample
toolame -b 160 -p 2 audio.wav audio.mp2

The -p 2 option tells toolame to use psychoacoustic model #2 (which in my opinion is the best one). The -b 160 option indicates a bitrate of 160 kbit/s, which you can adjust to whatever you want.

5.2 Inserting subtitles into the video

We use the mencoder program to insert subtitles into the video as before, except that this time we use the mjpeg codec for output instead of the divx codec. The use of mjpeg is necessary because the mjpegtools suite of programs (which contains the mpeg2enc encoder that we will use later) expects an mjpeg video stream as input.

Since the mjpeg file is only an intermediate file format on the way to the desired mpeg2 output, and yet is nevertheless a lossy format, it makes sense to use as high a bitrate as possible for the mjpeg output to ensure that the intermediate file does not itself introduce any encoding artifacts into the final result. Unfortunately, here we run into a major limitation of the .avi file format: the maximum size of an .avi version 1.0 file is 2 GB, and while mencoder will happily write an .avi file exceeding 2 GB, the mjpegtools suite of programs will only recognize the first 2 GB of contents in such a file. (Yes, you can blame this limitation on Microsoft, since they created the .avi format.)

One workaround is to rip each track from the DVD into a separate .vob file, and create a separate .avi for each .vob. For example, if you want the first title of a DVD and the title has 29 chapters, do:

# bash script only; tcsh users are on their own!
for i in `seq -w 29`; do
tccat -i /dev/dvd -T 1,$i-$i > $i.vob
mencoder -nosound -sub script.mpsub -ffactor 1 -ovc lavc -lavcopts vcodec=mjpeg:vhq:vbitrate=15000 -o $i.avi $i.vob

The resulting output files will be named 01.avi, 02.avi, etc. Later on we'll use lav2yuv to merge all the .avi's back into one video stream.

5.3 Encoding the video

We assume in this section that your TV equipment is NTSC. If you have PAL equipment, you can consult the excellent Linux SVCD Guide (written in French) for how to handle PAL input and output.

It is necessary to split the discussion into separate sections for TV source material (4:3 aspect ratio, 29.97 frames per second) and film source material (16:9 widescreen aspect ratio, 24 frames per second), because of the differences that arise when dealing with different frame rates and screen sizes.

DVDs of TV shows

This is actually the easiest case. The video on the DVD is sized for a 4:3 display and uses the NTSC standard of 29.97 frames per second, which both happen to be exactly what most standard NTSC televisions use. You can therefore transcode the DVD straight over to SVCD with minimal modifications.

The recipe is:

lav2yuv 01.avi [02.avi ...] | yuvscaler -n n -O SVCD | mpeg2enc -a 2 -f 4 -F 4 -S 800 -B 192 -I 1 -o output.m2v

Be prepared to wait a long time for the encoding to finish--my Athlon XP 1700+ system encodes at a little under half of realtime playback speed.

DVDs of theatrical releases

Film material typically originates as 24 frames per second widescreen (16:9) video, and must be resized to 4:3 and converted to 30 frames per second for display on an NTSC television set. Let's talk about the resizing first, since it is easier.

Aspect ratio issues

If your DVD is already resized to 4:3 on the disc itself (that is, it is either "pan & scan", or "letterbox" with added black borders), then you can use the same flags as in the TV section.

If your DVD is 16:9 widescreen, then you can either burn a widescreen SVCD or resize the video to 4:3 (adding black bars in the process) and burn a normal 4:3 SVCD. The first option sounds very attractive, except that almost no standalone DVD players actually implement playback of widescreen SVCDs! You can burn yourself a test disc to find out if your DVD player can play widescreen SVCDs. Of course, computers will play widescreen SVCDs just fine.

Here is what to do, depending on which option you choose:

Do not actually run these commands yet, since you may also have to add further options to the command line to deal with frame rate issues, as described in the next section.

Frame rate issues

Video from film, or in general from any 24 frames per second source, must be converted to 30 fps in order to play on an NTSC TV set. There are three ways that this conversion process (called "telecine") can be done:

  1. It can be done in analog, prior to DVD encoding, and then encoded by the DVD encoder as a normal 30 frames per second stream.
  2. It can be done by the DVD encoder, which in this case is programmed to accept a 24 fps input stream and produce 30 fps output by adding duplicated fields.
  3. It can be done by the DVD player or decoder at playback time. This trick is accomplished by storing the video on disc as 24 fps and setting a special "pulldown" flag on the disc that directs the DVD player to telecine the video on the fly.

The first case is rare, and bad when it happens, since there is no way to recover the original 24 fps video after it has been messed up by analog mixing. Your only choice here is to encode it as a normal 30 fps video stream as in the TV case; however, if the aspect ratio is widescreen (16:9), then you will also have to add in the relevant options for dealing with widescreen.

The third case is good, because it means you only have to encode 24 frames every second instead of 30, but unfortunately it is also very rare. When it happens, the thing to do is to set mpeg2enc to output 24 fps (or, technically, 23.976 fps since NTSC is not exactly 30 fps) and add the -p option to mpeg2enc to tell it to add the "pulldown" flag to the video stream, so that the DVD player will know to perform telecine. You must also add the -I 0 flag to indicate no interlacing, since in this case the underlying 24 fps video originates from film source, which has no interlacing. The complete command line looks something like:

lav2yuv 01.avi [02.avi ...] | yuvscaler -n n -O SVCD | mpeg2enc -a 3 -f 4 -F 1 -p -S 800 -B 192 -I 0 -o output.m2v
where -F 1 sets the frame rate to 23.976 fps and -p adds the pulldown flags to the output. Don't forget to also adjust the flags controlling aspect ratio as described in the previous section.

The second case is by far the most common case. Here the encoder that was used to produce the DVD will speed up the output frame rate to 30 fps and insert duplicate fields to compensate for the faster frame rate. One thing that you can do in this case is to proceed as in the first case, treating the video as normal 30 fps video. However, in most cases you can gain significant encoding quality by first undoing the telecine (in a process called "inverse telecine"), and then encoding the untelecined video and setting the pulldown flag to tell the player to telecine.

The program yuvkineco which comes with mjpegtools lets you do inverse telecine in linux. To use it, just insert it in the pipe as follows:

lav2yuv 01.avi [02.avi ...] | yuvkineco -F 1 | yuvscaler -n n -O SVCD | mpeg2enc -a 3 -f 4 -F 1 -p -S 800 -B 192 -I 0 -o output.m2v
This example produces widescreen output; see the aspect ratio section to find out if you need to use letterbox output instead.

5.4 Mastering and burning the SVCD

Once you have the mpeg2 video encoded as an .m2v file, there are only three steps left to generate the SVCD, and all of them are easy:

That's it!

5.5 Other SVCD tricks

The easy way out

The mplayer program comes with a script called mencvcd (in the TOOLS/ subdirectory) that automatically converts anything mplayer can play onto a VCD or SVCD. Most of the time it works very well, but on some occasions it delivers the audio and video streams badly (and irregularly) out of sync. Another problem with this script is that it doesn't produce the highest quality possible, since it doesn't use toolame or attempt any inverse telecine. It may still be worth trying, however.

Multitrack SVCDs

To make an SVCD with multiple tracks, simply make multiple .mpg files and pass them all to vcdimager at once:

vcdimager -t svcd -l "Title of disc" -c svcd.cue -b svcd.bin file1.mpg file2.mpg file3.mpg

Higher quality encodes

If you are willing to wait several times longer for your video to finish encoding, there are a couple of options you can use to somewhat improve the quality of your video stream.

Adding the -M BICUBIC option to yuvscaler will improve the quality of the rescaling algorithm used in resizing your DVD down to SVCD size. You can also add the rather cryptic options -4 1 -2 1 to mpeg2enc to make it work harder to try to improve the encoding quality.

Next Previous Contents