Harnessing Handbrake*

By: Maxym Dmytrychenko, Tim Duncan

Download Article


Harnessing Handbrake [PDF 587KB]

HandBrake


HandBrake* is a Microsoft Windows* application that takes almost any video file format and modifies it for use on devices like the Apple iPhone* and iPad*, Android* phones/tablets, and others. However, HandBrake has been a CPU-only conversion application. Intel® Quick Sync Video, a HW accelerator, allows you to offload the full decode/filter/encode (collectively termed, transcode) scenario from the CPU to Intel® HD Graphics. Offloading the transcoding to the Intel HD Graphics provides several benefits. First, the transcoding is quicker compared to the traditional CPU-based approach. Also by using the dedicated circuits in the Intel HD graphics you not only get a speed in performance but it also consumes less energy allow you to conserve your battery for other activities. Our goal in this effort was to improve user experience for HandBrake by extending it with support of HW acceleration while running on Intel® architecture.

Introduction


When video content is consumed whether it is on your smartphone, tablet, computer or some other device it most likely has been converted to a format that is best for that particular device. This video conversion process is very similar to when some put audio onto their smartphone, table computer, etc. The process is called transcoding when the source video is decoded, transformed (changing resolution, bitrate, frame rate or applying filters and the encoded (format into a format that is viewable on the consumption device. Transcoding video has traditionally been done in software on the CPU but with the introduction of the Intel 2nd Generation Core Intel now has dedicate circuitry within the processor graphics that allow this process to be hardware accelerated.


Figure 1. HandBrake User Interface

HandBrake is a well-known, open source project. For years it has been used to transcode video from cameras to formats compatible with other devices. It has averaged more than 650,000 downloads per month in the first seven months of 2013 on Sourceforge*.

HandBrake is one of those gems that didn’t show its worth until we needed it. Before Handbrake, we used other applications to convert video files to shareable file types, but we had to use three or four different utilities to get the file from our camera’s .MOV format to the right .MP4 or .AVI format. File sizes were often too large. Handbrake has profiles that support all of these, and customization is possible through personal settings create customized profiles. Pick the target device from the profiles included in Handbrake and you are on your way.

Intel engineers were interested in Handbrake due to their reputation and popularity in the marketplace. We approached their team to see if they wanted to collaborate to find ways to improve execution performance while keeping the user experience where users had come to expect.

We presented a proof of concept project to show how Intel HW acceleration could benefit them. They were intrigued.

When the latest build of HandBrake is installed on 4th generation Intel® Core™ processor-based computers running Windows with Intel HD graphics, HandBrake will display a new option on the video tab for video codec: H.264 (Intel Quick Sync Video).


Figure 2. HandBrake Video Tab showing location of Intel Quick Sync Video Codec

Please note that at the time this article was published, the Intel Quick Sync Video code was only included in the pre-release or beta testing release, a standard process for introducing new functionality into an established product like HandBrake. The executable for these builds can be downloaded at the nightly build link from the download section on the main HandBrake website.

A very active community exists in and around HandBrake, so you can find links for the latest news about the project, tutorials, support, a link for contributions, and more. Some links provided at the end of this article.

What We Did


Initially, Handbrake ran all its processes on the CPU including the transcode steps, the decode step followed by application of filters and finally the encode step. Hardware acceleration did not natively run within the application, so we dissected the internal workings of the program to see if we could have it utilize this feature natively. Additionally, we used our Intel® Media Software Development Kit (Intel® Media SDK) API to understand and work with Intel Quick Sync Video effectively. The Intel and HandBrake teams put our heads together to identify the steps needed to add Intel Quick Sync Video Intel HD Graphics acceleration to the project. This resulted in a list of functions we could start working on, including Intel Quick Sync Video-based H.264 decode/encode and Intel Quick Sync Video-based filters.

Improved Execution Performance When Using Intel Quick Sync Video

While on the CPU, the execution and timing of decode/encode, etc. differed compared to hardware acceleration provided by Intel HD graphics. Since we wanted to achieve the best performance possible, we needed to adjust internal pipelines, queues, and their corresponding sizes. To improve performance in this area, we adopted test/change approach to achieve the best possible results with Intel® Quick Sync Video in HandBrake. Currently, our experiments using the H.264 Intel® Quick Sync Video codec show Intel HD graphics on Microsoft Windows* 8 utilization approaching 100% while the CPU utilization remains under 20%, allowing for a full speed transcode since the dedicated Intel HD graphics is not affected by the other computing tasks the CPU must always attend to.

More Benefits from Tighter Intel Quick Sync Video Interaction

This project started with Handbrake, a fully functional and successful application. The application’s existing video processing filter operations are applied and completed between the decode and encode processes. Since HandBrake’s existing filters are excellent from quality and performance perspectives, the filters are executed by the CPU and not the Intel Quick Sync Video-enabled Intel® HD Graphics. Intel Quick Sync Video offers many of its own native filters through Intel Media SDK. Some Intel Quick Sync Video filters duplicate the functions of the current HandBrake filters, and in a majority of the cases, had the potential to be faster than the CPU based filters already in HandBrake. We completed several rounds of testing/validation to understand and choose which of these duplicate filters were better.

Final performance analysis

What we are seeing in our limited testing is 3-6 times faster transcoding using the Intel Quick Sync Video-based H.264 codec versus the CPU-only codec. HandBrake has done a great job taking full advantage of the Intel Quick Sync Video capabilities. It was hard to push all to the limits, but it was fun and interesting to see new issue(s), corner case(s), and make substantive contributions to this product.

Conclusion


The Intel Media SDK API, its documentation, and tools like Intel® Graphics Performance Analyzer were useful when identifying, measuring, and repairing several issues. We found the support of the HandBrake team invaluable. They were very open-minded and willing to discuss each new idea. Also, the Intel SDK and Visual Products teams’ support was required and appreciated for this challenging project. Because HandBrake is an open source project that anyone can see and study the implementation details and source code, we hope others will find it a little easier to add hardware acceleration with Intel Quick Start Video through the use of Intel HD graphics.

References

HandBrake Links:
Homepage - http://handbrake.fr/
Download page - http://handbrake.fr/downloads.php
Nightly builds page - http://handbrake.fr/nightly.php (executable w/Intel Quick Sync Video options)
Intel Quick Sync Video Source Browser - https://trac.handbrake.fr/browser/branches/qsv

Intel Links:
Intel® Media SDK 2013 Detail - http://intel.com/software/mediasdk
Intel® Graphics Performance Analyzer - http://www.intel.com/software/gpa
Intel Quick Sync Video Detail – Direct Link

About the Authors:

Maxym Dmytrychenko is a Senior Application Engineer working in Europe. He focuses on video processing and HW acceleration on IA and has worked in this area for several years with worldwide-known ISVs.

Tim Duncan is an Intel Engineer and is described by friends as “Mr. Gidget-Gadget.” Currently helping developers integrate technology into solutions, Tim has decades of industry experience, from chip manufacturing to systems integration. Find him on the Intel® Developer Zone as Tim Duncan (Intel)

Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.
Copyright © 2013 Intel Corporation. All rights reserved.
*Other names and brands may be claimed as the property of others.

Einzelheiten zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.