How to Encode to HEVC: A Simple Guide for H.265 First-Timers
If you haven’t already, sometime in 2015 you’ll have to encode your files to HEVC format for the first time. No worries, we’re here to help with this guide to encoding to HEVC using the MainConcept and x265 HEVC codecs.
Why these codecs? Because while there are some encoding vendors who will create and deploy their own HEVC codecs, most encoding vendors will incorporate one of these codecs, just like most encoding tools have incorporated the MainConcept H.264 codec and/or x264. So addressing these two HEVC codecs delivers the best bang for our editorial buck.
Fortunately, H.264 and HEVC are very similar from an encoding perspective, just as MPEG-2 and H.264 are. This is shown in Figure 1, which is from the Elemental Technologies White Paper “HEVC Demystified: A Primer on the H.265 Video Codec.” As you can see, the general concepts are similar, as are the frame types and various other elements. Where H.264 has greater precision than MPEG-2, especially in the Transform and Motion Estimation Blocks, HEVC has greater precision than H.264, though some of this is “under the hood” and not configurable with either codec.
Because of these fundamental similarities, much of your decision making when encoding with HEVC will relate to familiar configuration items: I- and B-frame interval, data rate selection, and bitrate control technique (VBR, CBR). None of the rules regarding these items have changed in theory, so you can apply them just as you always have, though obviously you’ll be using a different data rate than you would for H.264.
Getting Started
Most advanced codecs include dozens of configuration options that can lead to thousands, if not millions, of unique configuration permutations. To simplify operation for their users, both MainConcept and the developers of x265 (led by Multicore and sponsored by Telestream and Sorenson) create presets that represent relevant trade-offs between encoding time and output quality. This is shown in Figure 2, the preset selection screen from Telestream Vantage, which uses the x265 codec.
Fig 2. Choosing an x265 preset in Telestream Vantage
With Vantage, you can choose a preset and customize your HEVC encode even further by inserting command-line arguments in the field below the preset. Sorenson Squeeze, which also uses the x265 codec, lets you choose a preset and access all other encoding parameters within the actual encoding interface. Both encoders provide access to x265 tuning alternatives, which I did not explore in this article.
Rather than using a preset, MainConcept uses a P/Q selection, which ranges from 1 (Fastest Encode/Poorest Quality) to 30 (Slowest Encode/Best Quality). With the x265 codec, the Medium preset is the default; with MainConcept, 15 is the default. When using either codec, the most important issue is determining which preset is right for your encoding operation, so I’ll address this topic first. Before jumping into the results, let’s discuss how and what I tested.
How I Tested
For this series of tests, I used seven 5-second files with varying content, ranging from a low-motion, low-detail talking head video to a high-detail, high-motion shot of a Food City parking lot with lots of trees and bush, shot from a rising lift on a windy day. The distinct content obviously stressed the codecs in different ways, while the short duration enabled me to run hundreds of discrete encodes.
I tested at 1080p resolution encoding to the Main (rather than Main10) HEVC profile at 2Mbps per second, encoding to 1-pass CBR with a key frame interval of 60 frames. I tested each codec using five different standardized presets that I’ll identify below. I encoded the MainConcept files using version 3.2.0 (build 17871) of MainConcept’s TotalCode Studio. I produced the x265 files via command line using version 1.4.0 of the x265 video encoder. With all encodes, I verified that the encoder met the target rate, which proved much more of an issue with x.265 than with TotalCode. After running the tests, I compared quality using the Moscow State University Video Quality Measurement Tool’s Video Quality Metric (VQM) rating to assess output quality, and verifying the findings with subjective comparisons.
MainConcept Tests and Results
With MainConcept, I tested P/Q values 1 (lowest quality, fastest encode), 15 (the default), 22, 27, and 30 (highest quality/slowest encode) while keeping all other parameters identical. The goal was to understand the qualitative and performance trade-offs associated with the various presets. I present the summary results in Table 1.
Table 1. MainConcept results
The Average Encoding Time and Average VQM Score columns show the average encoding time for all 5-second clips, plus the average VQM score. The Increase in Encoding Time Column shows the increase in time between that and the previous preset, while the Quality Change does the same for quality, with the total difference at the bottom of each column representing the total change from P/Q 1 to P/Q 30.
So, the switch from P/Q 1 to P/Q 15 generated an average 15 percent quality improvement over all seven test clips, while encoding time increased by 68 percent. Accordingly, encoding at P/Q 15 captures 55 percent of the total quality difference between the two extreme presets (15 percent/27 percent) while increasing encoding time by 68 percent. This makes P/Q 15 a reasonable default for many users.
That said, jumping to P/Q 22 captures another 22 percent (6 percent/27 percent) of the available quality while extending encoding time by 58 percent. While faster is always better, encoding at P/Q 22 is an obvious decision unless slowing down to P/Q 22 would force you to buy another system to meet your encoding demands.
On the other hand, jumping from P/Q 22 to P/Q 27 increases quality by 5 percent but boosts encoding time by a factor of 12. Only low-volume shops will be able to make that change. With a quality boost of only 1 percent and a boost of encoding time of 231 percent, using the highest-quality preset seems like a bad idea for virtually all producers.
x265 Tests and Results
With x265, I tested the Ultra Fast, Very Fast, Medium (Default), Slower, and Placebo presets. Here, the results were counterintuitive, as the quality dropped significantly from Ultra Fast to Very Fast, and Ultra Fast was also slightly ahead of Medium in quality, despite encoding in around a third of the time (Table 2).
Table 2. x.265 Results
Related Articles
Use a single adaptive group, packaged differently for different targets, to keep encoding and storage costs down.
06 Apr 2016
While it's fun to be on the cutting-edge of new video codecs and formats, H.264 should be every publishers' primary focus for the time being.
04 Jun 2015
Why would set-top box makers bother supporting UHD video when home bandwidth connections aren't nearly robust enough to carry it?
24 Apr 2015
If you've spent any time at NAB or IBC, you'd think that HEVC is ready for prime time. The reality is that, for almost every use case, it's nowhere close.
15 Sep 2014
Are you already using HEVC? Are you thinking about it, but waiting until encoding times get shorter? Or are you still on the fence? We want to hear from you in our Streaming Media HEVC Survey.
03 Jun 2014
Which codec delivers better image quality? Which is more compatible? And what about Daala, the spoiler codec currently being developed from scratch?
09 May 2014
Companies and Suppliers Mentioned