HackToHell. Powered by Blogger.

Confusing codecs and formats explained (via SuperUser)

codec is short for encoder/decoder, which means that data generated by an encoder can always be decoded by the appropriate decoder. This happens to be valid for video, audio, but you could also think about cryptography (an encoder needs an appropriate decoder to display an encrypted message).

Nowadays, when a video codec is specified, the institutions that take part in it only specify the decoder part of the standard. They will say: "The bitstream format has to be like this", "The0x810429AAB here will be translated into that", et cetera. How an encoder is then written to match such a format completely is up to manufacturers. This is the reason why you will find many decoders for the same format, and some of them are even commercial.
Consider the case for h.264Mainconcept is a very good commercial encoder, whereas x264 is a free and open source one. Guess who claims to be the "better" one. Both. The fact that you can optimize encoding makes for a competition here. Both encoders deliver a standardized bitstream that can always be decoded by a h.264 decoder.
So, all in all, an encoder will take video frames, produce a valid bitstream. The decoder will take that valid bitstream and produce the video frames from it.

Current codecs

Currently, you will only find videos encoded with the following codecs. Interestingly, almost all of them are created by the Motion Picture Experts Group, with the help of some other joint effort groups. After they've created the draft standard, they will go ahead and let it be standardized by the ISO.


This is mostly used on DVDs and TV broadcasting, e.g. DVB. It offers high quality at the expense of high file sizes. It's been the main choice for video compression for many many years now. Encoders are often found embedded into hardware. The encoding scheme is very basic and therefore allows for fast encoding.
At some point though, its quality is not good enough for low bitrates. While a satellite or cable transmission offered enough bitrate for a high quality MPEG-2 video, it just wasn't good enough for the internet and multimedia age.
MPEG-2 videos mostly are in an .MPG container.

MPEG-4 Part 2

This is probably the one used mostly to encode videos for the web (where I mean, encode for letting others download it). It offers good quality at practical file sizes, which means you can burn a whole movie onto a CD (whereas with MPEG-2 you would have needed a DVD, see my answer here).
Its drawback is that the quality itself might not be good enough for some viewers. Some encoders that output MPEG-4 Part 2 video are DivX, its open sourced ripoff XviD, and Nero Digital.
MPEG-4 Part 2 videos mostly come in an .AVI container.

MPEG-4 Part 10

also known as MPEG-4 Advanced Video Coding (AVC) or h.264: This is the big boss, the number one codec today. It offers superb quality at small file sizes and therefore is perfectly suited for all kinds of video for the internet.
That was its main purpose actually, which you can see from the name. Originally, it was called h.264. You can see that this has nothing to do with the MPEG. In fact, the ITU created it based on h.263 – both were meant for videoconferencing. They however joined efforts and created this new standard.
You will find h.264 in almost every modern applications, from phones to camcorders, even on Blu Ray disks, video is now encoded in h.264. Its quality vs. filesize ratio is just so much better than with MPEG-2 or even MPEG-4 Part 2. The main disadvantage is that it is very slow to encode as it has some vast algorithmic improvements over them.
Some encoders for it are: x264MainconceptQuickTime. The videos mostly come in .MP4.MKV or.MOV containers.

The on2 Codecs

Some proprietary codecs are developed not by a committee or institution, but rather a company. One of those was On2, and they produced quite a few codecs that are worth mentioning.
  • VP3 is a codec that On2 has made open source. There is actually no specification, they only released the codec implementation, and that's it. It however became the basis of the free and open source Theora codec by the Xiph.Org Foundation.
  • VP6 is used in Flash 8 by Macromedia/Adobe.
  • VP7 claimed to be better than h.264, but it hasn't seen much usage.
  • VP8 was later turned by Google into WebM.
  • They also seem to have created the basis for Skype's video protocol.

Video Codecs over time

Here's a nice graphic that I found on AppleInsider, which shows the proliferation of video codecs over the last few years:
enter image description here

What is a format (container)?

Now that you have the raw bitstream, which is basically just really raw video data, you could actually go ahead and watch the video. But in most cases that's not enough. You need to wrap the video in a container. There are several reasons why:
  • Maybe you want some audio along with the video
  • Maybe you want to skip to a certain part in the video (like, "go to 1:32:20.12")
  • Both audio and video should be perfectly synchronized
  • The video might need to be transmitted over a reliable network and split into packets before
  • The video might even be sent over a lossy network (like 3G) and split into packets before
For all of those reasons there are container formats, some simple, some more advanced. What they all do is "wrap" the video bitstream into another bitstream. A container will synchronize video and audio frames according to their Presentation Time Stamp (PTS), which makes sure they are displayed at exactly the same time. It would also take care of adding information for streaming servers, if necessary, so that a streaming server knows when to send which part of the file.
Let's take a look at some popular containers.

Popular containers

You will find videos mostly wrapped in the following containers. There are other less popular ones as well, but as I said, mostly, it's those:


This is the most basic container, it's just there to interleave audio and video (heh, the name says it). It was written in 1992 and is still used today. It has quite a few disadvantages:
  • No aspect ratio information
  • Not all variable bitrate video or audio
  • No good support for codecs that use predictive coding (like h.264)
All in all, we shouldn't use AVI anymore, yet we do. Don't ask me why.

MPEG-4 Part 14

is also known as MP4 and is based on the QuickTime file format. This is the go-to format for h.264 video, but it also wraps MPEG-4 Part 2 and MPEG-2. It has the advantage of offering vast metadata information about a video, better and stable support for predictive coding.
Interestingly, this container might also wrap audio only, which is why you'll find so many .mp4 files which are no videos but rather AAC-encoded audio.
Note: The extension m4v is used for raw MPEG-4 Part 2 bitstreams instead!


is an open sourced and free file format that is often found for h.264 files nowadays. The fact that it is not yet supported in all players (especially hardware ones like TV stations or DLNA streaming servers) is a bit of a disadvantage.


The Ogg container is the container of choice for the Theora video codec (and the Vorbis audio codec), also created by the Xiph.Org Foundation. It's also free and open source (just like the codec). Some features include additional XML metadata information which theoretically offers much more than other containers.

Popular codecs and formats

Also, which of the following are codecs, which ones are file formats, and which ones are neither?
  • Quicktime MOV.mov is the file extension for the QuickTime File Format, which is a containercreated by Apple. This container was later adapted for MP4. It can carry all kinds of codecs.Quicktime is actually a whole media framework, it doesn't really specify any codec itself as far as I'm concerned.
  • MPEG (1, 2, 3, 4): Standards defined by the Motion Picture Experts Group. See my post above for details.
  • WMV: Windows Media Video. It's actually a codec wrapped in an Advanced Systems Formatcontainer, which uses the .wmv extension again. Weird, but that's the way it is.
  • FFmpeg: This is neither a codec nor a container. It is a library of video tools that also allow conversion between different codecs and containers. FFmpeg relies on the open sourcelibavcodec and libavformat libraries for creating codecs and containers, respectively. Most of video tools you find today are based on it.
  • AVC: Synonym for MPEG-4 Part 10 or h.264.
  • DivX: Another type of encoder for MPEG-4 Part 2 video.
  • Xvid: One type of encoder for MPEG-4 Part 2 video. It's just the open source, free version of DivX, which of course led to some controversy.
  • H.264: Synonym for MPEG-4 Part 10 or AVC.

On a side note:
Am I even using the correct terminology?
I guess once would prefer to specifically use "codec" and "container" instead of "format" to avoid misunderstandings. A format can theoretically be anything, because both codecs and containers specify a format (i.e. how data should be represented).
That being said, the FFmpeg terminology would be to use "format" for the container. This is also because of the distinction between:
  • libavcodec, the library for encoding/decoding
  • libavformat, the library for the containers
Share on Google Plus

About hacktohell

Love technology.
    Blogger Comment
    Facebook Comment