Advanced Video Compression - Part 2
Common Distribution Codecs and Containers

Continued from the first page.

II. Containers

1) AVI: Microsoft defined the AVI (Audio Video Interleave) container as a special kind of RIFF (Resource Interchange File Format). As a container it had very simple design attributes which would, in years to come, reveal all kinds of limitations of the format. However, it was able to contain a very large amount of video formats by having a Four Character Code (FourCC) to define which Codec was used to store the video stream. All sorts of clever "hacks" have allowed AVI to do all sorts of things that it was never designed to do, such as support B-frames. However, the container can only be stretched so far, and more advanced codecs like x264 can't reach their full potential in the AVI container. Although technically superior containers like Matroska exist, AVI remains a strong choice. Editing applications often don't even support many newer containers, so AVI is likely your best option. For distribution, AVI is one of the more popular choices, but has been losing ground to other containers lately. All Microsoft windows computers have built-in support for the AVI container, and most other systems shouldn't have much trouble playing it. This means that in order to view an AVI file, you generally only need to worry about having the appropriate video and audio codecs installed, wheras with a container like Matroska, you must also install support for the container itself.


MPEG: The MPEG container holds audio and video that are compressed with... you guessed it... MPEG. The MPEG standard not only defines the MPEG audio and video codecs, but also the container that they are stored in. DVDs use a special MPEG container called VOB that supports additional features like many audio and subtitle streams.


Quicktime: While Microsoft defined their rather simplistic AVI container, Apple developed a more robust and intricate container called Quicktime. During the late 90's the Quicktime container became the de-facto standard for movie trailers and other types of online video which is designed to be viewed in a web browser. Cross compatibility, however, has not always been smooth. Although Quicktime is available for many different systems, the windows implementations of Quicktime have sometimes been less than desirable. While it's an excellent container, bad implementations and invasive software has dogged Quicktime for years. If you edit on a Mac, then by all means use this container. If you are editing on a Windows machine though, AVI is probably a far better choice. For distribution, Quicktime is often highly frowned upon by viewers who have Windows.


Matroska: This open-source container aims to become the standard of multimedia containers, but it still has quite a ways to go. Technically, it is a very impressive container that offers many interesting features you wont find anywhere else. For the purpose of AMVs though, it's not a terribly practical option. For editing, you would be hard-pressed to find any serious editing software that supports this container. Hopefully this will change in the coming years, though. As for distribution, you would probably be better served by the AVI or MPEG4 containers. Because additional software must be installed in order to play Matroska files, you risk having people not being able to figure out how to play your video.


MPEG4: The MPEG4 container is based on Apple's Quicktime container, and is designed to hold MPEG4 compressed audio and video. Technically, it can hold a large variety of different video and audio codecs, but if you want your files to comply with the MPEG4 standard, you should use only the standard MPEG4 video and audio codecs. Their are 2 compliant types of video codecs that you need to be aware of. MPEG4 ASP (advanced simple profile) codecs, such as DivX and XviD, and h.264 (also known as AVC, or Advanced Video Coding) codecs, such as x264. The standard MPEG4 audio codec is called AAC, though it is also acceptable to use MP3 audio. It is usually necessary to download additional software in order to play MPEG4 files, but because this is a standard and is gaining in popularity, it should have much more widespread support in the coming years.


Windows Media: This proprietary container is designed exclusively for holding Windows Media Audio and Video (WMA & WMV). Microsoft created this container because their aging AVI container couldn't support all of the features that they needed. While it is in many ways technically superior to AVI, it doesn't offer nearly the openness and flexibility that AVI does. Most Windows users shouldn't have too much trouble playing these files, but users on other operating systems or older versions of Windows may have difficulty. If you edit using Windows Movie Maker, this might be an option for you, but otherwise this probably isn't the best choice.

III. Common Distribution Codecs


Origins: Back in the very late 80's, the Motion Picture Experts Group was trying to come up with an open, efficient video compression standard which was officially brought into the International Standards Organization as ISO/IEC-11172, or more commonly known as MPEG1. The MPEG1 standard was designed originally for 1.5MBit/second datarates (i.e. 1X CD-ROM speed, the 1.5 figure includes audio however) and 352x240 resolution, although it is not limited to this.

How it Works: MPEG relies heavily on Inter-frame compression. There are 3 different types of frames in the MPEG standard - Intraframes (I-frames), Predicate frames (P-frames), and Bidirectially-interpolated frames (B-frames). I-frames are essentially the MPEG equivalent of Keyframes - these frames have all the data necessary to recreate themselves, i.e. you don't need to reference another frame to render an I-frame. P-frames reference the previous I or P frame and store the changes in picture. B-frames are meant to be very low-bitrate frames, so they reference both past and future frames.

Benefits: MPEG1 was the codec which made distributable digital video happen. MPEG could be streamed, stored on CDs - you could do all sorts of stuff with it. Even today it is still a very viable compression algorithm. You can play MPEG movies on almost anything, from settop players, to PCs, to handhelds running PocketPC! That's pretty darn impressive!

Disadvantages: MPEG1 is old, lets make no bones about it. It's still darned good, and it beats out everything else in terms of compatibility, but in terms of technical quality there are much, much better things out there. In order to get a good picture, it does require more bits/second than other codecs.

Recommendations: MPEG1, while it won't make the smallest files, is the KING in terms of compatibility. If you want everything under the sun to be able to play your AMVs, distribute in 352x240 MPEG1 files. Otherwise, I'd stay away from it.



Origins: After the MPEG1 standard was finalized, and people started trying to apply it to higher-resolution video pictures, there were many flaws in the standard that became apparent. The biggest of these was that MPEG1 could only compress progressive-scan images, which meant real TV pictures (which were interlaced) were very difficult to compress. MPEG2 was born out of the desire to achieve compression of broadcast-quality video, and to this end it has succeeded. MPEG2 is used for DVDs, ATSC (High Definition Television) broadcasts, Personal Video Recorders (such as TiVo), and many other applications. MPEG2 is so versatile that while originally it was planned to have an MPEG3 standard for High-Definition TV broadcasts, it turned out that MPEG2 scaled in terms of bitrate so that only 1 standard was necessary for both Standard and High Definition video.

How it Works: MPEG2 is very similar to MPEG1 when you look at the surface, although several of the underlying pieces have been completely changed. But for our purposes, it's good enough to say that MPEG2 is a souped-up version of MPEG1 with support for Interlaced video and High-res pictures.

Benefits: MPEG2 gives better picture quality than MPEG1 at full CCIR 601 resolution (720x480) and at comparable bitrate. Basically, MPEG2 scales, while MPEG1 doesn't.

Disadvantages: MPEG2 takes more CPU horsepower to decompress, and basically has no advantage over MPEG1 at lower resolutions. If you're distributing for the web, you're not going to want to be compressing stuff in MPEG2 instead of MPEG1 because the benefits of MPEG2 aren't realized until you get into full TV resolution, which means big filesizes. Additionally, most operating systems don't support MPEG2 playback right out of the box, while they do for MPEG1.

Recommendation: If you're creating your own high-quality archival backups of your videos, I would encode them at DVD-quality MPEG2, but I would never use MPEG2 for online distribution. If you are submitting your video to a convention, MPEG2 is typically recommended.

3) DivX

Origins: (adapted from Wikipedia article on DivX)
DivX ;-) 3.11 Alpha and earlier versions generally refer to a hacked version of the Microsoft MPEG-4 Version 2 video codec, extracted around 1998 by French hacker Jerome Rota (also known as Gej). The Microsoft codec, which originally required that the compressed output be put in an ASF file (the precursor to Windows Media), was altered to allow other containers such as AVI. From 1998 through 2002, independent enthusiasts within the DVD-ripping community created software tools which dramatically enhanced the quality of video files that the DivX ;-) 3.11 Alpha codec could produce. One notable tool is Nandub, a modification of the open-source VirtualDub, which features two-pass encoding (termed "Smart Bitrate Control" or SBC) as well as access to internal codec features. In early 2000, Rota created a company (originally called DivXNetworks, Inc., renamed to DivX, Inc. in 2005) to improve DivX and steward its development. The company released a new version of the codec as DivX 4.0 in July 2001. DivX 4 was no longer a hack of a Microsoft codec, but was designed completely from scratch. It is worth noting, however, that DivX 4.0 actually began as the result of the work of many open-source developers back when it was known as the "OpenDivX" project. However when the page was pulled and the source was closed to become the commercial DivX 4.0, many of the unpaid and unacknowledged developers saved the last CVS snapshot of the OpenDivX code and from there worked to create XviD, rivaling DivXNetworks' commercial efforts. Regardless, DivX, Inc. has been granted patents on parts of the DivX codec, which is fully MPEG-4-Advanced Simple Profile compliant. The next major version, DivX 5.0, was released in March 2002. A further improved version, DivX 6, was released on 15 June 2005.

Benefits: Although previous versions of DivX always struggled to achieve the same quality as XviD, DivX 6 is quite on par with it. The codec is quite simple to set up and use. DivX does have very good playback options for PC, Linux, and the Mac, which covers the three biggest desktop platforms.

Disadvantages: It's a commercial codec, so in order to get all the options you have to pay money for it. There is a free version that limits the options you can use, but then the quality will suffer significantly. Considering that XviD is free and has comparable quality to the full version of DivX, it really doesn't make sense to pay for this codec.

Recommendation: Just pass this one up in favor of XviD. You really aren't missing anything.

4) XviD

Origins: When OpenDivX closed its source and went on to produce DivX4, a group of open source developers decided to take the code that was left from OpenDivX and start their own codec. Thus XviD (or DivX backwards) was born. By now very little of the original OpenDivX code remains but there's a few bits here and there.

Benefits: XviD has all sorts of tweakable options, which means an experienced encoder (or one following a well-written guide) can produce some very nice looking encodes. It can also produce MPEG4 compatible streams if you want to distribute as .MP4 files. Thanks to the proliferation of the MPEG4 standard it is possible to play XviD encodes on almost any platform you can think of.

Disadvantages: Unlike DivX, it can be difficult to setup at first glance. Not much else...

Recommendation: This is currently one of the most used codecs for distributing AMVs. It provides excellent quality and compressibility as well as advanced features, and it has good cross-compatibility amongst desktop operating systems. Highly recommended.

5) Windows Media Video 9

Benefits: A very competent codec indeed, on par with and possibly even slightly surpassing XviD in quality.

Disadvantages: Of course, its proprietary nature fails it, and it is not MPEG4 compatable. Not many options are exposed for you to tweak. This codec is generally found in the Windows Media container, rather than AVI, so it may be looked down upon for that. Also, the majority of people who encode to WMV9 tend to produce small, low-quality files, which tends to give the codec a bad name. While its certainly capable of very high quality, people will just generally assume that a WMV file is low quality.

Recommendations: While Windows Media Video 9 is capable of pretty nice quality, it generally has no significant advantage over XviD to really warrant its use. XviD is just generally better accepted.

6) x264

What it is: x264 is a freely available open source implementation of the h.264 standard. H.264, or AVC as it is sometimes known is a very advanced compression method that is part of the MPEG-4 standard.

Benefits: This simply offers the best quality at the smallest filesize, bar none. XviD can't even come close to what this codec can achieve!

Disadvantages: In order to take full advantage of this codec, it should be used with the MPEG-4 container. That makes one more thing that users may have to install in order to play your video. Probably the biggest disadvantage of x264 (or any h.264 codec for that matter) is that it can take quite a bit of CPU power to play back. If you use this codec, viewers on slow computers may not be able to watch your video!

Recommendations: If you want the absolute best quality to filesize ratio, then this is your best choice. Just keep in mind that you may be cutting off potential viewers by using this right now. This is continuing to gain popularity and is now starting to come into widespread use. If you don't mind the current disadvantages, this is highly recommended.