如果这篇文章的标题还没有让你头疼(head hurt),那么它的其余部分肯定会。好吧(Well),希望我能以对非技术人员有意义的方式来解释它。我正在写这篇关于video/audio codecs becauseI文章,因为有一天我试图向朋友(friend one)解释它时发现自己很困惑。
究竟什么是编解码器?我知道你需要他们在这里和那里播放电影,但它到底是什么?真正让我感到困惑的是我听说过但从未真正理解过的所有术语:H.264、DivX、MP4、AVI、MPEG-2、AVCHD、AAC、OGG、MKV等。这些都是编解码器吗?经过大量阅读和学习(reading and learning),我意识到音视频编解码器(audio and video codecs)和容器格式(container format)的世界非常混乱。其实我真的不知道编解码器和容器格式的区别(container format)直到我开始研究。
我不会详细介绍,只是因为这个话题很快就会变得非常简洁。如果 1 小时RAW(RAW)未压缩 1080p 60 帧每秒的视频会占用近 500 GB 的存储空间(storage space),您真的关心吗?可能不是。
什么是编解码器?
那么究竟什么是编解码器,它有什么作用呢?用最简单的术语来说,编解码器是编码器/解码器,或者在其原始形式中是压缩器 (co) – 解压缩(– decompressor)器(dec)。这正是编解码器所做的:它获取一个数字文件并将其压缩(或对其进行编码)以进行存储,并对其进行解压缩(或对其进行解码)以进行查看或转码。稍后我会告诉你什么是转码,我们不要这么早混淆自己。
要理解的重要一点是,编解码器有点像比特流外观的规范。什么是比特流?为了不是非常技术性,这就是应该如何为该特定编解码器安排字节序列。每个编解码器都有一组特定的准则。例如,它可以指定宽度、高度、纵横比等。看看这个页面,但不要阅读太多,否则你的头会受伤:
http://www.cs.cf.ac.uk/Dave/Multimedia/node262.html
因为它是一个规范,所以我有很多方法可以将数据转换为该格式。因此(Hence),一个编解码器可以有多个编码器。我将在下面的流行编解码器部分(Popular Codecs section)解释更多关于编码器的信息。
那么为什么我们甚至需要所有这些压缩和解压缩(compression and decompression)呢?就像我上面提到的,一个RAW(Well)未(RAW)压缩的 1080p 文件在一个小时内几乎高达 500GB。如果一切都以这种格式记录,您将需要自己的数据中心来存储您所有的家庭视频。这就是压缩发挥作用的地方。有不同类型的压缩,可转换为不同类型的编解码器。那么有哪些流行的编解码器?
流行的编解码器
H.264 (MPEG-4 Part 10 AVC) – 这也被正式称为MPEG-4 Part 10,但H.264是您通常听到的。是的,同一事物也有多个名称。H.264是迄今为止最流行的视频编码格式。H.264提供了世界上最好的:更小的文件大小和更高的质量。
同样(Again),请记住,H.264只是编解码器,您不会找到任何带有 .h264 扩展名的文件。这就是容器格式的用途,我将在下面的部分中解释。从智能手机到数码摄像机再到蓝光光盘(Blu-ray discs),该编解码器被广泛使用。它今天也用于提供大量网络视频,(web video today)因为它能够以高压缩比(compression ratio)和低比特率为您提供出色的(bit rate)图像质量(image quality),这意味着流媒体服务器的压力较小。
它也受到高度支持,并且可能会成为未来很长一段时间内最流行的编解码器。Apple、YouTube、HTML 5甚至Adobe Flash都支持它。
H.264唯一的缺点是它的压缩算法非常好,将视频编码成这种格式要慢得多。当我们在下面讨论转码时,您会发现更多相关信息。
正如我上面提到的,一个编解码器有多个编码器。对于H.264 编解码器(H.264 codec),最流行的编码器之一是来自VideoLAN的 x264,即创建(VideoLAN)VLC 媒体播放器(VLC Media Player)的同一人。x264 是免费和开源的,但也有许多商业H.264编码器。不管视频流(video stream)如何转换成这种格式,任何H.264 解码器(H.264 decoder)(如VLC)都可以查看文件。
MPEG-2 – 仍有大量DVD 收藏(DVD collection)?这一切都是使用MPEG-2 编解码器(MPEG-2 codec)完成的。它很古老,但很常见。您发现MPEG-2 压缩(MPEG-2 compression)的另一个地方是当您观看那些通过无线方式播放的高清频道时。这就是MPEG-2 压缩(MPEG-2 compression)。有趣的事情要知道,对吧?
由于使用MPEG-2的压缩算法远不如H.264,因此它具有编码速度更快的优势。但是,它从未适用于网络流媒体(web streaming),因为在较低的比特率下,质量会迅速下降,你最终会得到像素化的视频。这就是他们提出MPEG-4 Part 2的原因。
MPEG-4 第 2 部分(MPEG-4 Part 2)– 您可能还记得所有谈论DivX 和 Xvid(DivX and Xvid)的日子吧?这些是MPEG-4 Part 2格式的编码器,也就是H.263。您当时下载的许多电影都使用此编解码器进行了压缩,因为它为您提供了良好的文件大小(file size)并保持了合理的质量。然而,唯一的主要问题是高清内容在(high-definition content)图像质量(image quality)方面仍然受到影响,这就是我上面提到的H.264接管的地方。
Windows Media Video – 这基本上是Microsoft的MPEG-4 编解码器(MPEG-4 codecs)版本。WMV 7 于 1999 年推出,是MPEG-4 Part 2的副本。后来,出现了WMV 8和 9,然后是VC-1,这是一种主要复制MPEG-4 Part 10的编解码器,目前也用于蓝光光盘(Blu-ray discs)。您看到 WMV 和VC-1的唯一其他地方主要是在Microsoft相关产品中,例如Windows Movie Maker、Silverlight、HD DVD 和 Microsoft Expression Encoder(HD DVD and Microsoft Expression Encoder)等。
这些只是流行的视频编解码器(video codecs),你也有你的音频编解码器,当我们在下面讨论容器时,它们就会发挥作用。流行的音频编解码器包括FLAC、AC3、Dolby Digital Plus、DTS-HD、ALAC等。与视频一样,音频编解码器也有自己的容器格式,如AIFF、WAV等。
这些绝不是所有的编解码器,它只是一些最受欢迎的编解码器的列表。现在让我们谈谈容器格式。
容器格式
当您在Windows Media Player 或 VLC(Windows Media Player or VLC)或Quicktime或您选择的任何媒体播放器中播放文件时,您通常会打开一个容器格式(container format)。容器格式或包装器(container format or wrapper)基本上是一个或多个编解码器、视频或音频(video or audio)或两者的包。容器用于添加音频和视频,并确保音频和视频(audio and video)完美同步。该容器还将包含流媒体服务器(streaming server)或媒体播放器所需的其他信息。视频和音频比特流只是包装在另一个比特流中。
容器(Container)格式是您看到我们都使用的常见文件扩展名的地方,例如MP4、MOV、WMV、AVI等。让我们来看看一些最常见的容器:
MP4 – 您可能下载了一首带有 .MP4 扩展名的歌曲,它是许多视频和音频编解码器的包装。最常见的是,它用于包装H.264 视频和 AAC(H.264 video and AAC)编码的音频。它还支持MPEG-4 Part 2和MPEG-2 视频(MPEG-2 video)编解码器。此外,可以使用AAC(AAC)以外的其他编解码器对音频进行编码。
AVI – 这是 1992 年的Microsoft 容器(Microsoft container)格式。它在我那个时代非常流行,现在仍然很流行。如果您进行任何编码,则不应再使用AVI 容器(AVI container)格式。首先,它不支持像H.264这样的新编解码器。它还有一些其他主要问题,这就是它不再使用的原因。
ASF – Microsoft(Microsoft don)的高级(Advanced) 系统(Systems) 格式(Format)通常不使用.ASF 文件扩展名(.ASF file extension)。相反,您会看到大多数ASF容器使用 .WMA 或 .WMV。如果您使用所有Microsoft产品,您会看到这些文件。离开Microsoft 世界(Microsoft world)后,播放文件时会遇到问题,尤其是在使用H.264 编解码器(H.264 codec)时。
AVCHD – AVCHD是高清摄像机最常见的容器格式(container format)。视频通常是带有AC3(杜比数字(Dolby Digital))音频或线性PCM的(PCM)H.264。
MKV –最近下载(Download)电影?它可能是MKV 容器(MKV container)格式,其中包含H.264 视频(H.264 video)文件。相当多的工具支持MKV ,如Boxee、PS3 Media Server、XMBC、VLC等,但它还没有像其他容器格式那样被广泛支持。
FLV – 这是Adobe Flash,它支持许多不同的编解码器,最常见的是H.264 和 AAC(H.264 and AAC)。Flash 视频(Flash video)是通过Internet流式传输视频的最流行方式之一。由于HTML 5以及(HTML 5)Apple不会让 flash(let flash)在它的任何 iDevice 上运行这一事实,它正在失去阵地(losing ground),但它仍然很常见。
还有其他容器格式,例如QuickTime File Format、OGG、WebM等,但您现在可以了解情况了。
转码
关于这一切的最后一件事是,您可能必须将从摄像机下载的AVCHD 视频(AVCHD video)转换为不同的格式,然后您可以将其导入 iTunes 并在 iPhone 上播放。由于有如此多的编解码器和容器格式(codecs and container formats),并且每种容器格式(container format)可以具有不同的视频和音频编解码器组合,因此您需要一个转码器来为您的特定设备获取所需的文件类型。
有许多转码器,也就是视频转换器:HandBrake、FFmpeg、SUPER、VirtualDub等。有些是付费的,有些是免费的开源工具。一些工具,如HandBrake,为您提供预设,因此您只需选择源文件(source file)并选择iPod 或 iPhone(iPod or iPhone)等输出格式(output format),然后单击Start。它会为您选择所有设置、容器、编解码器等。但是,希望在阅读完这篇文章后,您现在可以了解更多一点,并且可以在格式之间转换视频并更好地了解底层过程。享受!
OTT Guide to Codecs, Container Formats and Transcoding
If the title of thiѕ article doеsn’t already makе your head hurt, thеn the rest of it definitely will. Well, hoрefully I can explain it in a way that makes sense to the non-technical person. I am writing this article аbout video/audio codecs becauseI found myself confused when trying to explаin it to a friend one day.
What exactly is a codec? I know you need them to play a movie here and there, but what the heck is it really? What really confused me were all the terms I’ve heard of, but never really understood: H.264, DivX, MP4, AVI, MPEG-2, AVCHD, AAC, OGG, MKV, etc, etc. Were these all codecs? After much reading and learning, I realized that the world of audio and video codecs and container formats is very confusing. Actually, I really didn’t even know the difference between a codec and a container format until I started researching.
I won’t be going into much detail, just because the topic starts to become very terse very fast. Do you really care if 1 hour of RAW uncompressed 1080p 60 frames per second video eats up almost 500 GB of storage space? Probably not.
What is a Codec?
So what exactly is a codec and what does it do? In the most simple terms possible, a codec is an encoder/decoder or, in it’s original form, a compressor (co) – decompressor (dec). So that is exactly what a codec does: it takes a digital file and compresses it (or encodes it) for storage and decompresses it (or decodes it) for viewing or transcoding. I’ll tell you what transcoding is a little bit later on, let’s not confuse ourselves this early on.
The important thing to understand is that a codec is kind of like a specification of how the bitstream should look. What is a bitstream? To not get very technical, it’s how the sequence of bytes should be arranged for that particular codec. Each codec has a specific set of guidelines. For example, it can specify the width, height, aspect ratio, etc. Check out this page, but don’t read too much or your head will hurt:
http://www.cs.cf.ac.uk/Dave/Multimedia/node262.html
Because it’s a specification, there can me many ways to convert data into that format. Hence, there can be many encoders for one codec. I’ll explain more about encoders in the Popular Codecs section below.
So why do we even need all this compression and decompression? Well like I mentioned above, a RAW uncompressed 1080p file is almost a whopping 500GB for just one hour. You would need your own data center to store all your family videos if everything was recorded in that format. That’s where compressions comes into play. There are different types of compression, which translates into different types of codecs. So what are some popular codecs?
Popular Codecs
H.264 (MPEG-4 Part 10 AVC) – This is also officially known as MPEG-4 Part 10, but H.264 is what you commonly hear. Yes, there are also multiple names for the same thing. H.264 is by far the most popular format for encoding videos. H.264 offers the best of all worlds: smaller file sizes with higher quality.
Again, remember, H.264 is just the codec, you won’t find any files with .h264 extensions. That’s what container formats are for, which I’ll explain in the section below. This codec is used all over the place from smartphones to digital camcorders to Blu-ray discs. It’s also used for delivering a lot of web video today because of it’s ability to give you great image quality with a high compression ratio and a low bit rate, meaning less strain on streaming servers.
It’s also highly supported and probably will be the most popular codec for a long time to come. It’s supported by Apple, YouTube, HTML 5, and even in Adobe Flash.
The only downside to H.264 is that it’s algorithms for compression are so good, it’s a lot slower to encode a video into this format. You’ll find out more about that when we talk about transcoding down below.
As I had mentioned above, there are multiple encoders for a single codec. For the H.264 codec, one of the most popular encoders is x264 from VideoLAN, the same people who create VLC Media Player. x264 is free and open-source, but there are many commercial H.264 encoders also. It doesn’t matter how the video stream gets converted into this format, any H.264 decoder (like VLC) will be able to view the file.
MPEG-2 – Still have a large DVD collection? That’s all done using the MPEG-2 codec. It’s pretty old, but very common. The other place where you find MPEG-2 compression is when you watch those HD channels broadcast over-the-air. That’s all MPEG-2 compression. Interesting stuff to know, right?
Since the algorithm for compression using MPEG-2 is vastly inferior to H.264, it’s got the advantage of being a lot faster to encode. However, it never worked for web streaming because at a lower bitrate, the quality would quickly nosedive and you’d end up with pixelated video. That’s why they came up with MPEG-4 Part 2.
MPEG-4 Part 2 – You probably remember the days when everything talked about DivX and Xvid right? Those were encoders for the MPEG-4 Part 2 format, aka H.263. A lot of movies that you downloaded back in the day were compressed using this codec because it gave you a good file size and maintained reasonable quality. However, the only major problem is that high-definition content still suffered in terms of image quality and that’s where H.264 that I mentioned above took over.
Windows Media Video – This is basically Microsoft’s version of the MPEG-4 codecs. WMV 7 was introduced in 1999 and was a copy of MPEG-4 Part 2. Later on, WMV 8 and 9 came, followed by VC-1, a codec that mostly copies MPEG-4 Part 10 and is currently used in Blu-ray discs too. The only other places you see WMV and VC-1 are mostly in Microsoft related products like Windows Movie Maker, Silverlight, HD DVD and Microsoft Expression Encoder, etc.
These are just the popular video codecs, you also have your audio codecs, which come into play when we talk about containers below. Popular audio codecs include FLAC, AC3, Dolby Digital Plus, DTS-HD, ALAC, etc. As with video, audio codecs have their own container formats like AIFF, WAV, etc.
These are not by any means all the codecs out there, it’s just a list of some of the most popular ones. Now let’s talk about container formats.
Container Formats
When you play a file in Windows Media Player or VLC or Quicktime or whatever your media player of choice, you’re usually opening a container format. A container format or wrapper is basically package of one or more codecs, video or audio or both. A container is used to add audio along with video and to make sure the audio and video are synchronized perfectly. The container will also contain other information needed by a streaming server or by the media player. The video and audio bitstreams are just wrapped in another bitstream.
Container formats are where you see the common file extensions we are all used too like MP4, MOV, WMV, AVI, etc. Let’s go through some of the most common containers:
MP4 – You’ve probably downloaded a song that had an .MP4 extension, which is a wrapper for an many video and audio codecs. Most commonly, it’s used to wrap H.264 video and AAC encoded audio. It also supports MPEG-4 Part 2 and MPEG-2 video codecs also. Also, audio can be encoded using other codecs other than AAC.
AVI – This is a Microsoft container format from 1992. It was very popular back in my day and it’s still around quite a bit. If you do any encoding, you should never use the AVI container format anymore. Firstly, it doesn’t support newer codecs like H.264. It also has a few other major problems which is why it’s not used anymore.
ASF – The Advanced Systems Format by Microsoft don’t normally use the .ASF file extension. Instead you’ll see most ASF containers use .WMA or .WMV. You’ll see these files around if you’re using all Microsoft products. Once you leave the Microsoft world, you’ll run into issues playing back the files, especially if you use the H.264 codec.
AVCHD – AVCHD is the most common container format for HD camcorders. The video is normally going to be H.264 with AC3 (Dolby Digital) audio or Linear PCM.
MKV – Download a movie lately? It’s probably in the MKV container format, which houses H.264 video files. Quite a few tools support MKV like Boxee, PS3 Media Server, XMBC, VLC, etc, but it’s not as widely supported as other container formats just yet.
FLV – This is Adobe Flash, which supports many different codecs, most common being H.264 and AAC. Flash video is one of the most popular ways videos are streamed over the Internet. It’s losing ground because of HTML 5 and the fact that Apple won’t let flash run on any of it’s iDevice’s, but it’s still very common.
There are other container formats like the QuickTime File Format, OGG, WebM, etc, but you kind of get the picture now.
Transcoding
The last thing to understand about all this is that you probably will have to convert that AVCHD video you downloaded from your camcorder to a different format that you can then import into iTunes and play on your iPhone. Since there are so many codecs and container formats and each container format can have different combinations of video and audio codecs, you need a transcoder to get you the type of file you want for your particular device.
There are many transcoders aka video converters out there: HandBrake, FFmpeg, SUPER, VirtualDub, etc. Some are paid and some are free open-source tools. Some tools, like HandBrake, give you presets so you can simply choose your source file and pick an output format like iPod or iPhone and click Start. It’ll choose all the settings, container, codec, etc for you. However, hopefully after reading this post, you now understand a little bit more and can go about converting videos between formats and understand the underlying process a little better. Enjoy!