Streaming, Gaming & Smart Devices

Video Codecs: H.264, HEVC, VP9 and AV1

Compare the four main video codecs on compression, device support and licensing, and learn which to pick when you encode.

Key takeaways

  • Newer codecs generally deliver the same visual quality at a lower bitrate, in exchange for more computing effort.
  • A hardware decoder in your device matters a great deal for battery life and smooth playback.
  • A codec is different from a container: an MP4 file can hold video compressed with several different codecs.
  • H.264 remains the safest compatibility choice, while streaming services often serve newer codecs to devices that support them.

A video codec is the method used to compress video for storage or transmission and to turn it back into pictures. H.264 plays on nearly everything. HEVC (H.265) and VP9 produce similar quality with noticeably less data. AV1 is newer and more efficient still, but takes more work to encode and needs a fairly recent device to play comfortably.

If you're exporting a video and just want it to work everywhere, choose H.264. The others pay off when bandwidth or storage is the constraint and you know your audience's devices can decode them.

What a codec actually does

Uncompressed video is enormous. A single 1920 x 1080 frame has about two million pixels, and a second of video has dozens of frames. Codecs shrink this by hundreds of times using a few core ideas.

Spatial prediction guesses one part of a frame from neighboring parts, such as a patch of sky from the sky beside it. Temporal prediction guesses a frame from earlier or later frames, storing how blocks of pixels moved. Transforms and quantization turn what's left into a form where fine detail the eye barely notices can be stored coarsely or dropped. Entropy coding then packs the result as tightly as possible.

Frames that are stored complete are called keyframes or I-frames. Frames stored mostly as differences are P-frames and B-frames. Keyframes are large, but a player needs one to start or to jump to a new point.

Each generation of codecs adds more flexible block sizes, better motion prediction and smarter filters. The encoder gets more options to search through, which is why better compression costs more computing time.

The four codecs

H.264, also called AVC (Advanced Video Coding), was standardized jointly by ITU-T and ISO/IEC in 2003. It's supported by practically every phone, browser, TV, camera and editing program in use.

HEVC, or H.265 (High Efficiency Video Coding), followed in 2013 from the same standards bodies. It's widely used for 4K and HDR video, and many phones record in it. Browser support is less uniform than for H.264 and often depends on hardware.

VP9 is a codec developed by Google and offered royalty-free. It's used heavily for web video and supported by major browsers and many TVs.

AV1 was released in 2018 by the Alliance for Open Media, a group that includes browser, chip and streaming companies. It was designed to be royalty-free and to improve substantially on VP9 and HEVC.

Four codecs at a glance
H.264 / AVC Plays almost everywhere Fast to encode Needs the most bits of the four HEVC / H.265 Common for 4K and HDR Phones often record in it Patent licensing is complex VP9 Royalty-free design Strong in web video Hardware decode is widespread on newer gear AV1 Royalty-free design Most efficient of the four Encoding is demanding without dedicated hardware H.264 / AVC Plays almost everywhere Fast to encode Needs the most bits of the four HEVC / H.265 Common for 4K and HDR Phones often record in it Patent licensing is complex VP9 Royalty-free design Strong in web video Hardware decode is widespread on newer gear AV1 Royalty-free design Most efficient of the four Encoding is demanding without dedicated hardware

How much smaller, really

The usual rule of thumb is that HEVC and VP9 can match H.264 quality using somewhere around 25 to 50 percent less data, and that AV1 improves on HEVC and VP9 by a further meaningful step. Treat those as rough ranges. Results depend heavily on the content, the encoder software, its settings, the resolution and how quality is measured.

A well-tuned H.264 encode can beat a hasty encode in a newer format. And at very high bitrates, where all four look nearly identical to the original, the savings matter less than at low bitrates, where the differences are easy to see.

Codec, container and file extension

People often say "an MP4" as if it were a codec. MP4 is a container: a wrapper that holds a video track, audio tracks, timing information and sometimes subtitles. The video inside might be H.264, HEVC or AV1. MKV and WebM are containers too. WebM is typically used with VP8, VP9 or AV1 video and Vorbis or Opus audio.

This explains a common puzzle: two files both ending in .mp4, one of which plays and one of which shows a black screen. The device understands the container but lacks a decoder for what's inside.

What sits inside a video file
.mp4 1 HEVC 2 AAC 3 1920x1080 4 6 Mbps 5 Container The wrapper that organizes tracks and timing. 1 Video codec How the pictures are compressed. 2 Audio codec How the sound is compressed. 3 Resolution The pixel dimensions of each frame. 4 Bitrate Data used per second of playback. 5 .mp4 1 HEVC 2 AAC 3 1920x1080 4 6 Mbps 5 Container The wrapper that organizes tracks and timing. 1 Video codec How the pictures are compressed. 2 Audio codec How the sound is compressed. 3 Resolution The pixel dimensions of each frame. 4 Bitrate Data used per second of playback. 5

You can inspect a file yourself with FFmpeg's companion tool, if you have it installed. The command works the same on Windows, macOS and Linux.

ffprobe -v error -show_entries stream=codec_name,codec_type,width,height input.mp4

For a quick check of whether a file's contents match its extension, the file type checker can help.

Hardware decoding and why it matters

Most phones, TVs and computers contain dedicated circuits that decode particular codecs. Hardware decoding uses little power and handles high resolutions easily.

Without it, the main processor does the work in software. Software decoding can be perfectly fine for a 1080p video on a strong laptop and miserable for a 4K one on a cheap streaming stick: dropped frames, a hot device and a draining battery.

Support depends on the specific chip, so two devices sold in the same year can differ. If AV1 or HEVC playback matters to you, check the manufacturer's specifications for the exact model. Some browsers also offer a hardware acceleration switch in settings, which is worth checking when video won't play properly in the browser.

Licensing, briefly

Codecs are covered by patents. H.264 and HEVC are licensed through patent pools and individual holders, and the HEVC arrangement is widely considered the more fragmented one. That uncertainty is one reason support for HEVC spread unevenly.

VP9 and AV1 were designed with royalty-free licensing in mind. Some patent holders have nonetheless asserted that their patents apply to these formats, and positions have continued to develop. If you're building a product that ships an encoder or decoder, this is a question for a lawyer. For personal videos and ordinary viewing, device makers and software vendors handle it.

Which should you use?

For sharing a clip with family or colleagues, use H.264 in an MP4 container with AAC audio. It opens almost anywhere without explanation.

For storing a large personal library on devices you control, HEVC or AV1 can save considerable space, provided every playback device handles the choice.

For uploading to a video platform, export at high quality in whatever the platform recommends. The platform will re-encode your upload into its own ladder anyway, so starting with a clean source matters more than starting with a modern codec.

For publishing video on your own website, offering a modern codec with an H.264 fallback gives most visitors a smaller download and nobody a blank box. HTML supports this by listing several sources, and the browser takes the first it can play.

Re-encoding an already compressed file loses a little quality each time. Convert from the original when you can, and avoid chains of conversions.

Encoder settings that matter as much as the codec

Choosing a codec is one decision. How you run the encoder is another, and it often has the bigger effect on the result.

Rate control decides how bits are spent. A constant-quality mode (called CRF in several popular encoders) aims for a steady look and lets file size vary. A target-bitrate mode aims for a predictable size or stream rate, which matters for broadcasting.

Speed presets trade encoding time for efficiency. A slower preset searches harder and produces a smaller file at similar quality. For a one-time archive it's worth waiting; for a live stream you must keep up with real time.

Hardware encoders built into graphics chips and phones are very fast and easy on the processor. At the same bitrate, they have traditionally trailed careful software encoding, though the gap has narrowed with newer generations.

Here's an example with FFmpeg that creates a widely compatible H.264 file with AAC audio. A lower CRF number means higher quality and a bigger file.

ffmpeg -i input.mov -c:v libx264 -preset medium -crf 22 -pix_fmt yuv420p -c:a aac -b:a 160k output.mp4

The -pix_fmt yuv420p option picks the color layout that the widest range of players expects.

What comes next

Standards bodies have continued working. VVC (H.266), finalized in 2020, targets another large efficiency gain, and successors to AV1 have been in development. History suggests a long gap between a codec being published and it being common in living rooms, because chips have to ship and old devices have to retire.

That's why streaming services keep several encodes of popular titles and pick one per device, an extension of the same adaptive bitrate system that changes your quality mid-show. For audio, which follows its own set of formats, see audio codecs and streaming quality.

Common questions

Does a newer codec make my video look better?

It lets you get the same look from fewer bits, or a better look from the same bits. Converting an existing low-quality file into AV1 won't restore detail that's already gone.

Why did my phone's videos refuse to open on an older computer?

The phone probably recorded in HEVC. Many phones offer a setting that records in a more compatible format, or can convert when you export. Menu names vary by model and version.

Does the codec affect how much mobile data I use?

Yes, when the service takes advantage of it. At a given quality level, a more efficient codec means fewer bytes, which also helps on slow connections.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Streaming, Gaming & Smart Devices →

Latest news on this topic