Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.
Explaining the difference between codecs and containers is relatively simple, but hard part is attempting to understand each format. The lines start to get blurred when you realize that most common codecs aren’t exclusive, and can make use of multiple compression technologies in order to get the job done. The blurred line becomes nearly invisible when you start to talk about formats like MPEG-4 which could be classified as a bit of a container and a bit of a codec, but that’s a rather complicated classification that’s best left for another time.
So, how do you teach yourself the difference between dozens of codec and container options? Don’t. There is only a handful of technologies that are used for online video, and the bulk of your effort will be spent understanding how these work, as well as understanding the trade-offs you’re faced with when deciding on what to use.
You could spend weeks studying technologies that are only used for a relatively small number of applications, so instead we’re going to focus our attention on what technologies you’ll use for most of your video encoding and playback needs.
What Is a Codec?
A codec – or coder/decoder – is an encoding tool that processes video and stores it in a stream of bytes. Codecs use algorithms to effectively shrink the size of the audio or video file, and then decompress it when needed. There are dozens of different types of codecs, and each uses a different technology in order to encode and shrink your video file for the intended application.
Depending on the codec, this encoding occurs in one of two ways: lossy or a lossless compression.
When looking for manageable file sizes, lossy compression is the most viable method available. While you certainly lose quality in audio, video, or both, the compression is a necessary evil (currently) in a world dominated by the need to share and store what would otherwise amount to impractical file sizes. Your average Blu-ray, for example, can exceed 40 gigabytes, and that sort of storage space would not only be expensive, but it’d make digital downloads and purchases inconvenient, if not an outright waste of time. The key when using lossy compression is to settle on the highest quality compression format for your intended use, so that you walk the fine line between loss of quality, and file size.
Lossless compression works much like a ZIP or RAR file in that after compressing and decompressing, the file is essentially the same. Through use of smart algorithms, the file doesn’t lose much quality, but it’s not an efficient way to store large files because there isn’t much compression that actually takes place. In addition, online transmission of large video files uses far too much bandwidth (although H.265 encoding may change that) to make it a viable compression option.
Unless you work in the film industry, or in video editing, it’s unlikely you’ll ever share video files in a lossless format (if even then). To put it into perspective, even a 4k television doesn’t contain the resolution needed to display a film shot on a modern camera and delivered without some sort of compression. In fact, it’s not even close (yet). While 4k video is beautiful, it’s not even close to the size of an uncompressed video format.
While a Blu-ray film is less than 50 gigabytes (if it has to fit on one disc), the first downloadable 4k movie (available to consumers – trailer below) is a whopping 160 gigabytes! Completely uncompressed 1080p video is a mind-boggling 410 gigabytes per hour, and that doesn’t include the audio file, which could add an additional 7 gigabytes per hour depending on how it was recorded. All-in-all, these files are all but useless for a consumer market with current technology.
It’s also important to note that codecs aren’t just for compression of audio and video files. Once a file has been encoded using a specific codec, that same codec must be used to decode the file in order for it to play on your device. Not using the correct codec is what leads to the majority of device compatibility or playback issues. This issue is becoming less common as modern containers often include the required audio and video codecs needed to play the file.
DivX is a commercially sold codec, while XviD is an open source utility meant to function as an alternative to its commercial cousin. Both codecs can decode the output of the other, as they are both built on the implementation of MPEG-4. While still widely used, its often strictly for video encoding and in conjunction with one of the more popular packs mentioned below.
MPEG-4 is the most common streaming format and it consists of many parts, of which only MPEG-4 Part II is used for video coding. MPEG-4 Part II calls on video encoders such as DivX or XviD in order to encode the video, while audio is typically carried in MP3 format. Modern updates to MPEG-4 are now using H.264 as well.
This is the most popular choice for high definition material. H.264 is also a relative Swiss Army knife of the codec world as it can utilize both lossy and lossless compression depending on the settings you choose when encoding, such as frame rate, quality, and target file size. H.264 relies on x264 for encoded video (as well as others, such as DivX or XviD), and audio is often encoded using AAC or MP3 audio codecs depending on the size and quality you’re targeting.
H.264 is touted as 1.5 to 2 times as efficient as basic MPEG-4 compression, which leads to smaller file sizes and seamless playback on more devices. That said, H.264 is now included in the MPEG-4 codec (part 10, known as AVC), so it could become a moot point in the near future as the codecs become less reliant on a single encoding technology, and instead take on the role of a codec pack which includes multiple encoding methods in a single package.
What is a Container?
A container exists solely for the purpose of bundling all of the audio, video, and codec files into one organized package. In addition, the container often contains chapter information for DVD or Blu-ray movies, metadata, subtitles, and/or additional audio files such as different spoken languages. The typical container runs like an executable (.exe) file on Windows. It uses a .bat file to tell the operating system that there are executable commands that need to be run together in order to achieve the intended result.
Flash Video (.flv, .swf)
Macromedia originally created Flash before they were ultimately acquired by Adobe in 2005. Flash is an aging container that is being phased out due to limitations in the technology, creating what Steve Jobs used to refer to as “buggy” file handling. This led to a very public omission from iOS devices for Adobe and it appears that this was the beginning of the end for the format. As HTML5 standardization takes hold, we should see less Flash videos online, and the container is most likely going to disappear with it.
MKV is a rapidly growing format that was designed to be future-proof. The container itself supports almost any audio or video format which makes it adaptable, efficient, and highly regarded as one of the best – if not the best – ways to store audio and video files. In addition, it even supports multiple audio, video and subtitle files even if they are encoded in different formats. Due to the options the container offers, as well as its handling of error recovery (which allows you to play back corrupted files), it has quickly become one of the best containers currently available.
MP4 is the recommended format for uploading video to the web, and services such as Vimeo and YouTube have it listed as their preferred format. The MP4 container utilizes MPEG-4 encoding, or H.264, as well as AAC or AC3 for audio. It’s widely supported on most consumer devices, and the most common container used for online video. You really can’t go wrong with MP4.
The bottom line is, a container is a (mostly) useless bit of information when referring to video. Telling someone to send you an MP4 file doesn’t give away any useful bits of information without understanding how the video and audio itself were encoded. The container is just that, a place to store the audio, video and the codecs needed to decode them for playback.
So, ultimately if you’re looking for advice on what to use, H.264 is quickly becoming the standard codec, while either mp4 or MKV are worthy containers. MP4 might get the edge here because it is better supported in consumer devices, and is the standard for most large streaming video sites. Ultimately, the choice is yours, and as long as the video can be decoded and played on the other end, there really aren’t a lot of bad choices you can make in terms of what to use.
I’d love to hear what you use and for which application you’re using it for. What are your go-to video compression codecs, settings, and containers? Let us know in the comments below.
Photo credit: compression tool Via Shutterstock, Tunnel of Images, Media, Photographs via Shutterstock, Amazing Nature by Dr. Wendy Longo (modified), Adobe Media Encoder CS4 by Kebman, Youtube by Esther Vargas all via Flickr