Thursday, July 2, 2009

3GP, MP4, M4A, WMA, AVI, DIVX and codecs

Hello again,

As the title suggests today I'm going to write a little bit about different Video file formats and what's the relationship between the file format (also called container) and the Video codecs. Finally I'll make some comments about some differences and what file formats and codec combos are better to use in Nokia phones and what are some common drawbacks.

Some of this information or for more details check out my Older post on How to become a better video editor

File Formats

The first thing is that we need to understand that the file container or wrapper, also known as the file format is what the name implies, just a wrapper, a structure or vessel where the content is going to be contained.

A file with extension MP4 can contain many different things inside. It could be an audio file, a video file, audio/video, or something else. The audio or the video can be encoded in many different ways and also using different codecs. Like xVid, MPEG-4, MPEG-4 AAC, eAAC+, H263, H264, to name a few.

The same goes for M4A or AVI or other file extensions. In fact M4A containers can have also video and they will work in Nokia devices, and MP4 can contain MPEG-4 audio files and they will play in the Music Player.

Some file extensions are commonly used only with one format of codec, but this is just that. It's commonly used. But you can put other things inside it and it's still a valid file and will work with several programs. Some extensions have changed it's use throughout time.

3GP format and later 3G2 were selected as the file container for MMS files and other telephony video formats as part of the 3GPP Standards. In general these files usually contained H263 encoded video, but more and more they are containing MPEG-4 and H264 video.

In the 90's .AVI files where usually containing uncompressed video like IndeoVideo, YUV2 or MSvideo. Now most AVI files contain xVid or Divx coded videos. But I still have some old encoders that will encode raw video into AVI.

This is one of the problems most people have when they try to play videos on their portable devices. They see an MP4 extension and assume that the video is MPEG-4 and that it must play in the device because it supports MP4. This is far from true. You need to know what exactly is inside that MP4 wrapper to know if it will play.

Some proprietary codecs have proprietary extensions so they are a bit easier sometimes. Still the contents could be different depending on the codec version used. See Video Codecs. Some examples:
  • DIVX coded videos are in .divx file format
  • Windows Video 8/9 videos are in .WMV file format
  • Quicktime format videos are in .MOV file format
  • MacroMediaFlash videos are in .FLV file format
  • RealVideo videos are in .RM format

Video Codecs and their relationship to File types

Ok so now that we know a bit more about file formats and containers, let's talk a bit about codecs. There are a number of video codecs. Each codec usually has also several versions or levels or a combination of both. E.G. H264 can be Baseline or Main Profile and then there are 4-8 levels within each profile.

The most common formats for videos I've come across are:

AVI files
These files usually contain divx or xvid coded videos. Although as mentioned before sometimes they contain uncompressed video. These files don't play out of the box in Nokia devices, but you can install Divx mobile player, Smartmovie or CorePlayer to use them.

MOV files
This is a proprietary format from Apple. They usually contain Quicktime coded files although more and more files I've seen contain MPEG-4 or H264 (MPEG-4 AVC) coded videos. These only play in the iPhone. You need to change the container or re-encode them into a suitable format.
Some MOV files have 480p, 720p or 1080p video resolutions. Also called High Def.

WMV files
This is a Microsoft proprietary format that has been licensed by many vendors including Nokia. The most recent Nseries devices starting from the N78 and N96 can play WMV videos if they are WMV8 or WMV9 and the resolution is less than QVGA (320x240). Newer models may support higher resolutions but I haven't tested that.
Some WMV files contain AC3 audio (5.1 surrund sound) and can contain HD content (very high resolution video). This is great to watch in a nice flatscreen, but require conversion to be able to watch them on the phones, and some encoders still can't handle AC3 correctly.

FLV files
MacroMedia flash has existed for many years. It was used for video and animations since the early 90's and came of age with the internet. But it wasn't until Google Video and YouTube started using this low quality file types that FLV really took off. Before FLV streaming became the norm most sites were using RealPlayer or ASF (windows format) to stream video over the internet.

Now it seems that even in the Microsoft video webpages they use FLV format to stream video content. The advantages of FLV is that it's very economical in bandwidth and storage the downside is that it's not very high quality. Now they have the HQ option in YouTube but then you lose the advantage of the low bandwidth. Another quirk is that usually you can't download these videos they're for streaming. You need some special or extra software to save the stream locally so you can re-encode them or transfer them to your device.

FLV videos will play on most new Nseries devices, but high quality FLVs may stutter quite a lot as they need a lot of CPU to render. Still, the best way to watch them is in the browser, but you can also side-load them and play them from the File Manager.

RM Files

RM or RMVB files contail RealVideo coded videos although they can contain audio only as well. There are many versions of the RealVideo codec and not all of them are supported properly in Nokia devices, so it's a bit of a gamble if you have an RM file. It may or may not play. Also the resolution needs to be a specific one otherwise it may not play 320x144 may play but 320x140 may not. I haven't figured out what the pattern is. It may be that it needs to be divisble by 16 or something like that.
The main advantage for these files is when you are using a streaming server since in a single file you can have support for multiple downlink speeds, so that the watching experience is good even if your broadband is not very fast.

MP4, 3GP, 3G2, M4V files
I put all of these file types together because they can pretty much be used indistinctibly. Also these files are surprisingly not very common even though a lot of mobile phones use these file types. Even some people have trouble playing them back specially the 3GP and 3G2 file types.

Most of these files can contain a number of different things and as such they are sometimes the trickiest to figure out why they don't play correctly. In many instances I end up re-encoding them again into the same file type but with a different codec or settings.

Mp4 seems to be the one that is sticking more and more as a Video format, but what's inside seems to vary a lot. Many of the MP4 files I've come across contain MPEG-4 or MPEG-4 AVC H264. But some contain xVid.

I actually found it odd that although most people think of MP3 as a music file format but even though MP4 can also contain music files, people think more of M4A as the MPEG-4 file format. I guess it's all thanks to iTunes, but it's funny to me nonetheless.

For a while I used 3GP for H263 coded files and 3G2 for MPEG-4 videos, it's convenient as this file format is supported by all 3G phones (or should be as it's part of the 3G standards). But like everything else, some combinations are not supported. Is should also be noted that 3GP, 3gpp can also be used for music files. Older 3GP files will have AMR or WB-AMR audio which does play in most phones but may not play in some PC video players.

Some differences in Codecs

Ok now I explained the different common file types and the codecs they usually contain. Now I'll talk about some differences.

One thing we need to keep in mind is that different codecs perform different types of compression. A codec is really a compression algorithm. The most effective codec then is the one that will look better with the lowest bitrate. In other words, the benefit of a "better" codec is that you will get better results with less information (bits, bitrate, file size). This is very important, because at some point, if you use too much bitrate you will lose the benefits of the codec and the resulting video quality and file size is the same regardless of the codec.

Newer codecs are not "better" than older codecs in terms of video quality.

Newer codecs are better in terms of compression, so they yield better results at lower bitrates.

As an example. If you encode a video in QVGA resolution at 2.0 Mbps into an MPEG-4 codec and also in an H264 codec also at 2Mbps the resulting videos will be almost exactly the same in terms of file size and video quality. The same could be said for xvid. So at this bitrate the benefits of H264 are lost, there is no better quality to be gained by adding more information (bits). But if you do the same video (QVGA) but do it at 128 kbps in both MPEG-4 and H264, then you WILL see a clear difference.

The same could be said for H263, MPEG-2 or MPEG-1. At low bitrates the vides done in these codecs will not be as good as the results using xvid, divx or H264.

BUT, if you crank the bitrate high enough you will get the same size and quality from any video codec.

This makes sense. After all DVD are encoded using MPEG-1 or 2 and blueray are mostly MPEG-4 AVC to get the size down for HD resolutions, but the first bluray discs used MPEG-2 video.

I hope I didn't confuse you a lot with this.

So what's the difference?

"Best" codec/file combos and common drawbacks
The difference of the different codecs/file formats for ME (IMHO) is how easy it is to move them between my different devices. PC-PS3-Phone-PSP-Digital Frame

With now most phones supporting very high bitrates of 1.5 to 2 Mbps videos in MPEG-4 and H264, the quality issue is pretty much done. That is until we move to larger resolution screens beyond the VGA range.

I tend to like AVI files containing xvid or divx codec if I have them already in this format. This is by far the most supported format I've seen. It seems to be everywhere. There are a ton of devices that support "DIVX files" in AVI format.

If I'm encoding a DVD or other source video for use in my devices I first make a master copy in DIVX at the same resolution and high bitrate to use as the basis for further encoding. This has served me well since my days with the 7710 and Ngage. As devices supported higher resolution I could re-encode the master high rez copy into new formats. Then I encode into whatever is the best for my device. In the case of the N96 the best seems to be MPEG-4 (also because Nokia only supports baseline H264 which is not supported by other devices sometimes). I use the MP4 file format as this seems to be the most commonly used.

RealVideo formats seem to be disapearing fast IMHO, I don't see it as often. FLV is king for streaming but not so for local playback. WMV is so-so. Mostly I've been using it for my home movies because I had already a bunch of home videos in WMV format, but I never convert videos into WMV if I can help it. Also the fact that only QVGA max resolution is supported in N96 is a drawback. Haven't heard if N97 brings WMV support for higher rez.

H263 in the 3GP file format is fairly common as many basic phones only record into 3GP using this codec. But more and more are using MP4/MPEG-4 combination to record, so it may be that in time it will go the way of the .qt files or .rv or .nim

And if you don't know what those file formats are then you have nothing to worry about, you're still young and have a long life in front of you. ;-)

Until next time I hope you enjoyed this.

PS: All these comments are IMHO. If you have a different perspective then good for you!

3 comments:

Billy (London) said...

Excellent summary there, well done!

It would be nice, now, to let us all know what is the best (IYHO) method (i.e. software.programme) to make those file conversions you mentioned above. Starting from, how (and maybe why) you encode a DVD into a master DivX? Couldn't you just rip the DVD and store it safely as a combination of VOB and IFO files? Surely, this is the most accurate "extraction" possible?

Also, and this is something I realised over the past few months that I have trying to master DVD encoding, I find that the quality of a DVD encoding varies from DVD to DVD for identical codec settings! I can't reall explain that, other than encoding is a function of original video quality; but then, how is the original video quality of a DVD quantified?

El_loco said...

To convert from DVD into DIVX or other format I use the ImToo DVD to 3GP suite. They also have another product called DVD to MP4 suite. They're both great and not very expensive. There's a link here to download it. Xilisoft also has a DVD to 3GP converter. And there are others out there (Handbrake, VLC, Red Kawa, etc.)

VOB + IFO files will (as you mentioned) work better in terms of keeping the original quality, I find it easier to work when the movie is in a single file. But you're right.

Well not all DVDs are created equal. Some use MPEG-1 encoding. Some are just not so good to begin with. Check out the reviews at ign.com about how are some DVDs in terms of video transfer. It all depends on who did the video master.

For example. I have Predator in Bluray, and the transfer is really poor, so even though it's bluray, the video quality is worse than some lower resolution DVDs I have.

Billy (London) said...

Thanks for your response.

I have followed your advice and trialed lmTOO Media Toolkit 5 in 1, which includes the DVD to mp4 converter/encoder. To be honest, I find it very poor, cheap and flaky. It doesn't really do a better job than Nero Recode and offers far less options than what I need.

In the past few days, I spent long hours researching and found a FREE software on download.com that, I must say, does a better and more comprehensive job than any other video converter/encoder programme (including some really expensive programmes). It is called "Any Video Converter" and it really does what it says and never failed me so far :o)

It is so simple to use, yet has extra features and various encoding techniques and containers to experiment with. The beaty behind it is that you can add your own subtitle files and hard code pretty much anything! All that for FREE!

So far so good. Only thing left for me to discover is how to and what to use in order to burn a compressed video file onto a DVD video (that will play on any ordinary DVD player) with optional subtitles so that you can turn them on or off as you would in an original DVD video.. I'll keep you posted!

FREE TRIAL