H.264 codec for video streaming

Anuradha Lohar
5 min readJan 4, 2022

--

What is H.264?

H.264 is a video compression standard for recording, compressing, and distributing video content online. Dubbed as the most widely utilized codec in the world, and also known as Advanced Video Coding. Advanced Video Coding, is a video compression standard based on block-oriented, motion-compensated integer-DCT coding

This codec offers great video streaming quality for substantially lower video bitrates than other previous standards, such as MPEG-2, H.263, or MPEG-4 Part 2, without making things so complex that its utilization would be too expensive or impractical to implement widely.

In short, H.264 has allowed video producers and viewers greater, easier access to better-quality streaming video on a broader variety of streaming platforms.

What is a Video Codec?

Video codecs are essential to web streaming.

Raw video is composed of a series of still images played one after another. However, at thirty frames per second, the amount of storage space necessary for digital video grows very quickly.

Codecs, which is short for “coder-decoder,” were created as a solution to this problem. At their core, a codec is a video compression method. They “throw out” certain data to make video files smaller in size, while trying to retain as much quality as possible.

Modern video codecs use many different mathematical methods to reduce file size. These methods include detecting when certain areas of the video don’t change from frame to frame, allowing you to toss out certain data.

Other methods look at movement and use mathematical prediction to reduce the need to store every pixel. Some of these methods are called chroma subsampling, quantization, and spatial/temporal down sampling.

There are different types of codecs available for broadcasting, and as related broadcasting technology evolves, codecs follow suit.

What is the Best Video Codec for Streaming?

At this point, H.264 is the best video codec for web streaming. The main reason that H.246 is considered the best code by many is because it hits the sweet spot between efficiency and compatibility.

While there are more efficient codecs on the market, none of them are quite as compatible as H.264.

H.264: An Overview

H.264 is a powerful video codec

H.264 was originally developed in the early-2000s and has been updated continuously. It has been the de-facto standard for internet video delivery for quite some time. This continues today.

Any device built in the last decade probably supports H.264 advanced video coding to some degree. This is the critical feature of H.264 since it means that any video encoded and distributed with H.264 can be watched on most devices. This includes laptops, desktops, smartphones, tablets, smart TVs, gaming consoles, and more.

Another benefit of H.264 is the relatively small file size. Compared to the previous generation of video codecs, such as H.263 and MPEG-2, file sizes are about 50% smaller. This helps users to conserve storage and bandwidth.

H.264 Encoder Profiles

The H.264 codec has gone through a number of iterations and updates. It’s not a monolithic standard. In fact, H.264 could best be understood as a “family” of related standards. These are captured in the H.264 “profiles” that are available in any encoder.

There are at least 20 profiles available for H.264. However, most of those are very specialized. Most encoding software only uses a small number of these profiles.

These more commonly-used H.264 encoder profiles are baseline, main, and high.

1. Baseline Encoder Profile

The baseline profile uses only the older, most widely-supported compression features of H.264. This means that video compressed using the H.264 codec, the baseline profile will be compatible with almost all devices. This includes older and low-power devices.

2. Main Encoder Profile

The main profile applies some additional encoding features of the H.264 family. This requires more processing power and memory on the decoding side. Older or low-powered devices (such as tablets or smartphones made more than 5–8 years ago) may not be able to decode videos streamed with this profile. However, file sizes are smaller.

3. High Encoder Profile

The high profile is the most modern implementation of H.264. It includes more encoding features that enable smaller file sizes. However, this requires more processing power and memory from the viewer’s devices.

Today, device power has become less of an issue. The high profile is supported on all modern smartphones, tablets, computers, set-top boxes, gaming consoles, and so on. However, using a high profile may prevent users with very old devices from accessing content.

Which H.264 Encoder Profile to Use

In short: use the baseline profile if you’re targeting users on very old, underpowered devices. If your viewers tend to use modern devices, the high or main profile should be fine to use.

Other H.264 Settings

Any video stream or file can be encoded using a wide variety of live video format options. Here are some of the H.264 encoder settings that need to be set when streaming to an HTML5 video player.

Resolution

Video resolution refers to the size of the video, measured in pixels. A standard high-definition video frame, for example, is 1920 pixels wide and 1080 pixels in height.

Frame Rate

Video is made up of a series of still images. The frame-rate is simply the number of pictures per second of video. Thirty frames-per-second (fps) is the most common setting.

Bitrate

Video bitrate refers to the amount of data being included in a video, measured in kilobytes or megabytes per second. For example, a video may be encoded at 500 kbps, or at 1000 kbps (equivalent to 1 Mbps). Bitrate has a direct relationship to quality. All else being equal, a higher bitrate video will be higher in quality than a lower bitrate video.

Audio Codec

Another setting for any video is the audio codec being used. As we covered, H.264 is the most common video codec, but AAC is the best audio codec. If in doubt, use AAC. MP3 is another common audio codec.

Audio Bitrate

Like video bitrate, audio bitrate influences quality. Generally, audio bitrates are kept between 32 kbps and 128 kbps. Thirty-two is appropriate for voice-only videos. For music or higher-quality content, 128 kbps is recommended.

Keyframes

We recommend setting the keyframe interval to 2 seconds.

Conclusion

H.264 advanced video coding helps you present your video files in the right format for your viewers, giving them an overall positive viewing experience.

--

--