Video with Linux

DV Video Workflow in Linux

Capturing DV video from a miniDV camcorder through firewire, editing, transcoding and then authoring a DVD is fairly straighforward with Linux. This document explains how to do it and a few pitfalls that may still exist or may not.

Needed Software

This method relies only on the following open source software.

Capture

Use dvgrab version 3.1 by Arne Schirmacher or later. Connect the firewire cable. Type
$ mkdir capture
$ cd capture
$ dvgrab -fraw -noavc src
and then press play on the camcorder. This will result in the files src001.dv, src002.dv and so forth being created in the capture directory. These are the DV stream files dumped direct from the camera.

We dump from the camera to a raw format file rather than directly multiplexing the DV video to an avi file during capture. This is to avoid bugs that sometimes manifest when the DV source suddenly switches between 16bit and 12bit audio or between standard and widescreen aspect ratios. After the files are captured, start kino with the command

$ kino src*.dv
to check the raw files. At this point we will do some preliminary editing with Kino and if necessary some more sophisticated editing later with Cinelerra.

For a simple project we will transcode each individual clip to a DVD compatible mpeg2 program stream and then join them together in a single title using dvdauthor. For a more complicated project we will paste the clips into Cinelerra edit them and then transcode the resulting video to a single DVD compatible mpeg2 program stream through a yuv4mpeg2 pipeline.

Preliminary Editing with Kino

Kino automatically splits each source file into clips that have contiguous time codes. If a clip is split across two files created by dvgrab join them back together to make one clip. Delete the clips that you don't want to use and trim the ones you with to keep. Now select the export tab in kino and select the export options DV AVI Type 2, OpenDML AVI, Auto Split Files and Resample Audio as follows.

It is important to select resample audio to avoid clicks that might occur when editing the files with Cinelerra. Since inexpensive camcorders have audio clocks which are not locked to the video clock, the exact number of audio samples for every frame of video usually does not correspond exactly to 48Khz. A click results when extra audio samples are thrown away to keep the sound in sync. Resampling corrects the audio track so it is locked to the video frame rate at exactly 48Khz. Since the audio is not in a compressed format nothing really bad happens to it with the resampling. Note that there is no transcoding of video at this step so it should go pretty quickly limited only by disk speed.

Simple Project

Suppose you have 13 avi files names s001.avi through s13.avi. Convert each file to a mpeg2 program stream using my script, ffmpeg, mencoder or mjpegtoos as described in the document creating DVD compliant program streams.

Authoring the DVD

Now you now have 13 mpeg2 DVD compliant program streams named g001.mpg through g013.mpg that can be concatenated together as one title on a DVD. Let's assume you also have two menus called menu-1.mpg and menu-2.mpg and an introductory logo called header.mpg. The following dvdauthor xml file contains two menus that select between the 13 chapters.
<dvdauthor>
    <vmgm>
        <menus>
            <video aspect="16:9" />
            <pgc entry="title">
            <vob file="header.mpg" />
            <post>jump titleset 1 menu;</post>
            </pgc>
        </menus>
    </vmgm>
    <titleset>
        <menus>
            <video aspect="4:3" />
            <pgc entry="root">
                <vob file="menu-1.mpg" />
                <button>jump title 1 chapter 1;</button>
                <button>jump title 1 chapter 2;</button>
                <button>jump title 1 chapter 3;</button>
                <button>jump title 1 chapter 4;</button>
                <button>jump title 1 chapter 5;</button>
                <button>jump title 1 chapter 6;</button>
                <button>jump title 1 chapter 7;</button>
                <button>jump title 1 chapter 8;</button>
                <button>jump title 1 chapter 9;</button>
                <button>jump menu 2;</button>
            </pgc>
            <pgc>
                <vob file="menu-2.mpg" />
                <button>jump title 1 chapter 10;</button>
                <button>jump title 1 chapter 11;</button>
                <button>jump title 1 chapter 12;</button>
                <button>jump title 1 chapter 13;</button>
                <button>jump menu 1;</button>
            </pgc>
        </menus>
        <titles>
            <video aspect="16:9" />
            <pgc>
                <vob file="g001.mpg" />
                <vob file="g002.mpg" />
                <vob file="g003.mpg" />
                <vob file="g004.mpg" />
                <vob file="g005.mpg" />
                <vob file="g006.mpg" />
                <vob file="g007.mpg" />
                <vob file="g008.mpg" />
                <vob file="g009.mpg" />
                <vob file="g010.mpg" />
                <vob file="g011.mpg" />
                <vob file="g012.mpg" />
                <vob file="g013.mpg" />
                <post>call menu;</post>
            </pgc>
        </titles>
    </titleset>
</dvdauthor>
Note that the aspect ratio of the menus is set to 4:3 aspect ratio even though the main video is 16:9 aspect ratio. This is to overcome a bug in dvdauthor that seems to tags the button overlays as 4:3.

Final Editing with Cinelerra

Now suppose we are not satisfied with the clips simply being pasted together by dvdauthor, but want to do something fancier with Cinelerra first. Load the avi files into Cinelerra and edit until you have a reasonable video. Since DV files are interlaced please consult Editing Interlaced Video with Cinelerra to avoid difficulties. Then render the video through a yuv4mpeg pipe using the script
#!/bin/sh
yuvcorrect -T INTERLACED_BOTTOM_FIRST |
mpeg2enc -M0 -nn -a3 -f8 -G18 -b7000 -V230 -q9 -o $1
Similar scripts can be used to pipe the output of Cinelerra into ffmpeg and mencoder. Render the audio track as a wav file. Then multiplex the video and audio together using the commands
$ toolame -b224 -s48 final.wav final.m2a
$ mplex -f8 final.m2v final.m2a -o final.mpg

Authoring the DVD

Load the final.mpg into avidemux_gtk and locate appropriate start times for the 13 chapters. Cut and paste from the time display in avidemux

and make a list of chapter start times as

chapters="0,1:00,3:14.35,6:14.52,8:08.408,9:00,10:00,11:00,12:00,13:32.12,
    14:25,15:10,18:23.15"
Let's again assume you have two menus called menu-1.mpg and menu-2.mpg and an introductory logo called header.mpg. The dvd.xml file for dvdauthor should now look like
<dvdauthor>
    <vmgm>
        <menus>
            <video aspect="16:9" />
            <pgc entry="title">
            <vob file="header.mpg" />
            <post>jump titleset 1 menu;</post>
            </pgc>
        </menus>
    </vmgm>
    <titleset>
        <menus>
            <video aspect="4:3" />
            <pgc entry="root">
                <vob file="menu-1.mpg" />
                <button>jump title 1 chapter 1;</button>
                <button>jump title 1 chapter 2;</button>
                <button>jump title 1 chapter 3;</button>
                <button>jump title 1 chapter 4;</button>
                <button>jump title 1 chapter 5;</button>
                <button>jump title 1 chapter 6;</button>
                <button>jump title 1 chapter 7;</button>
                <button>jump title 1 chapter 8;</button>
                <button>jump title 1 chapter 9;</button>
                <button>jump menu 2;</button>
            </pgc>
            <pgc>
                <vob file="menu-2.mpg" />
                <button>jump title 1 chapter 10;</button>
                <button>jump title 1 chapter 11;</button>
                <button>jump title 1 chapter 12;</button>
                <button>jump title 1 chapter 13;</button>
                <button>jump menu 1;</button>
            </pgc>
        </menus>
        <titles>
            <video aspect="16:9" />
            <pgc>
                <vob file="final.mpg" 
chapters="0,1:00,3:14.35,6:14.52,8:08.408,9:00,10:00,11:00,12:00,13:32.12,
14:25,15:10,18:23.15" />
                <post>call menu;</post>
            </pgc>
        </titles>
    </titleset>
</dvdauthor>
Create the DVD file structure with the command
$ dvdauthor -o final -x dvd.xml
You can check your DVD image using the command
$ vlc final

Burning the DVD

Once you are satified the menus work properly, burn the DVD with the commands
$ growisofs -dvd-compat -dvd-video -Z/dev/dvd disk1
The final disk should play on most DVD players.

Conclusions

It should be noted that both the simple project and the project edited with Cinelerra involve no intermedia encoding steps. Therefore, there is no generation loss during the editing process and the resulting DVD should have the best quality that is possible to obtain from the sources.
Last Updated: Wed Jul 15 23:28:05 PDT 2009