How to record from Plextor ConvertX TV-402U to DVD

Abstract

We are going to demonstrate the linux commands needed to sample an analog video signal with a Plextor ConvertX box, and without further lossy video processing, write that video to a DVD for viewing in a standard DVD player. The target audience is a linux user that knows basic filesystem commands, can install software, and has a linux system with working go7007 drivers.

Table of Contents

Technical Notes

NTSC-DVD is a valid region 1 DVD format.

Recording

Default tool for the Plextor ConvertX is gorecord - you'll want to use a version patched to keep A/V sync. Gorecord source code comes with the driver.

If you do not patch gorecord, no audio-video synchronization is forced. This means that the video capture clock and audio capture clocks are not synchronous, and due to imperfections (48kHz sampling may be 48.0001kHz), there may be a significant number of "extra" audio or video frames when the streams are muxed together with a "perfect" playback clock. For short, one or two minute clips, the sync will not be bad. But after an hour, it will be noticeable and will require fixing by demuxing, adjusting the audio stream (deleting or adding samples), and remuxing. Best to avoid the problem while capturing.

This line will do an hour of commercial TV on 700 MB or so after audio compression. The bitrate of 2000 is OK for sports, but I've found that if the DVD player or DTV (or both!) scales the video during playback there can be artifacts with such a low bitrate.

$ gorecord -input 1 -width 720 -height 480 -format mpeg2 -bitrate 2000 -duration 3600 foo.avi

Input 1 is the S-Video connector, which is active on my digital cable box while viewing the program we are recording. This is the best choice for sampling a baseband video signal. There is also a composite input on the ConvertX, but this will require separation of the luma and chroma and lower video quality. The TV402U has a built-in tuner that can demodulate RF transmissions from a cable broadcast (or antenna with transformer). This is OK if you take the input directly from an analog cable. But never use the RF output on a VCR or digital cable-box source if you don't have to -- it is introducing an extra modulation/demodulation step in the signal processing. And don't copy a DVD by sampling it with a capture box like the ConvertX. There are digital-domain, multi-pass processing techniques that are far superior for ripping DVDs.

Do not set the capture width to 640 pixels even if program format is 4:3 -- it won't be a DVD compliant DVD unless you post filter to add black bars to pad to 720 (requires lossy editing by most tools). Use the ConvertX in 720 pixel mode to hardware encode to the correct format.

Hardware encode to MPEG-2 for a DVD with the -format switch. Failure to do this will require transcoding later and loss of quality.

If you are recording from the built-in tuner, run gorecord without arguments to see the input mapping, then gorecord --help to see the channel selection syntax. I don't list it here because it is complex. In my town, I can grab off the lower 60 or so cable channels using "ntsc-cable" tuning and the built-in RF tuner.

Note, two semi-serious bugs in gorecord that have bit me.

First, it will only write 2 GB AVI files (due to Video for Windows architecture), then split off and write another. It will change the name of the avi on the split files to foo%d.avi where %d is the number of the split. This renamed file may or may not already exist on your filesystem and there is no clobber checking. Do not setup your scripts to record multiple files with a trailing digit or the filenames may overwrite each other.

Second, when the 2 GB limit is passed, it seems as if the duration flag is reset. So if you asked for 3600 seconds of video, you might get 3200 in one file until 2 GB, then 3200 in another until 2 GB, never tripping the duration. The only solution I can think of is a watchdog timer in another shell to kill the capture after one hour (3600 seconds):

$ sleep 3600; killall -SIGTERM gorecord

The gorecord application appears to write out the AVI headers on a Ctrl-C, so this should work.

Post-Processing

I recommend copying original video into a working directory.

For software, we are exclusively using the excellent mplayer (includes mencoder for encoding video). You can also work with ffmpeg for most operations.

You now have avi files. You may want to run them through mplayer to fix them (should be ok, but if you get a bad file you can fix):

$ mencoder -oac copy -ovc copy -o foo_fix.avi foo.avi

You will eventually need to convert to MPEG container and compress audio with AC-3 (ATSC A/52) for the DVD (PCM is strictly allowed, but huge in file size so I recommend compressing). Note, if you have built a playback application like VLC and also want to view the MPEG stream on your computer, you will want to link it with liba52 to enable AC-3 playback.

$ mencoder foo.avi -ovc copy -oac lavc -lavcopts acodec=ac3 -of mpeg -mpegopts format=dvd:vaspect=4/3 -o foo.mpg

Without the format=dvd, you'll get an MPEG file that does not contain program headers that dvdauthor will accept.

If you need to concatenate files, mplayer can do that for you:

$ mencoder -forceidx -ovc copy -oac copy -of mpeg -mpegopts format=dvd -o foo_big.mpg foo1.mpg foo2.mpg

To mark commercials for deletion, you can watch the video and hit the 'i' key to mark start and stop:

$ mplayer foo.mpg -edlout foo.edl

Or use comskip, which seems to get it right nearly all the time. It is a Windows program, but console, so running under WINE is seamless:

$ wine comskip foo.mpg

Then we can use edit this edl file to our liking, and use it to cut the video:

$ mencoder foo.mpg -edl foo.edl -oac copy -ovc copy -of mpeg -mpegopts format=dvd -o foo_cut.mpg

Note: ffmpeg can do some of these functions too, and may support features we're looking for but can't find in mencoder. An incomplete example:

$ ffmpeg -i foo.avi -acodec copy -vcodec copy -f mpeg foo.mpg

We now have a "final" MPEG, commercial cut, proper headers, AC-3 audio and MPEG-2 video that has never been transcoded.

DVD Authoring

(Largely taken from gentoo forums)

I recommend copying video into another working directory.

If we want a menu, we need to construct it with gimp: For NTSC disks, start a new image with 720x480 resolution, transparent background, advanced option of X resolution = 81 and Y resolution = 72 dpi.

You'll need the "Layers, Channels and Paths" dialog open (in File->Dialogs->Layers).

First layer is the background -- you can view your video in xine and do a screenshot if you like for this. Add anything you like to this, but also show button text here so the user can see where the navigation goes.

Next, make another layer, Layer Fill Type to be Transparency. Name this "button_highlight". Draw buttons, contiguous regions for each, with the text included. What you are drawing is the "cursor" for navigation, and dvdauthor will auto detect the buttons if they are contiguous blobs or blocks. You must only use 4 colors, which means turn off anti-aliasing of text.

Next, make another button layer in the same way, "button_select". This is the button shown while the user has pressed the "OK" selection on the cursor. Simply change the color or something.

A tip for copying text -- convert text in the layer menu to lose the text info. Then turn off all but text, copy visible, then select destination layer and use paste into. Positioning should be preserved.

We need to export the background, saving visible layers works, save as foo_menu_background.png (any format should work).

Then save the button layers as foo_menu_select.png and foo_menu_highlight.png (must be png).

The background image must be a MPEG-2 video. Make the video stream like this:

$ convert foo_menu_background.png ppm:- | ppmtoy4m -n50 -F30000:1001 -A10:11 -I p -r -S 420mpeg2 | mpeg2enc -n n -f8 -b5000 -a3 -o foo_menu_background.m2v

Convert is part of the Imagemagick suite. Ppmtoy4m and mpeg2enc are part of the mjpeg tools, which also includes mplex for muxing/demuxing streams (used later).

Now, you add an audio loop too if you like (AC-3).

$ ffmpeg -i your_music_file.mp3 -f wav foo_menu_audio.wav
$ normalize -a -10dB foo_menu_audio.wav
$ ffmpeg -i foo_menu_audio.wav -ab 224 -ar 48000 foo_menu_audio.ac3

Note that we could have used mplayer to dump the audio to wave, as well as other tools that come with most distributions. Normalizing is done by the normalize tool here, but sox or other common tools like audacity (GUI) can be used.

Or just make silence:

$ dd if=/dev/zero bs=4 count=99999 | sox -t raw -wsr 48000 - -t wav -r 48000 - | ffmpeg -i - -ab 224k -ar 48000 -ac 2 foo_menu_audio.ac3

Multiplex the audio and video into an MPEG stream:

$ mplex -f 8 -o foo_menu.mpg foo_menu_background.m2v foo_menu_audio.ac3

We need to mux in our buttons now. We use the subtitle mux, spumux, that comes with the dvdauthor tool.

Create a setup file, foo_spumux.xml:


<subpictures>
  <stream>
    <spu start="00:00:00.0" end="00:00:00.0"
         highlight="foo_menu_highlight.png"
         select="foo_menu_select.png"
         autooutline="infer"
         autoorder="rows"/>
  </stream>
</subpictures>

$ spumux foo_spumux.xml < foo_menu.mpg > foo_menu_final.mpg

You'll need an xml file to instruct dvdauthor how to make the disk. For example a really simple 16:9 example with no menus (two titles):

Creating a dvdauthor setup file, foo.xml:


<dvdauthor dest="DVD">
  <vmgm />
  <titleset>
    <titles>
      <video widescreen="nopanscan" />
      <pgc>
        <vob file="foo1_cut.mpg" />
      </pgc>
      <pgc>
        <vob file="foo2_cut.mpg" />
      </pgc>
    </titles>
  </titleset>
</dvdauthor>

This one has a menu (video line removed due to 640x480 video): Chapters not shown but can be added. Two titles on this disk.

foo.xml:


<dvdauthor dest="DVD">
  <vmgm />
  <titleset>
    <menus>
      <pgc>
        <button> jump title 1; </button>
        <button> jump title 2; </button>
        <vob file="foo_menu_final.mpg"/>
        <post> jump cell 1; </post>
      </pgc>
    </menus>
    <titles>
      <pgc>
        <vob file="foo1_cut.mpg"/>
        <post> call menu; </post>
      </pgc>

      <pgc>
        <vob file="foo2_cut.mpg"/>
        <post> call menu; </post>
      </pgc>
    </titles>
  </titleset>
</dvdauthor>

$ dvdauthor -x foo.xml

Test the disk before burning:

$ xine dvd:/absolute/path/to/DVD/VIDEO_TS/

Burning DVD

You can make an iso disk image (UDF filesystem for DVD), with the mkisofs tool:

$ mkisofs -dvd-video -udf -o foo.iso /path/to/DVD

and I have no DVD burner on Linux, so I ftp this from my Windows machine and burn with Nero. If I had a burner, I'd use cdrecord or a GUI like k3b.

If you had a DVD burner, try one shot (growisofs comes with dvd+rw-tools):

$ growisofs -Z /dev/dvd -dvd-video /path/to/DVD/

Summary of tools/packages used

Here's a summary of the tools we used, including some optional tools we may not have used. Equivalents are available for many -- check your distribution. Most are command-line/script friendly, but a couple are GUIs but are exceptional enough to be included.