Converting DV video to DVD-compliant streams
Camcorders often export captured material in DV format, and there are devices like the Pinnacle MovieBox DV which can transcode analog video into DV. This page describes how to take that video and re-encode it for storage on a DVD, so that it can be played on ordinary DVD players.
- 1. Store the video on your computer
- DV-capable devices typically communicate with a PC through an IEEE1394 (also known as Firewire or i.Link) interface. The tool dvgrab (part of the [Kino] DV software suite) can be used to capture DV from such a device; Kino's graphical interface can of course also be used.
- When capturing, you'll have the option of storing the video in one of three formats: DV1, DV2, or raw DV (see video codecs/DV for details). You should always use raw DV format with transcode, as it both uses less disk space and is faster to process. If you want to edit the video or select frames before transcoding, you can use Kino, which also supports raw DV streams.
- To capture the video with dvgrab, use a command line like the following:
- dvgrab --format raw --size 0 filename
- This will start the tape in your camcorder and capture the video to filename-001.dv; if that file already exists, the counter in the filename will be incremented to avoid collisions, so you don't need to worry about accidentally erasing existing files. If you want to control the tape yourself, or if you're capturing from a non-tape source (such as directly from TV), then use the --noavc option as well.
- 2. Transcode to MPEG2/MP2 (or MPEG2/AC3)
- Once you have the video on your computer, you need to convert it to a format that DVD players will recognize. DVDs are encoded using MPEG2 video and either PCM (uncompressed), MP2, or AC3 audio. Before doing the actual transcoding, you will need to decide on:
- the audio format to use
- the bitrate to encode at
- the video frame size
- how to handle interlacing
- the encoding (export) module to use
- other transcode settings
- 2a. Audio format
- Of the three formats, the one least frequently used is PCM, simply because it requires so much space: the bitrate of an uncompressed 48kHz 16-bit stereo audio stream is 1536 kbps, 5-10x more than typical encoding rates. If you're only encoding a short video, or if you want to make absolutely sure you don't lose any audio quality, then you might want to consider PCM; however, in almost all cases high-bitrate MP2 or AC3 will be so close to the original that no one will notice the difference.
- For an explanation of differences between AC3 and MP2 audio, see AC3 vs. MP2. The primary thing to consider is hardware player support: in the United States, MP2 audio support is optional, while in the rest of the world both AC3 and MP2 are required, so if you're creating a DVD to be played in the US, then you may want to consider AC3. (However, virtually all US players play MP2 audio with no problem.)
- The type of audio is selected with the -N option. The audio types are 0x1 for PCM, 0x50 for MP2, and 0x2000 for AC3.
- Audio can also be encoded in either monaural (1-channel) or stereo format. If there is little or no stereo separation in your audio--if your camcorder only has a monaural microphone, for example--then you can save space by reducing the audio to 1 channel. This can be done with the transcode option -E 0,0,1 (only for transcode compiled from CVS).
- 2b. Bitrate
- Bitrate is limited by two factors: the size of the disc, and the limits specified in the DVD-Video standard. The DVD specification says that the maximum multiplexed bitrate of a video/audio stream must be no greater than 10.08 Mbps (10080 kbps), and the video bitrate must not be greater than 9800 kbps; when considering audio and multiplexing overhead, a more realistic upper limit on video bitrate is 9000 kbps. For a standard 4.7GB DVD, this is equivalent to one hour of video, so (with a caveat, mentioned in section 2e below) if your video is less than one hour long you can encode at this maximum rate.
- However, if your video is longer than this, you will need to reduce the bitrate. The easiest way to find the maximum bitrate available is to divide the size of the DVD by the length (in time) of the video; however, you have to keep in mind that some of the DVD space will be used for control information when the video and audio are multiplexed. This amount is usually 3-5% of the total video and audio data, so by reducing the size of the DVD by the same amount, you will avoid running out of space. For a 4.7GB DVD, for example, reducing the size by 0.2GB (about 4.2%) gives the formula:
- maximum-bitrate (bits/second) = 4,500,000,000 (bytes) * 8 (bits/byte) / video-length (seconds)
- So, for example, a 90-minute video could be encoded at a total bitrate of (4,500,000,000 * 8 / (90*60)) = 6666666 bps = 6666 kbps.
- Once you have the total bitrate, you have to decide how to split it up between video and audio. If you're using PCM audio, then the bitrate is fixed at 1536 kbps (768 kbps for monaural audio), so the video bitrate is simply the total bitrate minus that value. Likewise, for MP2 and AC3 audio, it is generally easiest to decide on the audio bitrate first and use the remaining bits for video. A bitrate of 256 kbps is usually more than sufficient for most audio streams and listening environments.
- It is worth noting that the bitrate you specify for video encoding is only an average bitrate; the bitrate at any instant can go all the way up to the DVD limit of 9800 kbps (actually, transcode imposes a slightly lower limit of 9000 kbps, but this should make no practical difference). The encoding process examines the video stream, and will try to "save" bits in low-motion scenes so that they can be used later on to encode high-motion scenes in more detail.
- 2c. Video frame size
- The DV video frame size is fixed at 720x480 (NTSC) or 720x576 (PAL). This frame size is usable on DVD as well, but there are some reasons why you might want to change it. The most obvious one is size: a smaller frame size means less data to encode, and therefore less visual distortion at a given bitrate, with the tradeoff of a lower resolution. You can choose either half-width (352x480/352x576) or half-width, half-height (352x240/352x288); the former is useful if you want to preserve interlacing, while the latter will allow you to get a several-hour video stream onto a single DVD.
- The other reason to consider changing the video frame size is aspect ratio. The 720-pixel-wide DV frame is actually slightly wider than the 720-pixel-wide DVD-Video frame--technically, the two formats have a slightly different pixel aspect ratio, and therefore display aspect ratio--so that if you encode DV directly to DVD without changing the size, the image will be slightly "squished" horizontally. The difference is small enough that it's usually not visible, but if you want to get the correct aspect ratio, you can clip 16 pixels from the left and/or right borders to get a 704-pixel-wide frame, which is also legal for DVDs. In particular, TV broadcasts often have thin black bars at the left and right due to the frame size difference, and clipping these off will also improve encoding quality. (For these reasons, it is also preferable to clip the video frame before resizing when using half-width or half-width/half-height video.)
- The transcode option to clip the frame is -j, and the option to resize the frame is -Z; however, if you clip the frame before resizing, you can use -r for resizing instead, which is faster. A summary of clipping options for each frame size is shown below (you can adjust the parameters for -j to match your particular video source). The height is given as full for 480 (NTSC) / 576 (PAL), and half for 240 (NTSC) / 288 (PAL).
|352xfull||-j 0,8,0,8 -r 1,2|
|352xhalf||-j 0,8,0,8 -r 2,2|
- 2d. How to handle interlacing
- In most cases, your input video will be interlaced, so you need to tell transcode how to process it; this is done using the --encode_fields option. See the interlacing page for details.
- 2e. Encoding (export) module
- There are two modules for encoding MPEG2 video: ffmpeg and mpeg2enc. Each has its advantages and disadvantages; see FFmpeg vs. mpeg2enc for details and a visual comparison. Note that in order to use mpeg2enc, you need to have the [mjpegtools] software installed, and you will need to add the -F transcode option to set encoding parameters (a typical parameter string is -F '8,-c -q 2 -4 1 -2 1').
- If you choose the ffmpeg module, you can enable two-pass encoding with the -R option. In two-pass mode, you run transcode twice: the first time, transcode examines the file, and the second time, it uses that information to "look ahead" and decide when it can use extra bits to encode complex scenes. This can result in significantly better image quality at low bitrates, as shown on the comparison page above.
- There is one caveat, however, when using the ffmpeg module: as described on that comparison page, FFmpeg has a bug which can cause it to exceed the maximum video bitrate in the DVD specification (9800 kbps) during two-pass encoding. If this happens, you will get errors during the multiplexing stage, and if you try to play the resulting DVD in a hardware player then it may "freeze" occasionally during the video. At low bitrates (3000-4000 kbps), this problem rarely occurs, but it becomes more frequent as the bitrate increases. If you do encounter the problem, you can either lower the bitrate, or specify a lower maximum bitrate by creating a file called ffmpeg.cfg in the .transcode subdirectory of your home directory and adding the following lines:
- This reduces the maximum encoding bitrate from the default of 9000 kbps down to 7500 kbps. This is usually enough to avoid the problem, but if not, you can try reducing the rate further.
- 2f. Other transcode settings
- If you want to encode only a subset of your input video, you can use the -c option to list the frames to encode. For example, -c 100-200,300-400 encodes frames 100 through 199 and 300 through 399 (inclusive), for a total of 200 frames. Even if you want to encode the entire file as is, using the -c option will allow transcode to display an "ETA" (estimated time remaining) counter; in this case, specify a range of 0 to number-of-frames (which can be determined easily for raw DV files by dividing the file size in bytes by 120,000 for NTSC or 144,000 for PAL).
- For other settings, see transcode command line options.
- 2g. The actual transcoding
- The basic commandline to use for this purpose is as follows. Note that all of the options should be given on the same line; they are separated here so that comments can be added.
transcode --ext none,none # Kludge to prevent .m2v, etc. from
# being added to output filenames
-x dv,dv # Import modules--for two-pass encoding,
# use "dv,null" on the first pass to
# speed things up
-i input-file # Input file name
-y export-module # Export module, "ffmpeg" or "mpeg2enc"
-o output-video-file # Video output filename
-m output-audio-file # Audio output filename
-N audio-type # Audio type (see section 2a)
-w video-bitrate # Video bitrate, in kbps
-b audio-bitrate # Audio bitrate, in kbps
--export_prof dvd-type # Either "dvd-ntsc" or "dvd-pal"
--export_asr 2 # Aspect ratio (4:3)
--encode_fields mode # Interlacing mode (see section 2d)
[other options] # -R, -j, -r, -c, etc.
- 3. Multiplexing the video
- When you have finished transcoding, you will have two files, an MPEG2 video stream and an audio stream. To convert these to a single file (a VOB file), you need to multiplex them together. This is usually accomplished with the mplex program from mjpegtools:
- mplex -f 8 -V -o output-file video-file audio-file
- where video-file and audio-file are the output filenames used with transcode.
- 4. Creating a DVD filesystem
- Once you have a VOB file, you need to process it so that DVD players can play it correctly. This is done with the [dvdauthor] program. Details are in the [dvdauthor documentation], but at its simplest, dvdauthor can be used as follows (DVD-filesystem-dir should be a directory that does not yet exist--the filesystem will be created under this directory):
- dvdauthor -o DVD-filesystem-dir -t VOB-file
dvdauthor -o DVD-filesystem-dir -T
- Note that if you create the DVD filesystem this way, then on some hardware players, the disc will not automatically start playing--you will have to manually select Title 1 using the remote control.
- After creating the filesystem, it can be converted to an ISO image for burning to DVD with the mkisofs command from [cdrtools]:
- mkisofs -dvd-video -o ISO-image-filename DVD-filesystem-dir
- 5. Burning the DVD
- To burn the ISO image to a DVD, use growisofs from [dvd+rw-tools], which will burn all types of writable DVD media reliably:
- growisofs -dvd-compat -Z /dev/dvd=ISO-image-filename
See dvtodvd.sh for a script that uses transcode to convert DV files to VOB files.
Another, albeit very out-of-date, document on this topic can be found at: Outdated DV To DVD HOWTO