Friday, 7 August 2009

Automatic Video DVD Creation under Linux using command line tools

Doing DVD creation properly is a pain. Firstly, you have to master a GUI creation tool. Secondly, every DVD you create seems to involve too much manual work. Wouldn't it be nice if you could just throw a load of mpeg files into a directory and run a couple of commands.

I couldn't find anything out there to fit the bill, so I rolled my own. You can download everything you need in dvd-create.tgz

The prerequisites are the dvdauthor, cdrtools and MPlayer packages. Use your linux distros' package manager to ensure they are installed and up-to-date.

Unpacking dvd-create.tgz gives you a directory dvd-create. Within the directory are three main control scripts: create.sh, burn.sh and play.sh.

Start by copying the mpeg files you want on your DVD into the dvd-create directory. The files will appear on the DVD in alphabetical order, so if required rename (or numerically prefix) them so that the directory listing shows them in the correct order. Then use the create.sh script to process the mpeg files, generate a dvd.xml control script for dvdauthor then run dvdauthor to create the DVD structure within the subdirectory dvd.

#!/bin/bash
rm -f dvd.xml dvd-body.xml
chapter=$(( 0 ))
for f in *.mpg
do
echo " " >> dvd-body.xml
chapter=$(( $chapter+1 ))
done
cat dvd-head.xml dvd-body.xml dvd-foot.xml > dvd.xml
dvdauthor -o dvd -x dvd.xml
The second step is to burn the generated DVD structure to a DVD using the burn.sh script. If you dvd device is not located at /dev/cdrom you will need to edit the script to use the appropriate device.

#!/bin/bash
growisofs -dvd-compat -Z /dev/cdrom -dvd-video ./dvd/

The last step is to test the DVD you've just created using the play script, play.sh. This fires up the mplayer media player to view the contents of the freshly created DVD.

#!/bin/bash
mplayer dvd:// -dvd-device ./dvd

How quick was that!

0 comments: