H.265/HEVC (High Efficiency Video Coding) Status and How-To Encode Videos to H.265
Now H.264 is the main standard used for video compression, and most devices that can support video playback feature an SoCs capable of H.264 hardware video decoding. Since 2004, however, work has been done to improve H.264, and a new standard called High Efficiency Video Coding (HEVC), also referred to as H.265, will eventually replace H.264, even though this will take a few more years to really gain traction.
HEVC will be able to double the data compression ratio compared to H.264 with the same quality, or improve the quality using the same bitrate, and it can support 8K UHD (Ultra High Definition) with a resolution of 7680×4320 (4320p). This new video codec is a big deal for those who pay for video bandwidth (80% of internet traffic according to Ericsson), and it should also be welcomed by consumers, as it will magically double their storage device capacity, and they may say farewell to buffering messages while watching online videos. I still have to watch YouTube videos @ 360p to get a reasonable experience here…
The High efficiency video coding (HEVC) standard will be ratified in January 2013, but Qualcomm already showcased H.265 decoding on a SnapDragon at MWC 2012, Ericson unveiled the SVP 5500 H.265 Encoder for broadcasters at IBC2012, and a few other companies also announced H.265 solutions.
Fully optimized solutions should be available at the end of 2013, and broad use is bound to take a few more years, as was the case when content moved from MPEG-2 to MPEG-4/H.264. Ericsson uploaded an interesting video about the new standard, explaining why HEVC was being developed, and Jacob Strom (Ericsson Research) compares several images encoded with H.264 and H.265 using the same bitrate, and it clearly shows improved quality with the new codec.
You can read Overview of the High Efficiency Video Coding (HEVC) Standard. (19 pages PDF), If you are interested in the theory and technical details behind HEVC/H.265.
If you are adventurous, Fraunhofer provides reference software capable of encoding and decoding to/from HEVC. The main goal of this software is to provide a tool to experiment by the new codec, and it’s not particularly efficient or speedy, as you’ll discover below. As a user, it is actually a complete waste of time to do that, since, AFAIK, the most used players do not support the standard yet. But let’s go for it anyway.
All information you need is on Fraunhofer’s High Efficiency Video Coding (HEVC) page, but to get started with the software, you just need to download the documentation. I’ll document the steps I’ve followed to encode a short sample of Big Buck Bunny to H.265 in Ubuntu 12.04. You can also build and run the programs in Windows if you prefer.
First, checkout the code, and build the reference software:
svn co https://hevc.hhi.fraunhofer.de/svn/svn_HEVCSoftware/trunk cd trunk/build/linux/ make
The build should complete within a short time, and you’ll have 8 binaries in ../../bin directory, but we’ll only use 2:
- TAppEncoderStatic – The release version of the H.265 / HEVC encoder
- TAppDecoderStatic – The release version of the H.265 / HEVC decoder
Before we can use the tools, we need a video file in YUV format. If you don’t have one, you can convert any video file (I’ll use big_buck_bunny_480p_H264_AAC_25fps_1800K_short.MP4) to YUV with
ffmpeg avconv (ffmpeg is deprecated, and we should use avconv instead).
First, install the package containing ffmpeg/avconv, if you don’t have it already:
sudo apt-get install libav-tools
Convert the file to YUV, and get the width, height, framerate and number of frames with avconv:
avconv -i big_buck_bunny_480p_H264_AAC_25fps_1800K_short.MP4 big_buck_bunny_480p_25fps_short.yuv
Now let’s encode this yuv file to h.265:
./TAppEncoderStatic -i big_buck_bunny_480p_25fps_short.yuv -wdt 856 -hgt 480 -fr 25 -f 100 -c ../cfg/encoder_intra_main.cfg
- wdt – Indicates the width of the video (avconv reports 854, but since frame width must be a multiple of the minimum CU size, I’ve set it to 856).
- hgt – Indicates the height of the video
- fr – Sets the frame rate
- f – Number of frame
- c – Refers to the config file to be used. You main noticed config file name with “main” and “he10″, those correspond the “main” and “main 10″ profiles of the standard, which allows respectively 8-bit and 10-bit color depth (Over one billion colors)
Encoding took 966 seconds with this config file, which corresponds to around 10 seconds per frame on my machine (Intel Core 2 Duo @ 1.8 GHz). The file name is str.bin by default, but if you want to set your own file name add something like “-b big_buck_bunny_480p_HEVC_25fps_short.h265″. I also tried another config (encoder_lowdelay_P_main.cfg) which took 1 hour for 50 frames. So I’d recommend just using a few frames (even just one) for testing. The resulting HEVC file was bigger than the original H.264 file most probably because of different quality settings. There are many settings, and you may have to spend some time to understand them.
Now let’s decode our file back to YUV:
./TAppDecoderStatic -b str.bin -o big_buck_bunny_480p_recontructed.yuv
Decoding was much faster as it just took 12 seconds for 100 frames.
Now let’s check the encoding/decoding process worked properly, by downloading YUV Player and opening big_buck_bunny_480p_recontructed.yuv.
Nice! It works!
There’s also x265 project, an implementation that targets “embedded, FPGA, GPU and MultiCores systems”, but it has recently been suspended due to lack of free time of the developer.