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 http://www.vcdhelp.com/dvdplayers.php 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.
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.
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
done
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.
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.
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
where
01.avi
, 02.avi
, etc. are the avi files produced in the
subtitling step.-S 800
specifies the maximum size of the output file, in
megabytes. The above example is for an 80 minute CD. In general the
maximum size in MB should be ten times the play length of the blank CD
as an audio CD. This size is larger than the official capacity of the
CD as a data CD, since the SVCD standard omits the error correction
that the data CD standard uses.-B 192
indicates the anticipated bitrate of the audio
track, which you have to input to mpeg2enc since it does not know what
bitrate you have chosen to use for the audio. To be safe, this number
should be one increment larger than the actual bitrate of your .mp2
audio track, since the mastering process which follows will add
additional overhead.-I 1
tells the encoder to treat this material as interlaced
source material. See
Myths about DeInterlacing for an explanation of why you do not want
to deinterlace SVCD video (basically, it's because SVCD discs are
intended to be played on your TV screen, which prefers interlaced
video).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.
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.
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:
lav2yuv 01.avi [02.avi ...] | yuvscaler -n n -O SVCD | mpeg2enc -a 3 -f 4 -F 4 -S 800 -B 192 -I 1 -o output.m2v
The only difference from the
TV case is the use
of the option -a 3
to indicate the widescreen aspect ratio.
lav2yuv 01.avi [02.avi ...] | yuvscaler -n n -M WIDE2STD -O SVCD | mpeg2enc -a 2 -f 4 -F 4 -S 800 -B 192 -I 1 -o output.m2v
In this case, you use -a 2
as in the
TV case, but add the option -M WIDE2STD
to yuvscaler
which
tells it to resize the widescreen video down to TV size and add the
black borders.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.
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:
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.
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:
mplex -f 4 -V -o file.mpg output.m2v audio.mp2
vcdimager -t svcd -l "Title of disc" -c svcd.cue -b svcd.bin file.mpg
cdrdao write -v 2 --driver generic-mmc --device 0,0,0 svcd.cue
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.
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
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.