What Is a Codec? Audio and Video Codecs Explained
Every voice and video call depends on a codec to squeeze media small enough to send. Here is what codecs do, which ones calls use, and how browsers agree on one.
Codec vs container
|
Codec |
Container (file format) | |
|---|---|---|
|
What it is |
The method that compresses and decompresses media |
The wrapper that holds encoded streams and metadata |
|
Examples |
Opus, G.711, H.264, VP8, VP9, AV1 |
MP4, WebM, MKV, Ogg |
|
Decides |
Quality per bit and CPU cost |
Which streams, subtitles and timing info travel together |
|
Used in live calls |
Yes, on every audio and video stream |
No; RTP carries encoded frames directly |
|
Used in recordings |
Yes |
Yes; a recording is codec output inside a container |
|
Playback failure means |
The device can't decode that codec |
The player can't read that file format |
What is a codec?
The word is short for coder-decoder. The coder (encoder) turns raw audio samples or video frames into a compact bitstream. The decoder turns that bitstream back into something a speaker or screen can play.
Raw media is huge. One second of 720p video at 30 frames per second, stored in the common 4:2:0 format, is 1280 x 720 pixels x 1.5 bytes x 30 frames, or about 330 megabits. A video call sends the same second in 1.5 to 3 megabits. The codec closes that gap by dropping detail people barely notice and sending only what changed between frames.
Call codecs are lossy: the decoded output is close to the original, not identical.
How a codec works in a call
1. Capture
The microphone produces audio samples and the camera produces frames, often 30 per second.
2. Encode
An audio codec models the human voice and drops sounds you wouldn't hear. A video codec predicts most of each frame from the previous one and sends the difference, plus occasional full keyframes.
3. Packetize and send
The encoded data is split into RTP packets and sent, usually over UDP.
4. Decode and play
The receiver buffers a few packets to absorb jitter, decodes them and plays the result. If a packet is lost, the decoder hides the gap or asks for a new keyframe.
5. Negotiate first
Both sides must support the same codec. In WebRTC, each side lists its codecs in an SDP offer and answer, and they settle on a shared one before any media flows.
Audio and video codecs used in calling
Audio codecs
Opus: the default for WebRTC and most modern calling apps. It runs from 6 kbps to 510 kbps, handles speech and music, and copes well with packet loss.
G.711: the classic telephone codec at 64 kbps with narrowband 8 kHz audio. It's still mandatory in WebRTC because it makes bridging to phone networks easy.
G.722: a wideband codec common in desk phones and SIP systems.
Video codecs
H.264 (AVC): the most widely supported video codec, with hardware encoders and decoders in most phones and laptops. Commercial use is covered by patent licensing.
VP8: Google's royalty-free codec, mandatory in WebRTC alongside H.264, with similar quality per bit.
VP9: VP8's successor, with better compression and support for scalable video coding.
AV1: the royalty-free codec from the Alliance for Open Media, with the best compression of the group and the highest encoding cost.
For a deeper comparison of the video options, see H.264 vs VP8 vs AV1.
Safe default: Opus for audio and H.264 or VP8 for video. Every WebRTC browser must support them, so calls connect everywhere.
Example: list the codecs a browser supports
Before you tune anything, check what the browser can actually send. This runs in any modern browser console.
// Codecs this browser can send in a WebRTC call
const audio = RTCRtpSender.getCapabilities('audio').codecs;
const video = RTCRtpSender.getCapabilities('video').codecs;
const unique = list => [...new Set(list.map(c => c.mimeType))];
console.log(unique(audio)); // e.g. audio/opus, audio/PCMU, audio/PCMA ...
console.log(unique(video)); // e.g. video/VP8, video/H264, video/AV1 ...
Entries such as video/rtx and video/red are retransmission and redundancy formats, not codecs.
Where codec choice matters
In-app voice and video calls: Opus for audio plus H.264 or VP8 for video works on almost every device.
Group calls: a media server forwards streams as they are, so every participant must decode the sender's codec.
Calling a phone number: gateways to the phone network often use G.711, so a call may be transcoded at the edge.
Recordings and playback: recordings are stored as codec output in a container such as MP4 or WebM, so the codec decides which players can open the file.
Limits and pitfalls
Mismatched support: if two devices share no video codec, the call falls back to audio or fails. Always offer at least one mandatory WebRTC codec.
CPU and battery cost: software encoding of newer codecs can heat up phones. Hardware support matters as much as compression.
Transcoding adds delay: converting between codecs on a server costs latency and quality.
Licensing: H.264 is covered by a patent pool. Check whether your use needs a license; VP8, VP9 and AV1 are royalty-free.
Codec isn't the whole story: packet loss, jitter and a bad bitrate target hurt quality more than the choice between two modern codecs.
Codecs in CometChat calls
If you add calling with CometChat, codec negotiation is handled for you, so you can spend your time on the call experience.
WebRTC calling with codec selection built in
The CometChat Calls SDK is built on WebRTC. Its docs say voice calls use automatic codec selection with Opus preferred, and video calls support VP8, VP9 and H.264, with the SDK picking the best codec for each browser or device and negotiating resolution and frame rate. Media is encrypted with SRTP. SDKs cover web, iOS, Android, React Native and Flutter.
Frequently asked questions
What is a codec in simple terms?
It's the method a device uses to shrink audio or video before sending or saving it, and to expand it again for playback. The name comes from coder-decoder.
What codec does WebRTC use?
Browsers must support Opus and G.711 for audio and VP8 and H.264 for video. Most calls end up on Opus plus VP8 or H.264. Many browsers also offer VP9 and AV1.
Is MP4 a codec?
No. MP4 is a container that holds encoded streams. The video inside an MP4 file is usually H.264, H.265 or AV1, and the audio is often AAC.
Which codec gives the best call quality?
For audio, Opus. For video, AV1 gives the best quality per bit, but it costs more CPU and isn't supported everywhere. H.264 and VP8 are the safest choices for reach.
Why does a video say codec not supported?
The device has no decoder for the codec inside the file. Re-encode it to a widely supported codec such as H.264.