-->
Join us for Streaming Media Connect 2022, February 14th-18th. Reserve Your Free Seat Now!

How to Produce High-Quality H.264 Video Files

Article Featured Image

Fortunately, Compressor can access QuickTime plug-ins such as the x264Encoder plug-in that you can download at MyCometG3. Note that the developer of the site, Takashi Mochizuki, discontinued development on the plug-in at the end of 2011, so the code is frozen as of that date. That said, while there will continue to be quality and performance advances, the x264 codec at that time was highly optimized. As you can see in Figure 3, it delivers significantly better quality than the Apple codec.

Figure 3. Compressor’s native Apple codec is subpar at aggressive encoding parameters

For the record, unless otherwise stated, all comparison frames in this article were produced using my standard 720p test file, with the 29.97 fps video compressed to 800Kbps using the highest quality-related settings supported by each encoding tools, and consistent key frame, B-frame, reference frame, and similar parameters. These parameters are aggressive; by comparison, sites such as YouTube and ESPN produce their 720p, 29.97 fps video at 2.5Mbps or higher.

To be fair, if you’re producing your 720p files at 2.5Mbps or higher, you’d likely see very little difference between the Apple and x264 codecs. However, if you’re attempting to achieve the highest possible quality at the lowest possible data rate, the x264Encoder will perform much better. In particular, mobile encodes, which require a highly optimized stream to deliver the largest resolution at the lowest possible data rate, can significantly benefit from the x264 plugin. For those unfamiliar with the plug-in, note that OnlineVideo.net published an extensive tutorial on how to install and use the X264Encoder in an article titled, “Final Cut Pro X Tutorial: How to Get Better Encoding Results.”

Use the Best H.264 Codec

Many encoding tools, such as Sorenson Squeeze in Figure 4, offer multiple H.264 codecs, including the MainConcept codec, x264 and multiple hardware-accelerated codecs such as the MainConcept CUDA codec or Intel Quick Sync Video (QSV) H.264 codecs. Which are best here?

Figure 4. Which is the best option here?

First, you should never use the MPEG-4 codec unless you’re attempting to create files specifically for older mobile phones and similar devices. For general-purpose use, H.264 always delivers higher quality at the same or lower data rates.

As between the MainConcept and x264, Moscow State University issues an annual H.264 comparison that is both extensive and highly regarded. Over the last few years, x264 has proved the highest-quality option, with MainConcept in second, typically about 20% behind x264. To explain, the researchers reported that for their test clips, using the x264 codec, you could produce a file at a 20% lower data rate than MainConcept with equivalent quality.

Interestingly, Moscow State University relies solely on mathematical quality comparisons, specifically the Peak Signal-to-Noise Ratio (PSNR) and Structural Similarity Index (SSIM) metrics. Uniquely, the x264 codec offers tuning options (more later) that produce streams optimized for these tests, which apparently Moscow State University used when producing its x264 files. This potential advantage led the researchers to include this statement in their overall conclusion: “The leader in this comparison is x264 -- its quality difference (according to the SSIM metric) could be explained by the special encoding option (‘tune-SSIM’).”

That red herring aside, my own tests, which are entirely based upon subjective frame and playback comparisons, indicate that x264 produces higher quality streams than MainConcept, though the advantage seems smaller than the Moscow State University report might imply. Specifically, in most of the seven sequences in my standard test clip, the quality of the two streams was very similar. Where there was a difference, however, x264 was always better, as shown in Figure 5, where the x264 frame clearly retains more detail in the circled area.

Figure 5. x264 delivered slightly higher quality than MainConcept.

However, the difference isn’t nearly as dramatic as the x264-Apple differential shown in Figure 1. For this reason, while I use x264 when available in an encoding tool, I wouldn’t switch encoding tools because only MainConcept, and not x264, was available.

In comparison, as shown in Figure 6, I never use hardware-accelerated H.264 codecs such as the Intel and MainConcept CUDA codecs, since they are clearly inferior to software-only encodes. As a confirmation of my subjective findings, Moscow State University rated the Intel codec 82% behind x264, with the MainConcept CUDA 170% behind.

Figure 6. Hardware accelerated codecs encode much faster but offer noticeably less quality.

Briefly, these hardware-accelerated codecs leverage the dedicated encoding cores on Intel CPUs (QSV) or the general processing power of NVIDIA GPUs (CUDA), and the design emphasis was on speed, not quality. If you need fast draft encodes, these codecs might provide some value. Otherwise, you should eschew them in favor of totally software-based H.264 codecs such as the x264 or MainConcept codecs.

What about other products that use proprietary H.264 codecs? For the most part, you’ll find these on some higher-end products such as the hardware and cloud encoders offered by Elemental Technologies. In my experience, vendors that use proprietary H.264 encoders have invested significant resources to come close to or match x264’s quality. For this reason, codec quality is seldom a significant differentiator when comparing these high-end tools.

Optimize Your x264 Encodes

One popular feature of the x264 codec is a plethora of configuration options, though with options such as “Quantizer curve compression factor” and “Use mixed refs per 8x8 partitions,” it’s likely that very few compressionists in the field can tie these options to any desired encoding outcome. Fortunately, most encoding tools that use the x264 codec let you select both a preset and the tuning mechanisms, with the typical options shown in Figure 7, a screen from the x264Encoder discussed previously. Briefly, presets, which were created by the x264 development team, adjust the individual x264 encoding parameters in ways that trade off quality versus encoding time. When it comes to choosing a preset, the obvious questions ask how much quality and how much encoding time.

Figure 7. x264 Preset and Tuning from the x264Encoder

Let’s address encoding time first. Table 3 shows the encoding times with Sorenson Squeeze when producing my 92-second test file to the data rates shown using the presets shown. I performed these tests on an HP Z820 with two 2.7 Ghz Intel Xeon E5-2697 v2 CPUs, each with 12 cores (24 with HTT enabled). So this is a very fast computer, and the x264 codec is very highly optimized for multiple core computers, using nearly 100% of available CPUs on all encodes. If you’re using a slower computer, times will obviously increase, as will the differences between the intervals.

Table 3. Encoding times using the x264 profiles at these target data rates 

From a strict performance perspective, there is little reason to choose a preset slower than Medium, which is generally the default setting, since the performance boosts at the faster settings aren’t that dramatic. How does the quality compare?

Well, in my comparisons, the only preset that showed obvious artifacts was the Ultra Fast preset, which showed blockiness at both data rates (Figure 8). At the other end of the spectrum, the differences between even the Placebo and Medium settings was very minor, and often the frames looked visually identical. In fact, there’s a surprising lack of differential between all encodes ranging from Super Fast to Placebo.

Figure 8. Files encoded using the various x264 presets 

If you run a quality-focused shop and aren’t limited by throughput on your encoding stations, you could use the Very slow preset to potentially increase quality, while only doubling encoding time. In contrast, the Placebo setting would have a much more dramatic impact on encoding time, and it’s unlikely to produce better quality than the Very Slow option.

At the other end of the spectrum, if you’re throughput-limited, you could try encoding using the Super Fast option and test to see if the files appear degraded compared to those encoded using the Medium option. However, don’t expect the time savings to be significant. If you are throughput-limited, it may be time to consider shopping for a new encoding station.

What about x264 tuning? For general-purpose footage, some pundits recommend using the Film option, though in my comparison tests using my standard test files, I’ve seen no difference. Otherwise, if you’re encoding specialized footage, try the specific tuning option, such as the Animation setting for animated footage, Touhou for this Japanese computer game, Still Image for slideshows, and Grain for footage with lots of graininess.

What if your encoding tool doesn’t use the x264 codec? Unfortunately, the codecs and configurations used by these tools vary so much that any kind of specific advice is impossible. Fortunately, most encoding tools include presets designed to deliver the optimal blend of performance and quality. When a vendor offers presets, I would choose the preset closest to my target configuration, make sure the Profile is appropriate, and adjust the resolution and data rate to my target settings.

This article appears in January/February 2014 issue of Streaming Media magazine as "Time for a Tuneup."

Streaming Covers
Free
for qualified subscribers
Subscribe Now Current Issue Past Issues
Related Articles

Encoding for Multiple Screens? Rule Number One: Use H.264

Reaching viewers on desktops, notebooks, phones, tablets, and set-top boxes all starts with the same step: Encoding video into H.264.

Evaluation Crowns FFmpeg the King of the H.264 Encoders

FFmpeg might be a free download, but there's still a cost that goes with it. Robert Reinhardt explains why this encoder isn't right for every company.

MPEG LA Announces Proposed HEVC Licensing Terms

The news is good for content owners and not so good for encoding/decoding vendors, but gives everyone a feel for how the issue will play out.

HEVC Likely to be Subject to Similar Royalty Structure as H.264

Or, What I Learned During My HEVC Presentation at Streaming Media West

What to Look for in an H.264 Video Encoder

Today's video encoders are mostly similar and mostly good, said Robert Reinhardt at Streaming Media East. Still, there are a few features to seek out.

What Is H.264?

A look behind H.264, the world's most popular video codec, including encoding parameters and royalty concerns

Companies and Suppliers Mentioned