Converting DivX files to mpegs for an NTSC DVD


You have a bunch of DivX avi files and want to put them on a DVD for a friend. The friend wants to play the final product on a DVD player (not on a PC).


Believe it or not, my first inclination was to fire up my old Windows XP computer because it has all of the Sony programs on it–including DVD Architect. To make a long story short, Windows proved itself once again as an inferior system. The DivX files have to be converted to mpeg. I tried several converters which ran for hours at a time. I finally had 3 converted files ready to burn. I thought everything worked fine until I played the DVD on a machine. It looked horrible and skipped a lot…unacceptable.

Fortunately I have Linux which helped produce a much better final product. My originals were all 16:9 widescreen, but I wanted to make them work on a 4:3 system. After installing ffmpeg (on Fedora, do this: sudo yum install ffmpeg -y), here is the command I used to do the conversion:

ffmpeg -i originalfile.avi -target ntsc-dvd -aspect 4:3 -s 720x400 -padtop 40 -padbottom 40 outputfile.mpg

Looks hairy, but it works well. I discovered the actual size of my original files are 720×400 by looking at the output of ffmpeg. So I kept this size and padded 40 to the top and bottom to create the letterbox. For reference, here some sample output from ffmpeg:

Seems stream 0 codec frame rate differs from container frame rate: 30000.00 (30000/1) -> 23.98 (24000/1001)
Input #0, avi, from 'filename.avi':
Duration: 00:44:12.1, start: 0.000000, bitrate: 1239 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 720x400, 23.98 fps(r)
Stream #0.1: Audio: mp3, 44100 Hz, stereo, 112 kb/s
Output #0, dvd, to 'filename.mpg':
Stream #0.0: Video: mpeg2video, yuv420p, 720x480, q=2-31, 6000 kb/s, 29.97 fps(c)
Stream #0.1: Audio: ac3, 48000 Hz, stereo, 448 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding

Then I decided to wrap it in a little perl script so I could do all 24 of the files without sitting around watching the progress:

$dir = '/home/adam/';
opendir(DIR, $dir);
@files = readdir(DIR);
closedir DIR;

foreach (@files) {
next unless $_ =~ m/^([\w\.]*)\.avi$/i;
# This should all be on one line...
print `ffmpeg -i $_ -target ntsc-dvd -aspect 4:3 -s 720x400 -padtop 40 -padbottom 40 -y $1.mpg`;

As usual, this is mostly for my reference, but maybe somebody else will also find it useful.