Saturday, 4 February 2006

FreeBSD for Video

Using FreeBSD for Video and DVDs

I've just spent the last week using FreeBSD to create some DVDs for my Brother's birthday. I am a fan of a UK series from the early 90s called "The Secret Life of Machines". I downloaded three series from the web encoded with Xvid mpeg4. At first I tried using Sony's DVD Architect. Its a nice bit of software, after downloading an array of kiddy-ware and codec packs for Windows - in an attempt to get DVD Architect to load the Xvid files without conversion, I stumbled across the fact that you can just change the four char code to DIVX/divx and both Vegas and DVD Architect will recognise the files...or so you think. It turns out that DVD Architect doesn't like variable bitrate mp3 - so the resultant DVDs have skipping audio and considerable lag between audio and video. A bit of VirtualDub meant that I could extract the audio to uncompressed PCM, and add it in as the soundtrack in DVD Architect. Some of these lessons are hard to learn when the processes take so long, re-encoding the video and burning the DVD took about 9.5 hours on my 2Ghz Athlon XP.

This all worked great for 2 of the series. The third kept failing after about 6.5 hours - no errors, it would just stop updating the progress bar. The quality of the software I was using (VirtualDUB, codec packs etc) was giving me cause for concern, and most is pretty ugly anyway, so I decided to get to grips with doing it under FreeBSD. I've been pleasantly surprised lately how good Mplayer is when you do more than scratch the surface. I don't use the interface, the power is hidden in the command line. I won't watch TV/DVDs without Xvidix extensions running nowadays, and figured there must be a way of re-encoding DivX to MPEG2.

I ended up following this Gentoo how to. If you know FreeBSD, its pretty easy to adapt. Rather than writing my own XML for DVDAuthor, I used DVDStyler. To get DVDStyler working properly, you need to add support for ATAPI to your kernel:

options atapicam

Then add the apprpriate links and permissions in /etc/devfs.conf - mine looks like this (the pass0 was a new one on me)

link acd0 cdrom
link cd0 dvd
perm acd0 0660
perm pass0 0660
perm cd0 0660

I had to modify the transcode flags to compress the MPEG2 to get six episodes onto one disk and to maintain the 48khz audio - I was getting squeaky soundtracks before this. and make sense of the 4:3 aspect of the original. I ended up with the line:

transcode -i Secret\ Life\ Of\ Machines\ 101\ The\ Vacuum\ Cleaner.avi -y ffmpeg --export_prof dvd-pal --import_asr 2.21:1 --export_asr 2 -o Vacuum -D0 -b224 -N 0x2000 -w 3000 -s2 -m Vacuum.ac3 -J modfps=clonetype=3 --export_fps 25

Once you've set this up you should be able to do use the following to 'mux' the audio and video into one MPEG2 file.

mplex -f 8 -o matrix_dvd.mpg matrix.m2v matrix.ac3

Which DVDStyler will accept as compliant content, and away you go...The last thing which bit my bum, was setting the Menu frame count in DVDStyler - I used a figure of 180 - without this your DVD player will flash your menus at you tantalisingly for only 1 second...