Containers and Codecs
From MediaCoderWiki
When using software programs like “MediaCoder” to convert one type of file to another, some of the problems people run into are: terminology and method.
End Result
It's always best to think backwards of what you want to achieve. Knowing the "end result" helps you decide the method to use. If you know your "end result" will be a file that will play on a home entertainment DVD, then you can choose the proper format and delivery. For a home DVD player, that would be determined on what the DVD player will accept. Other "end results" might be to create a video/audio file that would playback just on your computer, a file that plays on a older slower computer, or a file that you use for storage and editing. All these and many more examples each require a different process.
For example, my home DVD (the one hooked to my television) instruction book says it will accept MP3, VCD or DVD files. It also says that these files have to be on certain types of media or discs. In this case mine can read from CD -R, DVD -R, DVD +R and MP3's (recorded on a "data" type disc). Based on that information, I'll be able to setup things correctly to make a media disc that will playback on it. But, let's suppose that I want to create a video/audio file that plays back only on my computer using its CD or even DVD drive. Now, that would be a different setup altogether.
One important thing to remember is that each "end result" is unique. So, just because I create an video/audio file that plays on my computer, doesn't mean that it will playback on another device.
Containers and Codecs
First let's get some terminology out of the way.
A video/audio file is comprised of three primary things: A container, the codecs, and the video and audio signal. Some people refer to a container as the "format" or the sometimes the file extension. For instance, "AVI" is a container. MPEG2 is a container, QT/Quicktime's "MOV" is a container, and “WMV” is a container. All these "containers" hold the codecs for both the audio and video signal.
So what is a codec? CODEC is a acronym or abbreviation for "Compressor Decompressor". When you record or encode, transcode or "recompress" a video/audio signal you compress the signal, and when you play it back, you decompress it. Now, this had me stumped for years: If a video or audio signal is encoded with a certain codec, then you'll have to have that same codec to play it back. This is why you get that irritating message: "Windows Media Player cannot play the file. One or more codecs required to play the file could not be found." This, of course, is when you're trying to playback a file on your or someone else's computer.
So, as you can see, the type of codec you use within the container is also important, especially if you want compatibility between computers or platforms (MAC vs. PC). In other words, not all "containers" or all "codecs" work on all computers. To obtain additional codecs in the form of installable codec packs, see "Additional Information" below.
And, there is another issue: Many codecs have settings or options that allow you to set the quality of the encoding (and ultimately playback). The higher the quality, the larger the file size, and all of this “quality” requires more computing power, memory and player speed.
Choosing a container and codecs
Again, think backwards from what you want to create. If perhaps you want your final file for storage and playback on a PC, then MPEG2 container with the MPEG2 codec might work, or for little or no compression, then the AVI container using any of the low loss codecs like Huffyuv or DV to name a few. Just remember: quality will come at a cost in terms of eating up lots of drive space.
On the other hand, if you want a file that you can give to a friend that has a MAC, then perhaps a QT or Quicktime file would be best. Think about the delivery of the file. Is it going to be on a disc or streamed? You also have to think about what type of computer you’re going to playback the file on since it will have to have the necessary hardware (CPU, drives and memory) and software (OS, media player and codec support). You may even want to consider creating a master file that you can use for different platforms with different methods of delivery.
Sound confusing? Choosing a container and a codec is actually pretty easy when you follow these steps.
- Determine your final product, and what it will playback on.
- Pick the container
- Pick the codecs based on the platform or delivery (PC, MAC, DVD, streaming or other personal device), quality of compression, file size and specifications of the format.
Keep in mind that every time you convert or re-encode from one to another, you introduce more artifacts, more noise...etc. These "generations" start with the raw or shot video source and go down in quality for every conversion or edit. Essentially your dealing with math computations in these codecs and doing anything to a A/V file will "round" and "truncate" the math. True, some codecs do that math better!
So, it seems that you want to keep the video as good as possible by sticking with the generation your computer and editor will handle.
Note: Programs like “MediaCoder” may refer to containers codecs or compression in different terms. For example: In “MediaCoder”, audio "Encoder" is the same as selecting the audio codec, and video "Format" is the same as selecting the video codec. Also, while it is feasible to "mix and match" just about any codec with any container, many will be non-standard and won't be supported for playback.
A container/codec example: DVD home players
Now when it comes to using a container and codec that will work in a standalone (non-computer) DVD/CD player, it’s even easier because these DVD players will only playback an disc that contains certain types of files. Those files that are also made up of containers and codecs for both the video and audio signal are specific to the player and its hardware. Most modern DVD players will play either a VCD or DVD disc.
A VCD is a disc based on MPEG 1 standards. A DVD is a disc based on MPEG 2 standards. Playable DVD’s or VCD’s that will play in a standalone DVD player require three things: The correct type of disc or media and the correct files on the disc. These files on the disc have to conform to certain standards. They can either be “manually” burned to the appropriate media or you can use an authoring program.
Note: If you use a software program to create or “author” your DVD or VCD and your video or audio files don’t conform to the DVD or VCD standards, then the program will recompress the files as necessary. Many programs will only recognize certain containers, file extensions, formats or codecs. This also applies if you decide to manually create the proper DVD files (without using an authoring program) from “scratch” since the player will still need the correct files and layout.
USA Single layer DVD standards (basic)
- Media: DVD –R or DVD +R disc
- Container: MPEG2
- Video Codec: MPEG 2 (best) NTSC USA (525 lines)
- Size: 720 x 480 pixels
- Aspect ratio: 4:3 or 16:9 (widescreen)
- Frame Rate: 29.97 Bit Rate: CBR or VBR Minimum 2.0 Mbps to Maximum 8.0 Mbps
- Audio Codec: Uncompressed PCM (AIFF/Wave) audio or AC3
- Bit Rate: Maximum 1536 Kbps
- Sample Rate: 48 kHz
- Sample Size: 16 bits/sample
- Number of Audio Streams: 1 Number of Audio Channels: 1 (mono) or 2 (stereo)
USA Single layer VCD standards (basic)
- Media: CD –R disc
- Video Codec: MPEG 1 NTSC USA (525 lines)
- Size: 352 x 240
- Aspect ratio: 4:3
- Frame Rate: 29.97
- Bit Rate: CBR or VBR Minimum 1.15 Mbps to Maximum 1.856 Mbps
- Audio Codec: MPEG 2
- Bit Rate: Maximum 224 Kbps
- Sample Rate: 44.1 kHz
- Sample Size: 16 bits/sample
- Number of Audio Streams: 1 Number of Audio Channels: 1 (mono) or 2 (stereo)
For more information on USA or PAL DVD or VCD standards see: http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html
How much will fit (especially for authored or DVD's for standalone players)?
The amount of material you can put on a VCD or DVD disc is determined by the codec, compression, quality of the video and audio signal, duration and the type of media. There's no secrets here, it all comes down really to the bitrate of the signal. So, for saving files to a DVD or CD it's just a matter of having enough space.
For authored or discs that will play in a standalone player, you could spend a few minutes doing the math, but a quick search of the Internet will provide you with numerous "calculators" that will calculate the maximum amount of time or bitrate you can use.
Remember, when you use these "calculators" and you are creating a DVD or VCD for a standalone plyaer, you still need to conform to the DVD and VCD standards for either NTSC or PAL (see above), as well as leaving some space for file and menu generation.
Bitrate calculator for DVD: http://www.videohelp.com/calc.htm
What will it look like (quality)?
The old adage applies here: "Garbage In = Garbage Out". In other kinder words, if you start with a blocky, noisy video signal, enlarge it and "re-encode" it to another format, it's going look even worse. One example of this is when I thought I'd save a bunch of Flash Video files and convert them so I could watch them on my television. Well, they didn't look so good because of the quality of the original material, the re-compression, and the poor resolution of my television. Other factors for playback quality can also be determined by your codec settings.
CBR vs VBR, two/three pass
from: http://www.aidinc.com/features/dvdfaq.asp
CBR stands for "Constant Bit Rate", while VBR stands for "Variable Bit Rate". Bit rate is a measurement of how much your video is compressed. For instance, DVD video (not including audio or overhead) can be anywhere from 1.5Mbps (Megabits per second) to 9.2Mbps. When performing a CBR encode, all video is encoded to MPEG-2 at the same (constant) bitrate. When performing a VBR encode, the encoder intelligently varies the bitrate up and down as appropriate to the given video segment. VBR is more efficient, because different video segments are more or less complex than other segments. By using a low bitrate on some, the encoder can then using a higher bitrate on others. The idea is to only lower the bitrate when the video is easy enough to encode that you won’t notice the higher compression. As the compressionist, you define how much the encoder is allowed to vary the bitrate (typically by entering a minimum, maximum, and average bitrate).
In theory, you might think you should always use VBR because of its higher efficiency. In practice, however, encoders can make mistakes when they determine how much bitrate is needed for a given scene. If they guess to low, they can create ugly artifacts. For this reason, professional encoders offer features such as 2-pass VBR encoding and segment re-encoding to help reduce these errors. But professional encoders are expensive and 2-passes takes twice as long.
A good encoder using CBR will look great on shorter programs (up to about an hour). At some point, you will decide it is worth it to use VBR. There is no precise threshold for when to invoke VBR, but most programs that runs more than 70 to 90 minutes will benefit greatly from it.
Additional Information
MediaCoder converting examples: http://mediacoder.sourceforge.net/wiki/index.php/Converting_Examples
For more information on containers or codecs see:
- A/V Containers: http://en.wikipedia.org/wiki/Comparison_of_container_formats
- Containers and Codecs: http://www.animemusicvideos.org/guides/avtech/video4.htm
- Codecs: http://www.microsoft.com/windows/windowsmedia/player/faq/codec.mspx
- Codecs: http://people.csail.mit.edu/tbuehler/video/codecs/intro.html (older information)
- Codec Packages (Windows XP): http://www.free-codecs.com/download/XP_Codec_Pack.htm
- Codec Packages: (K-Lite): http://www.free-codecs.com/download/K_Lite_Codec_Pack.htm
- Codec Packages: (MediaCoder only): http://mediacoder.sourceforge.net/getfile.htm?site=sf&file=mediacoder-codecs-20071118.exe
Notice
This article is in process and will be edited to add more topics and information.
mixer, 01/03/08
The text contained in this article is copyrighted (automatically under the Berne Convention) and licensed to the public under the GNU Free Documentation License (GFDL).
"Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts." A copy of the license is available for viewing at: http://www.gnu.org/
If you create a derivative version by changing or adding content, this entails the following:
* your materials in turn have to be licensed under GFDL, * you must acknowledge the authorship of the article (section 4B)
You may be able to partially fulfill these obligations by providing a conspicuous direct link back to the article hosted on this website. Other obligations may also have to be met.
