DVD homebrewing…

July 2, 2007 | General | By: Mark VandeWettering

Every once in a while, I try to make some actual DVDs using software that I have lying around the house (namely, an Ubuntu box). A question occurred to me a couple of days ago: can I store uncompressed PCM video onto a DVD? It turns out the answer is yes, although the methodology using free tools was a bit convoluted. I’m writing some of it down here so I can find it again.

The first thing to realize is that PCM audio on DVDs is only legal when sampled at 48khz, instead of the 44.1khz that is the standard for audio CDs. To test, I ripped a file from one of my CDs using “grip” to store it in wav format. I then used the Swiss Army knife of sound conversion, sox, to resample it to 48khz and to store it in big endian, signed word format (2 channels):

sox input.wav -r 48000 -c 2 -s -w -x output.lpcm resample -q

The -x option tells it to swap the byte order: I think that DVDs expect audio in bigendian form: Intel boxes (such as my Ubuntu box) are little endian. If you forget this step, you’ll probably have nothing but annoying noise when you burn your cd. For some reason, I think the extension on the output file is significant, but I could be wrong.

To multiplex this with a properly formatted video file, you can use mplex:

mplex -f 8 -o output.mpg -L 48000:2:16 video.m2v output.lpcm

Try running mplayer.mpg on the resulting file. The sound should work, and that mpeg should be usable by programs like dvdauthor.

Oh, some more things: I was trying to figure out how to convert individual image files into mpeg video, and get the right aspect ratio. I was particularly interested in making 16:9 video that would look right on my HD TV set. I ended up using the ppmto4m program on a 960×540 file with square pixels, piping the result through y4mscaler to resize that to the 720×480 format that is standard for video dvds, and then using mpeg2enc to create the video file. To test this, I encoded a simple 16×9 grid pattern with a command line that looked like:

ppmtoy4m -n 3932 -r -F 24000:1001 -A 1:1 -I p grid.ppm | \
  y4mscaler -O preset=DVD_WIDE | \
  mpeg2enc -f 8 -o video.m2v

Why the odd size? Mostly to make the math turn out right. Ultimately, your image is going to be squished into a 720×480 mpeg stream. Oddly, that image has a 3:2 aspect ratio. To make a 4:3 image with square pixels and 480 lines, you’d need 640 horizontal pixels. These would get stretched out, so you wouldn’t really get the highest resolution possible (it’s about 12% low). To make an appropriate image, you’d need the full horizontal resolution (720) with enough vertical resolution to make pixels square (720×540).

If we do the same calculation with 16×9, we find that an input image of 720×405 would work out fine, but again, we wouldn’t get all the vertical resolution we need. If we do the minimum necessary vertical res, the horizontal resolution doesn’t work out to a whole number. Such untidiness doesn’t seem right to me. So, instead, I use the same vertical resolutio that we used in the 4:3 case, and computed the necessary horizontal resolution to match. You end up with 960×540.

(Note: Oh, I could stop being silly and use 854×480. It’s off by only around 0.08% from being square. Nobody could detect it)

None of this probably matters unless you are trying to be especially tidy with aspect ratios and encodings. But since I work at a movie studio, I try to be tidy.

Addendum: I also did some experiements adding MPEG II audio to these streams. I couldn’t get toolame to actually resample the sound from 44.1k to 48k, so I ended up using mp2enc, which worked fine but much slower. I’ll revisit this later. I haven’t really played with AC3 sound either.

[tags]dvdauthor[/tags]