AnimeMusicVideos.org > Guide Index
Codecs and Containers
Now that you know the basic concepts and terminology behind
video compression, we can talk about various containers and codecs, and
which one is right for you. First off, we need to point out what the
difference between a Codec and a Container is. Codec stands for
Compressor/Decompressor, meaning it is something which can both encode
and decode something, in this case video. Codecs
include things like MJPEG, Sorenson, Cinepak, and DivX. Some codecs may have specific containers associated with them, such as MPEG. Some other containers you are probably familiar with include AVI, Quicktime, or Matroska. A container simply holds everything together. For instance, the AVI container holds both the video stream (which is compressed with a Codec) and an audio stream. Without the container, the video and audio would be in seperate files! More advanced containers like Matroska can allow for additional things like subtitle streams, multiple audio and video steams, chapters, menus, and more.
A container does not necessarily mean anything about the video
quality, it only dictates the underlying structure of a file. I always
scratch my head when people say things like "I like AVIs better than
MPEGs because they're smaller," which is a statement that makes
absolutely no sense. I've had an AVI file that's 26GB large, orders of
magnitude larger than most MPEG files. The fact is that containers like
AVI and Quicktime have little to nothing to do with the underlying
Codec, except that the limitations of a container must be adhered to in
the codec. For instance, AVI does not support many of the features required for h.264 (MPEG-4 AVC) compressed video.
||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 is a very impressive container that offers many interesting features you wont find anywhere else. Because of it's great subtitle support, it is frequently used for anime fansubs. For the purpose of AMVs though, most of its unique features aren't typically very useful. 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, most people tend to go with the more standardized AVI or MP4 containers for their AMVs.
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 these days it has become quite a popular option.
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.
II. Common Editable Codecs
||MJPEG - Motion Joint-Picture-Experts-Group
Benefits: MJPEG is blazing fast. You probably wont find a speedier codec! MJPEG can achieve decent
compression rates and good image quality for most natural images like
Disadvantages: Here's where MJPEG starts looking
much less attractive. First off, JPEG does not compress anime well. Due
to the way that JPEG works, abrupt changes in color and brightness (for
instance, thin black lines in between different blocks of color) are
not handled well by JPEG, which means MJPEG suffers from the same
problem. JPEG has a problem with sharp edges which is unavoidable,
partly because the standard was meant to compress natural images like
There's also the problem of recompression. While the human eye can be
fooled by JPEG's compression, computers aren't. Thus, when you compress
from MJPEG into another format to use for distribution, you will
receive a lower-quality picture than if you had a lossless source
because there is data missing which, while it's not important to the
visual cortex, is very important to a mathematical analysis of things
such as color data.
Recommendations: MJPEG is an old standard. It is generally lossy, so about the only time you
should use MJPEG is for fast-editing temporary files, but
DON'T use them as your final source.
DV - Digital Video
Benefits: DV looks very good, better
than MJPEG in every respect. DV is good enough that it's used by both
consumers and many professionals as a compression standard. If you are only going to be doing a recompression once or twice, the quality shouldn't be much of an issue. With repeated recompression though, you can start really losing quality.
Disadvantages: The main disadvantage is that
DV is fixed to 720x480 in 29.97 FPS (or 720x576 in 25 FPS) at
25MBit/second. Some variants of DV exist that may support different resolutions, or allow for progressive (non-interlaced) video. But for the most part, DV severely limits what you can put into it. Also, its not lossless, but the quality is still VERY good.
Recommendations: If you don't plan to do any pre-processing (discussed later in this guide) on your video source, and you don't have the disk
space/hard drive throughput to edit in a lossless codec like Huffyuv or Lagarith, this is a decent choice, but in many cases the limitations it imposes aren't really worth the trouble.
Huffyuv - Lossless Video Compression, for a price.
Benefits: Obviously, the biggest benefit is that
you have a perfect recreation of the original video data (unless you do
colorspace conversions). That
means no matter how many times you recompress the video in Huffyuv,
you'll still have the same video data that you had in the beginning.
This is a very nice thing. Huffyuv also compresses and decompresses video pretty quickly.
Disadvantages: Due to the very large space requirements (Huffyuv takes a LOT of disk space,
sometimes 4x more than even DV), disk throughput becomes a very large
factor. Also, this codec does not support the YV12 colorspace (although modifications of the codec which DO support this colorspace exist).
Recommendations: If you have the disk space to burn, this is a very viable codec for editing. Huffyuv is also a great choice for exporting your final video out of your editing program, before you compress it with something else. However, its pretty old, and there are some better lossless codecs around these days, like Lagarith.
Lagarith - Better, Slower, Lossless Video Compression.
Benefits: Like Huffyuv, Lagarith is a lossless codec, so you get back exactly what goes into it. In addition to offering better compression than Huffyuv (so it doesn't use as much disk space), it also has support for additional colorspaces such as YV12, and it offers interesting features such as a "reduced resolution" mode, which is useful for editing with proxy files (discussed later in this guide). Lagarith is also multithreaded, so that means if you have a CPU that can take advantage of this, you will get even faster performance. Finally, since it can make smaller files than Huffyuv, disk throughput is not as much of a factor, and your hard disk is less likely to become a bottleneck when trying to play back these files.
Disadvantages: Both compression and decompression can be slower than HuffYUV. If you have a slower CPU, you may want to consider other options. This codec IS multitheaded though, whereas HuffYUV is not, so on newer dual core processors, this codec may compress and decompress even faster than HuffYUV.
Recommendations: Unless you are editing on a pretty old system, I would recommend that this be your editing codec of choice.
III. Common Distribution 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 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.
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 MPEG1 files. Otherwise, I'd stay away from it.
Benefits: MPEG2 gives better picture quality than MPEG1 at full DVD 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 most operating systems don't support MPEG2 playback right out of the box, while they do for MPEG1.
Recommendation: If you are submitting your video to a convention, MPEG2 is typically recommended, but I would never use MPEG2 for online distribution.
Benefits: XviD is a free codec that has been around for a while now and works very well. It can give you very good video quality at a reasonable size, and it doesn't require a fast computer to play back. It can be used in a variety of different containers, including both MPEG-4 and AVI.
Disadvantages: XviD's only real disadvantage is that it's starting to get old, and better codecs are available now. XviD is a sort of middle ground between MPEG-1 and x264.
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, but x264 may be a better choice these days.
||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 compatible. 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.
Benefits: 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. 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. Probably the biggest disadvantage of x264 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! However, as it's been around for a few years now, most people now have systems capable of playing it with no problems.
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 that, then this is highly recommended.