编解码器(codec)指的是一个能够对一个信号或者一个数据流进行变换的设备或者程序。这里指的变换既包括将信号或者数据流进行编码(通常是为了传输、存储或者加密)或者提取得到一个编码流的操作,也包括为了观察或者处理从这个编码流中恢复适合观察或操作的形式的操作。编解码器经常用在视频会议和流媒体等应用中。
经过编码的音频或者视频原始码流经常被叫做“Essence”(有译作“本体”,“精”),以区别于之后加入码流的元信息和其它用以帮助访问码流和增强码流鲁棒性的数据。
大多数编解码器是有损的,目的是为了得到更大的压缩比和更小的文件大小。当然也有无损的编解码器, 但是通常没有必要为了一些几乎注意不到的的质量损失而大大增加编码后文件的大小。除非该编码的结果还将在以后进行下一步的处理,此时连续的有损编码通常会带来较大的质量损失。
很多多媒体数据流需要同时包含音频数据和视频数据,这时通常会加入一些用于音频和视频数据同步的元数据。这三种数据流可能会被不同的程序,进程或者硬件处理,但是当它们传输或者存储的时候,这三种数据通常是被封装在一起的。通常这种封装是通过视频文件格式来实现的,例如常见的*.mpg, *.avi, *.mov, *.mp4, *.rm, *.ogg or *.tta. 这些格式中有些只能使用某些编解码器,而更多可以以容器的方式使用各种编解码器。
编解码器对应的英文“codec”(coder和decoder簡化而成的合成詞語)和decode通常指软件,当特指硬件的时候,通常使用“endec”这个单词。
Description
[edit] Related concepts
An endec is a similar (but different) concept for hardware. In the mid 20th century, a “codec” was hardware that coded analog signals into Pulse-code modulation (PCM) and decoded them back. Late in the century the name came to be applied to a class of software for converting among digital signal formats, and including compander functions.
Codecs (in the modern, software sense) encode a stream or signal for transmission, storage or encryption and decode it for viewing or editing. Codecs are often used in videoconferencing and streaming media applications. A video camera’s analog-to-digital converter (ADC) converts its analog signals into digital signals, which are then passed through a video compressor for digital transmission or storage. A receiving device then runs the signal through a video decompressor, then a digital-to-analog converter (DAC) for analog display. A “codec” is a generic name for a video conferencing unit.
An audio compressor converts analog audio signals into digital signals for transmission or storage. A receiving device then converts the digital signals back to analog using an audio decompressor, for playback.
The raw encoded form of audio and video data is often called essence, to distinguish it from the metadata information that together make up the information content of the stream and any “wrapper” data that is then added to aid access to or improve the robustness of the stream.
[edit] Compression quality
Most codecs are lossy. Originally this was in order to make the compressed files small enough to be readily transmitted across non-broadband networks and stored on relatively expensive media, such as non-volatile memory and hard disk as opposed to write-once read-many formats such as CD-ROM and DVD.
There are lossless codecs but for most purposes the slight increase in quality (some would say almost imperceptible increase) is not worth the increase in data size, which is often considerable. The main exception to this is if the data is to undergo further processing (for example editing) in which case the repeated application of lossy codecs (repeated encoding and subsequent decoding) will almost certainly degrade the quality of the edited file such that it is readily identifiable (visually or audibly or both). Using more than one codec or encoding scheme whilst creating a finished product can also degrade quality significantly (however there are many situations where this is all but unavoidable).
Many codecs are designed to emphasize certain aspects of the media to be encoded. For example, a digital video (using a DV codec) of a sports event, such as baseball or soccer, needs to encode motion well but not necessarily exact colors, while a video of an art exhibit needs to perform well encoding color and surface texture. There are hundreds or even thousands of codecs ranging from those downloadable for free to ones costing hundreds of dollars or more.
Many multimedia data streams need to contain both audio and video data, and often some form of metadata that permits synchronization of the audio and video. Each of these three streams may be handled by different programs, processes, or hardware; but for the multimedia data stream to be useful in stored or transmitted form, they must be encapsulated together in a container format.
While many people explain that AVI is a codec, they are incorrect. AVI (nowadays) is a container format, which many codecs might use (although not to ISO standard). There are other well known alternative containers such as Ogg, ASF, QuickTime, RealMedia, Matroska and MP4.