Converting NTSC-Videos to PAL DVDs

General things

There are several approaches to convert NTSC-Videos to AVI, but I will only describe how to do it with mencoder. I'm sure there are people who prefer transcode for a lot of good reasons, but it took me several days to gather the information for mencoder and it just works, so why try something else ;o) In this tutorial, I will only focus on creating PAL-DVDs, but of course, you can simply modify the parameters and get an AVI. But I wouldn't know about any good reason to make a PAL-AVI out of an NTSC-AVI...

Why convert NTSC to PAL?

My DVD-player at home does not properly support telecined NTSC-material. If I play it there, audio and video get desync after some time, so it loops a bit back (like 5s or so) and replays a scene. This obviously sucks, but the main-problem is that subpictures are not displayed properly, because it seems to have troubles following the MPEG-stream

So I thought, the only solution to this would be what the film-industry does, too: playback the movie with 25fps instead of 23.976.

How to do it

We want the best quality available and have a tightly-fit DVD, so we use 2-pass-encoding. The parameters for the first pass are quite „simple“:

mencoder -ovc lavc \
         -nosound \
         -of mpeg \
         -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:keyint=15:aspect=16/9:vbitrate=3282:vpass=1 \
         -mpegopts format=dvd \
         -vf scale=720:432,expand=720:576,harddup \
         -sws 9 \
         -speed 25025/24000 \
         -ofps 25 \
         -o /dev/null \
         <file>

We tell mencoder that we want to use the excellect lavc-codecs for MPEG2-encoding into a DVD-compliant cintainer: -ovc lavc -of mpeg -mpegopts format=dvd.
We want no sound in our first pass, it slows down things alot: -nosound.
We need to resize the video which is a widescreen-movie in this example: -vf scale=720:432,expand=720:576,harddup.
If you don't have a wide-screen movie (4:3 or 16:9), use -vf scale=720:576,harddup.
We want extra-sharp resizing, so we use lanczos: -sws 9.
We need to pass some MPEG-specs, like aspect-ratio, bitrate, and so on: -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:keyint=15:aspect=16/9:vbitrate=3282:vpass=1:turbo,
but your vbitrate may vary, depending on the length of your movie and of course the aspect ratio depends on what the source-material is. Use 16/9 for 16/9 or widescreen, otherwise 4/3.
vpass=1 enables multi-pass encoding and gathers information about motion, etc. of the movie in a file divx2pass.log.
We need to playback the movie with 25fps instead of 23.976fps and mark it as 25fps: -speed 25025/24000 -ofps 25.
„Why 25025/2400” you might ask? 23.976 is just an approximation for 24000/1001. 25 / (24000/1001) = 25 * 1001 / 24000 = 25025 / 24000.
And since this is a first pass, we don't want it to create any mpeg-file at all: -o /dev/null.

The second pass is a bit more complicated as it involves audio-processing. You know that when you playback something faster, the pitch gets up. There are ways to compensate for that using appropriate filters, but shifting the pitch is far from being good. You will hardly ever notice the 4% increase in pitch anyway, so don't care about it. Also, playing back a 48000 Hz AC3 with 25025/24000 will result in 50050 arriving at the door of the audio-transcoder, we have to keep that in mind, too and downsample to 48000 Hz.

The first change we have to do for the second pass is remove vpass=1 and replace it with vpass=2. Then we don't want to encode to /dev/null, so we specify an output-file like -o /tmp/movie.mpg.
We also want to add some quality-enhancing filters to -lavcopts and resample the audio-stream into AC3 with 48.000 Hz and 2 or 6 channels. If you need to recode a 5.1-AC3, you should use
-lavcopts acodec=ac3:abitrate=448 -channels 6 -af volnorm,channels=6:6:0:0:4:1:1:2:2:3:3:4:5:5
otherwise use
-lavcopts acodec=ac3:abitrate=192 -af volnorm
The sounds gets also normalized on-the-fly.

The complete second call looks like this:

mencoder -ovc lavc \
         -oav lavc \
         -srate 48000 \
         -of mpeg \
         -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:keyint=15:aspect=16/9:vbitrate=3282:acodec=ac3:abitrate=448:vpass=2:trell:mbd=2:precmp=2:subcmp=2:cmp=2:dia=-10:predia=-10:cbp:mv0:vqmin=1:lmin=1:dc=10 \
         -mpegopts format=dvd \
         -vf scale=720:432,expand=720:576,harddup \
         -channels 6 \
         -af volnorm,channels=6:6:0:0:4:1:1:2:2:3:3:4:5:5 \
         -sws 9 \
         -speed 25025/24000 \
         -ofps 25 \
         -o /tmp/movie.mpg \
         <file>

Which bitrate?

One thing I haven't answered so far is how to calculate the bitrate for the video. It depends of course on the duration of the movie and the audio-bitrate as well as the DVD's capacity.

Let's assume, we have a 4.7GB DVD-R which is in fact 4.7 * 1000 * 1000 * 1000 bytes and not 4.7 * 1024 * 1024 * 1024.
The bitrate we have to give is in kbit/s where 1kbit is 1000 bits, not 1024 bits. The length of the movie is X seconds and the bitrate of the audio is A kbps.
We do now need 4.7 * 1000 * 1000 * 8 / X - A kbps for the movie.

Example:

4.7 * 1000 * 1000 * 8 / 5400 - 192 = 6770 kbps

Of course you should not calculate with 4.7 GB, because creating a DVD-filesystem consumes some space, too, as well as possible subtitles you might want to add. Maybe using 4.6GB as a start is better for you, just fiddle a bit :o)

And then?

Once you have this DVD-compliant MPEG, you can add subtitles with spumux and/or create a DVD-file-system with dvdauthor and then burn the DVD. An example spumux.xml-file looks like this:

<subpictures>
  <stream>
    <textsub filename="/tmp/subs.srt" characterset="ISO8859-1"
     fontsize="28.0" font="DejaVuSans.ttf" horizontal-alignment="center"
     vertical-alignment="bottom" left-margin="60" right-margin="60"
     top-margin="20" bottom-margin="10" subtitle-fps="25"
     movie-fps="25" movie-width="720" movie-height="572"
    />
  </stream>
</subpictures>
    

You have to have „DejaVuSans.ttf“ in ~/.spumux/ otherwise it won't work. Call spumux like this: spumux -m dvd -s 0 -P spumux.xml < /tmp/movie.mpg > /tmp/movie2.mpg

Afterwards, you have to create the DVD-filesystem and .IFO-files with dvdauthor. Use a configuration-file (e.g. in /tmp/dvdauthor.xml) like this:

<dvdauthor>
  <vmgm />
  <titleset>
    <titles>
      <video aspect="16:9" />
      <audio lang="en" />
      <subpicture lang="en" />
      <pgc>
        <vob file="/tmp/movie2.mpg" chapters="0,5:00,10:00,15:00,20:00,25:00,30:00,35:00,40:00,45:00,50:00,55:00,1:00:00,1:05:00,1:10:00,1:15:00,1:20:00,1:25:00,1:30:00,1:35:00,1:40:00,1:45:00,1:50:00,1:55:00,2:00:00,2:05:00,2:10:00,2:15:00,2:20:00,2:25:00,2:30:00,2:35:00,2:40:00,2:45:00,2:50:00,2:55:00,3:00:00" />
      </pgc>
    </titles>
  </titleset>
</dvdauthor>
    

Call dvdauthor like this: dvdauthor -o /tmp/dvd -x /tmp/dvdauthor.xml and then burn using your favourite tool.
You can for example use growisefs for this job: growisofs -dvd-compat -dvd-video -speed=8 -Z /dev/cd0 /tmp/dvd
or you can use cdrecord. Get a free registration key and use the pro-version:

export CDR_SECURITY="your registration-key for cdrecord.prodvd"
TSIZE=`mkisofs -dvd-video -q -print-size "/tmp/dvd"`
mkisofs -q -dvd-video "/tmp/dvd" | cdrecord.prodvd driveropts=burnfree speed=8 dev=1,0,0 fs=16m tsize=${TSIZE}s -v -dao -data -
    

Conclusion

mencoder is the hell of a tool for transcoding videos. Paired with lavc and ladspa, you can do just about everything you could dream of. It's just that the documentation lacks a few examples. Too many knobs to play with...

Any good?

If any of this was of any help for you, please let me know. And if there are improvements to be added, feel free to mail me, too. And just so you wonder... of course I scripted all the necessary steps, I don't fiddle with the parameters anymore, this is all done by a perl-script for me.


Last modified: 26.07.2006 [01:25:48]    102318013402@mark.reidel.info