Advanced Video Compression - Part 2
Common Distribution Codecs and Formats

Continued from the first page.

II. Common Distribution Codecs and Formats

1) The AVI Container and the Early AVI codecs - Cinepak and Indeo Video

The container: Microsoft defined the 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

The early codecs: Cinepak was originally developed to play small movies on '386 and '030 systems, from a single- speed CD-ROM drive. At the time it was hailed for it's low cpu usage... but not much else. Compression was pretty slow, especially when compared to Indeo. Indeo 3.2 was developed by Intel in the 1980's, and was originally knows as "RealTime Video 2.1" (RT21). Indeo is very similar to the Cinepak codec but had much faster compression. Both codecs are very old in terms of code and are very poor in comparison to modern codecs. Once MPEG-1 became popular, these codecs (including the later revisions of Indeo) started to become obsolete.


MPEG1 - The Golden Oldie

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.

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. The standard MPEG stream structure used in VCDs, SVCDs, and DVDs is IBBPBBPBBPBBPBBPBB, although the official MPEG standard doesn't place any restrictions on the distance between I or P frames. A group of frames that starts with an I frame and ends at the frame before the next I frame is called a Group of Pictures, or GOP. It's perfectly legal to stop a GOP short, insert a new keyframe and begin a new GOP at any time. This is akin to Variable Keyframe Interval in other codecs.

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 damn 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.



MPEG2 - The Behemoth

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.

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.


The Quicktime Container and the Sorenson Codec

No, Quicktime isn't a codec in and of itself - it's more of a video container like AVI is. While Microsoft defined their rather simplistic AVI container, Apple developed a more robust and intricate container called Quicktime.

Early Quicktime codecs were often the same as equivalent codecs available for use in AVI files at the time - Cinepak, Indeo, Mjpeg etc. With the release of Quicktime 4, however, a very powerful codec called Sorenson 3 became the biggest gun in the Quicktime arsenal, establishing quicktime 4 as the de-facto distribution method for movie trailers in the late 90s.

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 excellent as a format, bad implementations and invasive software has dogged quicktime for years.

5) Realplayer G5

Ahh those were the days. If you wanted small.. and I mean REALLY small... and you didn't care about having to use your imagination too much, then the classic Realplayer G5 encodes were the greatest thing on the planet. Remember those old 30mb digisubs where you could just about read the subtitles if you strained hard enough. It was revolutionary - no other codec could be scaled so small and be watchable at the time.

Thanks to these tiny sizes, the Real G5 encodes were cutting edge in terms of streaming video... but with a huge price. The old realplayer software was closed-source, riddled with adware and destructively invasive. Cleanly uninstalling realplayer was story only to be heard in legend.... and people still remember.

The scars caused by the old Realplayer software are still visible today where, despite a much friendlier software package and an excellent codec people prefer to stay away. Real networks made a very bad reputation for themselves in the late 90s and despite the benefits of small streaming video, the codec itself was associated with garbled encodings. All this has changed now, but the stereotype remains.

6) The MPEG 4 Standard

After the success of MPEG2 (and the fact that MPEG3 was no longer needed), the Motion Picture Experts Group began work on defining the MPEG4 standard. Early releases of the standard started showing up around 1998/99. MPEG decided that the Quicktime container format was to be used as a basis for the MPEG4 container and not longer afterwards a number of different implementations of MPEG4 came to fruition.

Nowadays, most MPEG4 implementations are standards compatible with certain profile levels (DivX, XviD and so on), but this was not always the case in the early days of mpeg4 codecs.

The most important early attempt at using the MPEG4 specification was Microsoft's. Desperate to win the streaming media war against Real and Apple, Microsoft developed their first mpeg4 codecs to go with their new Advanced Streaming Format container. The format wasn't entirely unsuccessful and did have a few days in the sun in the streaming media wars until their code was hacked open and manipulated....


DivX ;-) 3.11a Alpha - MS-MPEG4v3 without the drawbacks

Origins: A guy who went by the handle "Gej" used a hex editor and some other tools to modify the binary dll file of Microsoft's MS-MPEG4v3 ASF codec so that it would work under AVIs, so that you could use it to encode high-res movies (since ASF as a format was restricted to 352x288 resolution). He then released it onto the net. This became the original DivX which was updated until version 3.11alpha.

How it Works: Essentially it's the same codec as what's used in the old ASF encodes (if you don't believe me, use the ASF VirtualDub to extract an ASF video stream to an AVI file, then change the AVI's FourCC code to DIV3 and notice it still works) except that it uses the AVI file format, meaning no resolution restriction, no filesize overhead, and easy manipulation and playback in any program supporting AVI.

Benefits: DivX is a decent MPEG4 implementation (although incomplete). It can compress images better than MPEG1 in less bits, but it does lose more color data than MPEG1 (at least in Microsoft's implementation it does). However it's since been surpassed in quality by XviD but still has better compatibility.

Disadvantages: DivX isn't quite as compatible as MPEG1 - it plays on PCs, BeOS, and Linux easily enough, and it will play on the Mac with some work, but on other platforms you're out of luck. It also takes more horsepower to playback than MPEG1 (not as much as MPEG2 though), but there are settings in the advanced area of the Codec for playback on slower machines at slightly lower video quality. DivX also has some issues with solid black not being black.

Recommendation: At this time I would recommend encoding to XviD if you want MPEG4 encoding, but DivX3 is still a very viable codec and when used properly with NanDub it can make very good encodes.

8) DivX4/5 - The sequel to DivX

Origins: After the success of the original DivX3 codec, a group got together and started an open source version of DivX from scratch called OpenDivX. Unfortunately, they later closed the source and started working on it solely in house. First they released DivX4, which was alright but wasn't as good as DivX3. With the release of DivX5, they managed to hack in B-frames into an AVI file, which is a pretty impressive feat, although they way they do it is very messy and produces AVI files with rather bizarre structure, but they'll playback via DirectShow just fine.

How it Works: DivX5 is a pretty standard MPEG4 codec, and in fact can produce MPEG4 compliant streams if you encode audio to AAC and distribute as .mp4 files. However you'll need an MPEG4 software player or wait until Microsoft includes MPEG4 playback in their media player.

Benefits: DivX5 is pretty easy to setup and work with, but it doesn't have very many other advantages for encoding. It's playback filter, though, is fast and offers good post-processing capability. The playback filter's also easy to install and works good on properly encoded XviD files so we actually recommend installing DivX5 even if you don't plan on encoding with it. DivX5 does have very good playback options for PC, Linux, and the Mac, which covers the three biggest desktop platforms.

Disadvantages: DivX5's quality, while pretty good, still doesn't surpass the original DivX3 in my opinion, and the inability to really tweak the codec's internal options are a big downside. Also, in order to get all the options you have to either pay money for it, or download a version with adware and spyware attached to it. While it's possible to remove it, I think it's insulting and I don't want to get it near my machine. Fortunately you can download a full-fledged decoder in the non-adware version. Not a terrible codec by any means, but not a star performer either.

Recommendation: I don't recommend encoding your movies in DivX5 due to its inflexibility and adware. XviD is the better option for MPEG4 encoding, IMO


9) XviD - Fast, Open Source, Customizable, and Gorgeous

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.

How it Works: XviD is an MPEG4 compliant codec which performs very well and has oodles of options. It has as many implementations of mpeg-4 features as its rivals and some are even superior in their quality and detail.

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. Usually the latest snapshots released by Koepi are pretty stable and a good representation of the state of the code, and since XviD's always producing MPEG4 compatible streams, you should never run into a situation where your old encodes are no longer compatible. 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 DivX5, it can be difficult to setup at first glance. There are some minor bugs with version 1.0 and it's not as often installed by regular users so playback may be an issue with complex settings. These limitations are avoidable by using encoding options compatible with DivX5 as this guide will show you.

Recommendation: This is what I use exclusively now to distribute my files. It provides excellent quality and compressibility as well as advanced features, and it has good cross-compatibility amongst desktop operating systems.

10) Quicktime 6

After Sorenson, Apple fight back. After the success in having MPEG4 use the quicktime file format in its specification, Apple were keen to utilise this to the full and so came Quicktime 6 with Apple's own MPEG4 encoding. While Apple claims to have a fully compliant MPEG4 codec in their Quicktime Version 6 package, it is a much simpler implementation than DivX5 and XviD and has trouble playing more complex streams.

Apple fell short on their own MPEG4 video implementation but had a much greater success in their aac audio codec (the audio codec of the mpeg4 standard).

11) Realplayer 9 and 10

Innovation again is the key to Real's major updates to their codec. Not a MPEG4 standard, but MPEG4 quality, Real were able to create something short of phenomenal with their RV9 and RV10 codecs. They even made a public SDK and many of the criticisms which previously cursed Real Networks were vanishing.

The codec performed well... VERY well. In fact, at the time of writing, it is clear that there is no better codec for compressing animation and the best codec for live action is only a matter of opinion rather than fact with RV9/10 challenging the top. Unfortunately for Real Networks, this is not enough for many users. Feeling betrayed by the manipulative adware of the old Realplayer software and frustrated by the lack of cross-compatibility the bad reputation of Real lives on. Even with a much improved player and a great compatibility than ever people are still unwilling to delve into the Real codec for personal use.

12) Windows Media Video 9

In many ways, Microsoft's answer to RV9. A very competent codec indeed, much to the surprise of pretty much everybody. Of course, it's proprietary nature fails it again in many ways, but provided it is used well it can be a very good codec.

It is not, however, an MPEG4 compatible codec - so where DivX, 3viX and XviD are basking in the glow of Hardware players, Microsoft are trying to catch up... and I'm sure with all their money they will. In compatibility at least. Quality wise there is no major advantage in using WMV9 over XviD. WMV9 is a very competent codec and in many situations superior to its MPEG4 counterparts but there are plenty of reasons not to use WMV9... at the moment it is still too proprietary.

13) h.264 - MPEG4's big brother

What it is:
h.264 or AVC as it is sometimes known is actually the marriage of two development groups, MPEG and VCEG. The result is a specification which, from the MPEG side is MPEG4-10 and from the VCEG side is h.264.

The advantages: The additions to the encoding options include advanced entropy coding, a Loop/Deblocking Filter, variable block sizes, multiple reference frames and much much more.

The implementations: At the time of writing, it is clear that the h.264 specification is currently the most sophisticated video compression algorithm out there. Early attempts at h.264 codecs are numerous and already, with only a small amount of the specification covered, the codec is approaching the quality levels that XviD took so many years to achieve. Things are looking very good for this specification and if all goes predictably well we may see this being the official codec of the HD-DVD standard.

Here's hoping. For more info on h.264, see this FAQ on the forums at