Understanding the difference between codecs and containers is simple, but the hard part is explaining each format. The lines blur when you realize that most common codecs aren't exclusive and can use multiple compression technologies to get the job done.

So, how do you teach yourself the difference between dozens of codec and container options?

Don't.

You could spend weeks studying technologies that are useful only for a smaller number of applications, so instead, we're going to focus our attention on what technologies you'll use for video encoding, understanding the trade-offs and playback needs.

What Is a Codec?

Codec is an acronym that stands for compressor/decompressor or coder/decoder. It is an encoding tool that processes video and stores it in a stream of bytes. Codecs use algorithms to effectively shrink the audio or video file size and then decompress it for playback, editing, or when needed. There are dozens of different codecs, and each uses a different technology to encode and compress your video file.

Knowing when and when not to use a codec is important throughout the process of post-production, compression, and final delivery of your content. But principally, you have to maintain the trade-off between image quality, file size, processor usage, and popularity. Depending on the codec, this encoding occurs in one of two ways: lossy or lossless compression.

Lossy Compression

When looking for manageable file sizes, lossy compression is the most viable method. While you certainly lose quality in audio, video, or both, compressing is all about making the best compromises possible without giving up on quality. However, do remember that quality degrades with a higher ratio of compression.

For example, an average Blu-ray disc can exceed 40 GB, and that sort of storage space would not only be expensive, but it'd make digital downloads and purchases inconvenient. 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-vs-lossy-compression-dragonfly

Lossless Compression

Lossless compression works much like a ZIP or RAR file in that after compressing and decompressing, the file is essentially the same. Through the use of smart algorithms, the file doesn't lose much quality, but it's not an efficient way to store large files because not enough compression 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 video editing, it's unlikely you'll ever share video files in a lossless format. Here is our guide on how to reduce video file size without losing any quality.

Compression Parameters

Before we dive into the formats, you should be aware of the parameters that will directly affect the quality of the finished video. Some settings are global, i.e., similar from codec to codec or specific to an individual codec.

  1. Bitrate: The number of bites you're allowing the tool to describe each frame of the video. The higher the bits, the more the picture quality increase—but so does file size. They're denoted by Kbps or Mbps.
  2. VBR and CBR: Variable bitrate encoding varies the output bits over time. For example, higher bitrate for action-packed scenes in a movie and a lower-bit rate for slow scenes. Constant bitrate maintains a constant bitrate per segment, regardless of the complexity.
  3. Frame Rate: The frequency or rate at which consecutive images are displayed. It is expressed in frames per second (FPS).
  4. Frame Type: It describes the way picture data is structured in an MPEG stream or file. They play an important role in video compression and are of three types: I-frame (keyframe), P-frame, and B-frame. If you want to understand more about frame types and keyframes, check out our guide on keyframes for video editing.
  5. Aspect Ratio: 4:3 and 16:9 are the two most common aspect ratios. As you scale the video resolution, you must preserve the aspect ratio.

As you might expect, some codecs are more popular than others. Understanding where each codec is used can help you determine which codec you should use for your project.

XviD/DivX

DivX is a commercially sold codec, while XviD is an open-source utility that functions 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, it's often strictly for video encoding and is often used with one of the more popular packs mentioned below.

MPEG–4

MPEG–4 is the most common streaming format, and it consists of many parts, of which only MPEG–4 Part II applies for video coding. MPEG–4 Part II calls on video encoders such as DivX or XviD to encode the video, while audio is typically carried in MP3 format. Modern updates to MPEG–4 are now using H.264 as well.

H.264

H.264 is a relative Swiss Army knife of the codec world. It can use both lossy and lossless compression depending on the settings you choose while 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.

What Is a Container?

A container is a bundle of audio codec, video codec, and metadata organized into a single package. It ends with file extensions like MP4, AVI, MOV, FLV, and more. The metadata includes subtitles, resolution info, creation date, device type, and language files.

The container file interleaves the different data types and makes them accessible to the video player. Despite their importance, a container is a useless bit of information. It doesn't reveal how the video and audio were encoded.

As with codecs, there are popular containers, too.

MP4

MP4 is the recommended format for online video, and services such as Vimeo and YouTube have it listed as their preferred format. The MP4 container utilizes MPEG–4 encoding, or H.264, and AAC or AC3 for audio. It's widely supported on most consumer devices.

MKV

MKV is a rapidly growing format that was designed to be future-proof. The container supports almost any audio or video format, making it adaptable and efficient. It is regarded as one of the best ways to store audio and video files.

It even allows you to playback corrupted video files, support multiple subtitle tracks even if they're encoded in different formats, DVD menu and chapters, and more. Unfortunately, although the Matroska format is a free and open standard, it isn't universally supported yet.

AVI

First introduced by Microsoft, AVI videos were most popular throughout the 90s and into the early 2000s. AVI files can hold different types of audio and video streams, and with the help of the DivX codec, they can display superior video quality with a small file size.

However, when you compress AVI beyond a certain limit, it loses video quality. Since screens are now capable of HD, Ultra HD, and 4K, the tolerance has significantly reduced. Also, if you compress the video using a codec, you must have the same codec in your machine to play the file.

How to Find the Details of Codecs Used in a Video

If you're ever watching a video on your computer and you suddenly wonder, "What video codec is this using," there are several ways you can find out.

MediaInfo

MediaInfo is an open-source codec identification tool you can use to find out all the information about any audio or video file. The best part of the software is that it shows the extracted data in different structures like Sheet View, Tree View, HTML View, and more.

Download: MediaInfo for Windows (Free) | MediaInfo for Mac (0.99$)

mediainfo-user-interface

VLC Media Player

VLC gives you details of codecs and other associated information. First, load the video file, then go to Tools > Codec Information. You can view details like codec used, video resolution, frame rate, audio codec, sample rate, bit per sample, and more.

Download: VLC for Windows and Mac (Free)

codec-information-with-vlc-media-player

Which Codec and File Format You Should Choose?

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 because it supports consumer devices and is the standard for streaming video sites. H.264 is 1.5 to 2 times as efficient as basic MPEG–4 compression, leading to smaller file sizes and seamless playback.

That said, H.264 is now included in the MPEG–4 codec (part 10, known as AVC), so it could become a moot point soon as the codecs become less reliant on a single encoding technology.