Quick Transcoding Guide on Linux

Necessary Software

Install ffmpeg, xvid, dvd+rw-tools, mkisofs, lame, mjpegtools, kino, transcode, libdv, xine-lib, xine-ui, dvdauthor, and maybe faac for newer ffmpeg versions if you need AAC coding. Plus support for any other container formats like libquicktime or Matroska.

Sample transcode from DV to MPEG4 .avi

For converting 720x480 (TV pixels) to 640x480 (square pixels), motion-adaptive deinterlacing, 3D denoising, and sharpening, with a 2-pass encode:

transcode -i input.dv -o out.avi -V -J smartyuv,hqdn3d,msharpen -Z 640x480 -y xvid4,null -w 1800 -b 256 -R 1; transcode -i input.dv -o out.avi -V -J smartyuv,hqdn3d,msharpen -Z 640x480 -y xvid4  -w 1800 -b 256 -R 2

To crop in transcode, use the -Y top,left,bottom,right argument. e.g. -Y 0,8,6,8

Sample transcode from DV to MPEG2/AC3 DVD

transcode -i input.dv -y ffmpeg -F mpeg2 --export_prof dvd-ntsc --export_asr 2 -o video -D0 -E 48000,16,2 -b 320 -m audio.ac3 --export_fps 29.97 -w 6100

Moving DV Files Around

kino can capture from firewire and has exporting tools.

If kino's tools don't work, use dvconnect to talk to the camcorder. For example, to send a raw DV file from the computer to the camcorder:

dvconnect -s raw_dvfile.dv

Burning DVDs on Linux

Use growisofs (of the dvd+rw-tools), which also depends on mkisofs:

growisofs -Z /dev/dvd -dvd-compat -speed=1 -r -J -f data_dvd_directory
growisofs -Z /dev/dvd -dvd-compat -speed=1 -dvd-video video_dvd_directory

To assemble a video DVD filesystem, use dvdauthor on MPEG2 files. kino now supports automatic dvdauthor XML generation, but can build one manually as well.

Codec Settings Guide

ffmpeg.cfg can turn on trellis encoding for ffmpeg


xvid.cfg can turn on many features for xvid

  • quant_type defaults to h263 (good for low bitrate). mpeg is good for higher frequencies/sharpness
  • vhq defaults to 1 (fast). 4 is much more CPU intensive.
  • max_bframes defaults to 2. Might be good for cartoons, but reduce this for videos with high motion/pans/zooms. Some hardware decoders struggle with more than 1 B-frame.
  • quarterpel. sharpness at expense of bitrate and hardware decoder compatibility
  • gmc. Supposed to help with pans and zooms. Never seen it help much. Some hardware decoders struggle with this.
  • trellis. This helps and does not hurt hardware encoders.
  • cartoon. Use this for cartoons.
  • quantizer settings. Safe range is 2-31 for each of I,P,B frames. For small internet files, best to leave it alone. For high quality files, reduce the max quantizer settings as much as possible. In all cases, do a test run to make sure the encoder isn't blowing up in bitrate, which is a sign of being overconstrained.

    Quick Video DVD Guide

    DVD Format Basics

  • Audio and Video combined data rates must NEVER exceed 10.08 mbits/sec.
  • Audio rates should be appropriate for the chosen format and should be constant bit rate (CBR).
  • Video rates can (and often should) be variable bit rate (VBR). This way the MPEG2 encoder can spend more bits on complex video and less bits on simpler video.
  • Video data rate itself must not exceed 9.8 mbit/sec.
  • HOWEVER, it is true some DVD players are less than compatible at the high end of the DVD standard spec. Good rule of thumb is follow the above rules and make sure video and audio rates combined are never above 9.8 mbit/sec.
  • Everything on the DVD is a script-driven set of MPEG2 streams. This includes all menus and angles. To come up with menus you need software that can generate these. (Generally I never waste my time with them but a professional DVD generally looks better with them.)

    DVD Audio Basics

  • The DVD spec defines 3 formats for audio, each with their own unique limits.
  • Linear PCM: This format is lossless and best-quality but requires a higher data rate. I forget its exact limits but generally aim for 16-bit stereo, 48 KHz, which conveniently matches DV tape's 16-bit audio format. I do not know if DVD supports DV tape's 12-bit/32 KHz audio mode. Probably not. In this case the audio needs to be resampled to 16-bit/48 KHz. For stereo, 16-bit, 48KHz audio, the datarate is a constant 1536000 bits/sec (about 1.5 megabit/sec).
  • MP2 (MPEG1, layer 2): It is lossy. No, DVD does not support mp3s by default. The MPEG audio is allowed to go to I think either 320 or 448 kbit/sec. MPEG audio higher in the 192 to 320 kbit/sec range is probably ideal. Again, aim for stereo 16-bit 48 KHz.
  • AC3 (AKA Dolby Digital): Most movies have this. It is lossy. Again the peak bitrate is around 320 or 448 kbit/sec. AC3 audio higher in the 192 to 320 kbit/sec is ideal. (Knight Rider uses 192 kbit/sec AC3.) Again, aim for stereo 16-bit 48 KHz.

    DVD Video Basics

  • DVD ONLY allows MPEG1 or MPEG2 video, but forget MPEG1 exists. Just think MPEG2.
  • For NTSC TV, aim for 720x480 resolution (interlaced) which is exactly what DV tapes use. (Note: TV pixels are not square like a computer's pixels. So 720x480 looks stretched on a computer monitor but fine on a TV.)
  • Generally you want variable bitrate (VBR) MPEG2 video, so some areas will take less bits (e.g. 4 mbit/sec) and some will take alot more (e.g. 8+ mbit/sec).
  • Again, be mindful of DVD requirements. Never let audio+video exceed ~9.8 mbit/sec to be safe. So your peak video bitrate should be ~9.8 - audio bitrate. For example, if you are using 256 kbit/sec AC3 audio, don't let the video exceed approx. 9.5 mbit/sec ever.
  • Be mindful of your DVD's total space. This determines your average video bitrate. Your average bitrate determines your overall quality. See below.
  • MPEG2's quality: I don't care what other geeks say, MPEG2 has a quality curve that's more like a cliff. The only way to get good DVD video is to have a high bitrate (and clean source video and a good encoder program). I've seen 2 mbit/sec DVDs taken from TIVOs and it is not pretty!

    MPEG2 Video Quality Guidelines

    7-9+ mbit/secunder 7 mbit/secunder 6 mbit/secunder 5 mbit/secunder 4 mbit/sec

    DVD Space Guidelines

  • A regular single-layer DVD-R is 4.7E9 bytes.
  • A dual layer DVD-R is 8.5E9 bytes.
  • Remember to leave some room for the DVD filesystem, menus, extras, etc.
    The formula to use is ((total space in bits)/(time in seconds)) - (audio bitrate) - (some small margin as needed...)
    For a dual-layer DVD and 4 hours of video with 320 kbit/sec AC3 audio we find:
    ((8.5E9 * 8)/(4 * 60 * 60)) - 320000 == about 4.4 mbit/sec video.

    So even before we get to extras we find ourselves at the bottom of the quality spectrum. But if we drop to 3 hours instead:
    ((8.5E9 * 8)/(3 * 60 * 60)) - 320000 == about 5.9 mbit/sec video.

    If we want to use 7 mbit/sec video and 192 kbit/sec audio, how much can we fit on a dual-layer DVD-R?
    ((8.5E9 * 8)/((7E6 + 192000) * 60 * 60) == about 2.6 hours

    Alternatively we can use the bitrate calculator here.

    Encoder Guidelines

    I have no experience outside of Linux on various MPEG2 encoders. But given the choice to use these, here are some nice things to try if you have them available.
  • 2-pass encoding. It takes alot longer of course, but this gives the encoder a better estimate of the areas that need the most bits. Useful for preserving constant data rate.
  • 10-bit DC coefficient. Might help reduce blockiness in areas of constant color.
  • More complex motion estimation settings. Will greatly slow down the encode process.
  • closed GOPs. Mostly useful for multiple angles, which we never use on the FC DVDs anyway.
  • Lower quantizer values will help spacial quality at expense of bitrate.