Transcoding beginners guide:H264,MP4,AAC,MPEG4 ASP explained

Discuss about generic usage of MediaCoder.

Moderator: HuggiL

dtechnology
Amateur
Amateur
Posts: 22
Joined: Tue Jan 19, 2010 8:55 pm

Transcoding beginners guide:H264,MP4,AAC,MPEG4 ASP explained

Post by dtechnology » Mon Jan 25, 2010 4:41 am

Since it took me a lot of time to figure this out for myself, I decided to write a small guide summarizing this out.
This is meant to be a comprehensive guide for people with no or little knowledge of video encoding, decoding, transcoding and thing like that. It is not meant to be a complete overview of the trancoding field.
Feel free to link to it (or make it sticky ;) )

Suggestions, corrections or points of improvement are welcomed.

[anchor]basics[/anchors]
[goto=basics]The Basic terms[/goto]

If you lack a solid basis, things can get confusing very quickly. You might already know some of this, but I still advise to read it through fully.
Please note that "device" can mean anything that can play media files, including a computer.
The longer the paragraph is, the more detailed it gets and the less important the information is. If you lose track or don't find the information interesting anymore, skip to the next one!

Isn't it amazing? What? You don't get it? This is amazing: that you are reading this article now is amazing. That your device works is amazing. If you realize it's complicated hardware and operations it performs just to show you the sentence you are reading now: amazing. But I digress. What I meant to tell you is: nothing in (electronical) devices can go automatically. Everything is done, stored, transferred and processed as bits. Including a media (video and/or audio) file. Because a bit is nothing more than a 1 or 0, it cannot hold very much information by itself. However, if you concatinatie them into a bitstring (e.g. "1010") you can store for example 1024 different values using only 10 bits. Use a thousand (Kilobit,Kbit or Kb), a million (Megabit or Mbit) or even more you can represend (store, view) almost anything. (note: it is actually 2^10 bits for kilobit, 2^20 bits for megabit etc. This is why windows reports your "750 GB" hard drive to actually have about 700 GB of space. Officially a Kilobit is 10^3 or 1000, but because 2^10 or 1024 was so close early Computer Scientists decided to use that instead, of which we now have the legacy)

A group of 8 bits is also usually called a byte (altough less usually in the transcoding field). 1000 or 1024 bytes are called a Kilobyte, a million or 2^20 a Megabyte and so on. To differ between the two capitals are used. A Kilobit is called a "Kb", a Kilobyte is called a "KB", the same for mega-, giga-, and so on. Capitals are important when talking about bits and bytes. To calculate bits out of bytes, multiply by eight. To calculate bytes out of bits, divide by eight.

However, you can not just send billions of bits to a device and tell it to get cracking. A computer needs to interpet that bitstring, it needs to know what it means. This is where it becomes interesting, and were codecs come in. A codec is short for encoder and decoder combination. A codec contains both (although sometimes a "codec" includes only a decoder). A coder "tells" the computer how to store the bits (create a file), a decoder "tells" the computer how to read them (play a file). Well known video codecs are MPEG2 (DVD), MPEG4 part 2 on which XviD, DivX) are based. WMV 7, a codec from Microsoft, is also based on this, but is incompatible with the other one. Theoretically alls MPEG4 part 2 decoders should be able to read each other. Initially this wasn't so, but nowadays that has been pretty much achieved. There are much, much, more codecs, but for the sake of simplicity I will focus on the most modern and upcoming one, described in the next paragraph.

The most interesting and currently frequently used codec is MPEG4 part 10, known as H.264, AVC or H.264/AVC. Microsoft also made a version of it called VC-1 or WMV 9, but again it is incompatible from the rest. I will focus on main H.264. H.264 is rapidly being introduced on all sorts of devices and formats (mobile phones, Blu-ray players, computers, the internet, flash, you name it!) and has an unique feature currently no other codec has: almost everything manufactured nowadays that support media playback support H.264. This defiantly amazing status has not been achieved by other formats and codecs. Windows supports it natively since Windows 7 (you need Home Premium or higher), iPods have it since the iPod video 5G (very limited) and iPod classic (more general). The iPhone has it, android has is, modern Windows Mobile Phones have it, Blu-ray has it, HD-DVD has it (okay, that's not so interesting anymore), Digital TV has it for HD playback (altough also MPEG2 is used) and even simple mobile phones have it (very limited) as .3gp.

Well known audio codec are MP3 (MPEG layer 3, part of MPEG 1) and the more modern one AAC (MPEG 4 layer 3) also known as LC-AAC. AAC has almost fully replaced MP3 as an audio codec (it has been in use since the origional iPod by apple, other players soon followed), altough it can only be played natively on Windows since Vista (or 7, I don't remember). My advice to everyone would be to stop using MP3 and switch to AAC, there's simply no reason not to. Improved versions of AAC are called HE-AAC and HE-AAC v2. While they are interesting and support much better compression, support has only recently started to appear (e.g. the iPhone supports it since iPhone OS version 3). AAC is used as the default audio format for all MPEG-4 formats, and as with H.264 nearly every media device supports it.

The last thing you need to know are containers. They are used for storing an audio and video file together. A well known container is AVI (Audio Video Interleave, c'mon you've never seen a .avi file before?). While widely supported it is at the time ancient, deprecated, obsolete, legacey and any other term you can think of :). The only reason it is still used is because of it's wide support. luckily that is starting to change (also thanks to H264).

Modern containers are MP4 (official MPEG4 container), MKV (A flexible one that supports a wide range of formats and options) and WMV (only used and usable for WMV video). MP4 and MKV are the preferred containers for H.264, depending on use. MP4 is widely supported and thus I would generally recommend this. MKV is useful if you want some of its cool features (like multiple audio streams/languages, subtitles and chapters)

this guide is currently still under construction. I plan to finish it within a week. Feedback is appreciated.

Things that will certainly be included: bitrate, cbr, abr, vbr, 2-pass, resolution, aspect ratio, audio channels, video channels, (soft) subtitles and probably more. If you think something should be added: post or PM. I will also structure the guide a little more and add more (sub(sub))sections, but I first want to fully complete it.

dtechnology
Amateur
Amateur
Posts: 22
Joined: Tue Jan 19, 2010 8:55 pm

Re: Transcoding beginners guide:H264,MP4,AAC,MPEG4 ASP explained

Post by dtechnology » Mon Jan 25, 2010 4:48 am

Oops, see that this forum doesn't support the [anchor]if_you_dont_see_this_it_does[/achor] tag, nor the [goto=if_you_dont_see_this_it_does]goto tag[/goto] (if this is a link it does). Requesting it to be added as custom BBCode, since it is a very usefull and simple tag, especially for guides.

BBCode:

Code: Select all

[anchor]{SIMPLETEXT}[/anchor]
Replacement:

Code: Select all

<a name="{SIMPLETEXT}"></a>
BBCode:

Code: Select all

[goto={SIMPLETEXT}]{TEXT}[/goto]
Replacement:

Code: Select all

<a href="#{SIMPLETEXT}">{TEXT}</a>
A combination (I prefer, but not many board implement it). You can rename it to anything you like (ilink = internal link), but I would advice not to use anchor since it might confuse people.

BBCode:

Code: Select all

[ilink={SIMPLETEXT}]{TEXT}[/ilink]
Replacement:

Code: Select all

<a href="#{SIMPLETEXT}" name="{SIMPLETEXT}">{TEXT}</a>
Hmz, I don't really like the code tag implementation here neither, but it is my personal opinion.

dumpy
Amateur
Amateur
Posts: 35
Joined: Thu Dec 17, 2009 4:45 pm

Re: Transcoding beginners guide:H264,MP4,AAC,MPEG4 ASP explained

Post by dumpy » Mon Jan 25, 2010 6:01 am

Actually I completely disagree about your status of h264, I was recently looking for media devices, like the WDTV Live, and found that many devices supported dvix/xvid rather than h264. There are many mp3/mp4 players that only play xvid and not h264. Many of the sub-$100 mediaplayers that you can hook up directly to a tv support xvid rather than h264. Especially chinese-made devices that you find all over the internet, like ebay. Most upconverting dvd players that also have usb jacks only accept xvid, not h264. Like I said, I spent months looking at specs for dozens of media devices and found dvix/xvid far more popular. While quite a few of the devices that play xvid can also play h264, almost every device I've seen that plays h264 can also do xvid. I will say that h264 and VC-1 will soon be the format of choice for device manufacturers as more devices become HD oriented, I just think it's misleading to say that almost everything being built today can do h264. And I definitely don't agree that h264 has achieved some amazing ubiquitous state that no other format has ever gotten to, from your list of examples it's clear that h264 is generally favored in devices that handle high-def, but it's not in such favor with SD content. Netflix doesn't even use h264 for it's streaming; they use wmv9 and VC-1, according to their own blog. I think it's safer to say that between xvid AND h264, you probably can't go wrong with MOST of the devices built today. I personally prefer h264, but xvid is still essential in many cases.

And while we're on the subject, even though you haven't gotten to bitrates and profiles yet, let's acknowledge that while many devices can play h264/AVC - there are many different AVC configurations and each device has it's limit. So, as a disclaimer up front, let us inform the reader that even if h264 were to achieve truly ubiquitous use among media devices; there is no h264 configuration that will work for everthing and still play on all h264 compatible devices. I'm also not sure it's technically accurate to say that VC-1 is the Microsoft version of AVC. As far as I've read, they are alternatives to each other built on similar technology, but not the same.

dtechnology
Amateur
Amateur
Posts: 22
Joined: Tue Jan 19, 2010 8:55 pm

Re: Transcoding beginners guide:H264,MP4,AAC,MPEG4 ASP explained

Post by dtechnology » Mon Jan 25, 2010 7:20 am

dumpy wrote:Actually I completely disagree about your status of h264, I was recently looking for media devices, like the WDTV Live, and found that many devices supported dvix/xvid rather than h264. There are many mp3/mp4 players that only play xvid and not h264. Many of the sub-$100 mediaplayers that you can hook up directly to a tv support xvid rather than h264. Especially chinese-made devices that you find all over the internet, like ebay. Most upconverting dvd players that also have usb jacks only accept xvid, not h264. Like I said, I spent months looking at specs for dozens of media devices and found dvix/xvid far more popular. While quite a few of the devices that play xvid can also play h264, almost every device I've seen that plays h264 can also do xvid.
You are (somewhat) correct, I think I will nuance the guide on that point. But you have to agree: it's quite rare that one format has such wide support (especially on mobile devices).
I do agree that (currently) MPEG4 ASP (Xvid) has wider support, especially on devices in the somewhat cheapear price range (no offence at you indented) and devices that deal with high resolution (TV, HD) because H.264 is so resource-intensive, especially at high resolutions. I do expect that to change in the coming (1-3) years, as hardware develops and becomes cheaper. And, you must admit, "normal" people are much-less interested in (usually somewhat difficult to use) media players like the one's you cited. Most want an easy way to transcode their videos to their iPods, iPhones, mobile phones, PSP's and what nows what. And I cannot think of such a current device that does support MPEG4 ASP but not H.264.
I must admit I find it strange that streaming media devices also do not often support H.264: you would think the lower bitrate (at same quality) would outweigh the disadvantages. Maybe it is just to pricey.
I was already planning to explain Xvid in the guide, so de facto it doesn't change anything. As I intended this guide to be future-proof, I still will focus mainly on H.264.

To conclude: H.264 currently has higher market share on low-resolution and bitrate markerts (mobile, internet, etc.), but still leaps behind MPEG2 and MPEG4 ASP on higher-resolution devices, mostly because of cost. I expect that to change
I will say that h264 and VC-1 will soon be the format of choice for device manufacturers as more devices become HD oriented, I just think it's misleading to say that almost everything being built today can do h264. And I definitely don't agree that h264 has achieved some amazing ubiquitous state that no other format has ever gotten to, from your list of examples it's clear that h264 is generally favored in devices that handle high-def, but it's not in such favor with SD content. Netflix doesn't even use h264 for it's streaming; they use wmv9 and VC-1, according to their own blog. I think it's safer to say that between xvid AND h264, you probably can't go wrong with MOST of the devices built today. I personally prefer h264, but xvid is still essential in many cases.
I already explained most of it above, but I do agree. I might add a (small) VC-1 section too. To state again: it is as much intended a basic information on transcoding guide as it is a "How do I" guide, so it is relatively codec-independant (with the exception of bitrates, profiles and levels)
And while we're on the subject, even though you haven't gotten to bitrates and profiles yet, let's acknowledge that while many devices can play h264/AVC - there are many different AVC configurations and each device has it's limit. So, as a disclaimer up front, let us inform the reader that even if h264 were to achieve truly ubiquitous use among media devices; there is no h264 configuration that will work for everthing and still play on all h264 compatible devices at this time.
I totally agree (altough you could probably play a AVC BP 1.3 320x240 128 Kbit/s file on any device, it's not what it is intended to). A large goal of this guide is to make alle the profiles, levels and bitrates clear, as that was one of the most annoying, confusing and difficult thing for me to find out. Now that I understand them, I want to summarize and explain them clearly.

dtechnology
Amateur
Amateur
Posts: 22
Joined: Tue Jan 19, 2010 8:55 pm

Re: Transcoding beginners guide:H264,MP4,AAC,MPEG4 ASP explained

Post by dtechnology » Mon Jan 25, 2010 11:42 am

thanks mixer.

A small preview of what I want to include further in my guide: this topic.

I understand the locking&guide part, and made this topic a normal one precisely because of it: I would like feedback and/or corrections, as I'm not 100% sure of my knowledge (yet). Also I plan for the final version to be a little more balanced and include a short (description) of semi-popular ones (e.g. I haven't mentioned On2 VP or Ogg at all, while still relatively well-known/well-used)

The final version will be a little more guide-like, but I will keep the "story" aspect, especially in the beginning. I think it allows easy entrance for absolute newbies and doesn't overload the brain with acronyms. Also switching serious information (which I made bold) with less-important information or just fun-facts allow the guide to be interesting all the way-though, for different knowlegde- and experience levels (okay, that is a hyperbole but you know what I mean). I don't know how it will end up, but the guide might by suitable for reading twice by the same person: once as an abosulte beginners guide/introduction (=not understanding it fully and skipping parts) and a second time once a reader has some more knowlegde and/or experience: he can then understand it fully (altough it will still be relatively basic knowledge).

I also intend to link to the other guides, especially the aspect ratio guide and make a latex/pdf version (in fact: I'm creating it now as it is easier than on a forum, while it can still be easily converted to forum style)

meRobs
Expert
Expert
Posts: 3116
Joined: Tue Jun 23, 2009 2:45 pm
Location: Sydney, Australia

Re: Transcoding beginners guide:H264,MP4,AAC,MPEG4 ASP explained

Post by meRobs » Mon Jan 25, 2010 1:16 pm

Suggest you modify you comments about AVI. Age doesn't mean 'of little use'!
Certainly, if your only concern is modern gadgets (iPods, iPhones, etc), then, sure, the newer containers are more relevant.
However, don't forget that MediaCoder caters for other conversion requirements, such, as conversions to suit quality video editors that far prefer (even need) formats that do not have intra-frame compression. For example, Adobe Premiere prefers DV-AVI or AVI based on the Huffyuc Codec.
Also, quality digital cmovie cameras often output to DV-AVI.
Have you checked out the Tips & Guides for MediaCoder? Try: http://forum.mediacoderhq.com/viewtopic.php?f=17&t=8061
Also, get older builds at: http://www.videohelp.com/tools/MediaCoder/old-versions#download

dumpy
Amateur
Amateur
Posts: 35
Joined: Thu Dec 17, 2009 4:45 pm

Re: Transcoding beginners guide:H264,MP4,AAC,MPEG4 ASP explained

Post by dumpy » Mon Jan 25, 2010 7:03 pm

Some of your response, dtechnology, baffles me. There are contradictions and elements of your argument that aren't coming across very well, re-read your response and you'll probably see what I mean (also it seemed a little passive-aggressive in a couple of spots). I'm not going to break it down point-by-point because we could go back and forth on a issue that just isn't that interesting or pertinent to the overarching topic (not to mention distracting from the true purpose of this collaboration).

My main point has been illustrated by mixer; the finalized guide should have only basic descriptions of the most popular codecs and just enough supporting information to help beginners know how to choose which codec to use and how best to set it up for a video encoding. No personal preferences for a certain codec. That was my only intention in pointing out a few inaccuracies and biases that I thought was coloring a guide that was otherwise off to a good start. And I did try to present my points in an emotion-less and unbiased manner. I take my academic guides very seriously and find that they are best written from a neutral, just-the-facts perspective. Just in case you took my earlier comments as an attack on your work.

I think instead of saying that one codec is better than another, mention that a person should first check the specs of their media hardware and then choose based on that information (this is the real point behind my earlier comment). Perhaps mention what differences a beginner would see in file size and bitrate when a file is converted into xvid, h264, etc.. That comparison information alone should allow individuals that have multi-format media players to choose intelligently which codec is best and how to anticipate what effects a given conversion might have for their video files.

Regarding Mixer's comments: I completely agree it's best that the first draft of the guide be done as an open topic that people can comment on. Cooperation could yield a better product. Then, the finished guide could be reposted and made sticky. Otherwise, we end up with people making competing guides that offer more personal preference rather than actual useful information when instead we could have a one-stop source for the basics. Honestly, this information already exists in a thousand places all over the internet; the only hope this guide has for becoming great is to take that scattered and somewhat arcane information and distilling it to the core principles that a beginner needs the most. I know that's what I was hoping for when I first saw this thread.


dtechnology
Amateur
Amateur
Posts: 22
Joined: Tue Jan 19, 2010 8:55 pm

Re: Transcoding beginners guide:H264,MP4,AAC,MPEG4 ASP explained

Post by dtechnology » Tue Jan 26, 2010 2:34 am

dumpy wrote:Some of your response, dtechnology, baffles me. There are contradictions and elements of your argument that aren't coming across very well, re-read your response and you'll probably see what I mean (also it seemed a little passive-aggressive in a couple of spots).
-- snip --
That was not my intention. I simply (mostly re-)iterated my arguments why I did something and why I (mainly) support H.264: because I think it is the most interesting for new users so they would want to read about it. It also is a difficult codec for new users, e.g. with Xvid you can come far if you only know what a bitrate is, while that certainly is usually not enough with H.264.
Again: it is not my intent to make this guide "the ultimate guide on H.264", but more as a universal starting point for new beginners. At this point I believe that includes some basic explanation on avi, mkv and mp4, mp3 and (he-)aac and finally a basic explanation of MPEG4 ASP (Xvid, Divx) and a more advanced explanation on H.264. But, again, most of it should be universally relevant.
Bear also in mind that text (especially quick-writte like on the internet) does not always brings it message 100% across. Both the reader and writer could (and usually are) be to blame on that: a writer might not phrase it's text correctly (especially if he is, like me, foreign) and a reader might read a text incorrectly or biased (especially if he already has an opinion on someone or got into discussion earlier). I am always trying to be aware of that, and try to bring my intention as good as possible. Also please note that disagreeing and bringing in arguments in not the same as hostile behaviour. I disagree with you, but am not hostile to you. Please consider that before using words like "baffle" and "passive aggressive".
I don't see the contraction immediately, but they might be caused by my efforts to nuance my point of view.

Please note that I do not wish to turn this thread into a flamewar, especially not a personal one, but neither one about "what is the best container/codec/format". I restate that this is a beginners guide. I do acknowledge that a lot of points of view can be more nuanced, and I have already edited the guide on that (not online though yet).
Regarding Mixer's comments: I completely agree it's best that the first draft of the guide be done as an open topic that people can comment on. Cooperation could yield a better product. Then, the finished guide could be reposted and made sticky. Otherwise, we end up with people making competing guides that offer more personal preference rather than actual useful information when instead we could have a one-stop source for the basics. -- snip --
I completely agree. Note that I do not intend to give this guide an "arcane" status (altough it would be nice ;)) But I do intend is to be a good and usefull one, thats why I placed it here. If I wanted to make another average to "okay but just not really complete" guide I would've made it myself fully :P

Also note that I'm planning to release the guide under Creative Commons ANS (the dutch version because that's where I live, so I need to use it). If enough writers contribute/change I will remove the Attribution clause. If it causes problems for Mediacoder, I will remove the Non-Commercial clause. I will not remove the Share-Alike clause.
So if you really don't like it you can always make your own version ;)

While true that many guides are available most are either:
  • Of bad to moderate quality
  • On a specific topic
  • On an advanced topic
  • Not very well written
or a combination of those. Again, my purpose is to create an all-round guide suitable for a solid (thin) foundation and to get your toes wet. And besides I currently do not see such a guide on the MediaCoder forums, which is the first place they will look if they don't get it.

I mainly do this because I never found such a guide, and Mediacoder was waaay to confusing for me when I tried it a few years ago (0.5 since). I had to use all sort of freeware crap. Ofcourse mediacoder has come a long way since then (extentions, ipod version etc.) but the core of the problem is still there.

I hope this clears things up a bit
Last edited by dtechnology on Tue Jan 26, 2010 2:40 am, edited 1 time in total.

dtechnology
Amateur
Amateur
Posts: 22
Joined: Tue Jan 19, 2010 8:55 pm

Re: Transcoding beginners guide:H264,MP4,AAC,MPEG4 ASP explained

Post by dtechnology » Tue Jan 26, 2010 2:39 am

meRobs wrote:Suggest you modify you comments about AVI. Age doesn't mean 'of little use'!
Certainly, if your only concern is modern gadgets (iPods, iPhones, etc), then, sure, the newer containers are more relevant.
--snip--
While true, keep in mind that this guide is indented at beginners. They are generally not interested in (semi-prof to prof.) camera's and DV (amateur camera's usually just output in a more well-known format by default unless you change them, if that is even possible).
So I will nuance the guide a little bit on this point, but rather have beginners think "AVI SUX0RZ" that they later can nuance when they gain more knowledge then that they start using AVI unnecessarily because "AVI IS TEH BEST HE SAID SO ROFLOLOLOL" ;)

Post Reply