Compiling and Running Handbrake in Ubuntu

Exclusive offer: get 50% off this eBook here
Getting started with Audacity 1.3

Getting started with Audacity 1.3 — Save 50%

Create your own podcasts, edit music, and more with this open source audio editor

$23.99    $12.00
by Delan Azabani | May 2010 | Linux Servers Open Source Web Graphics & Video

Handbrake is considered the Swiss Army knife of video conversion tools. Running on the three major operating system platforms, Handbrake can open a huge variety of formats, including common ones that others can't handle (like the titles in the MPEG TS structure of a DVD). Handbrake outputs to a small selection of efficient formats, including H.264/MPEG-4 AVC, MPEG-4 ASP and Theora video. It has advanced features including chapter marking, subtitle inclusion and audio selection, plus filters for optimising video. On Linux, Handbrake can make use of the libdvdcss2 library to decrypt CSS-protected DVDs in-place during encoding, saving the need to use DVD Decrypter or another tool, usually through Wine. This article by Delan Azabani will guide you through the process for building Handbrake, installing it and converting video with it.

Background

Handbrake has stable builds for Windows, Mac, Ubuntu and Fedora. The developers of Handbrake haven't made a stable release for quite some time, leaving the latest version at 0.9.4. While this generic version is good enough for most people, generally it's better to build Handbrake yourself, on your computer for best results. The official PPA is only for Karmic Koala (9.10), and though packages are meant to be forward-compatible, the interface doesn't work in Lucid (10.04) at all. Hunter Kaller's PPA has a proper Lucid build, but for most installations, the video output is garbled. Where does that leave us? A build from the trunk.

Compiling Handbrake

To compile our own copy of Handbrake, we must obtain the source code from the Subversion repository. If you don't have Subversion (the default install doesn't), install it from the Ubuntu repositories:

sudo apt-get install subversion

To download the source code, you must run Subversion in a terminal:

svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk

Before we compile Handbrake, we must install some dependant packages - without knowing and installing these, the compile process will stop again and again until we install all the packages one at a time:

sudo apt-get install yasm build-essential \
autoconf libtool zlib1g-dev libbz2-dev intltool libglib2.0-dev \
libdbus-glib-1-dev libgtk2.0-dev libhal-dev libhal-storage-dev \
libwebkit-dev libnotify-dev libgstreamer0.10-dev \
libgstreamer-plugins-base0.10-dev

After changing to hb-trunk, run the configure script:

cd hb-trunk
./configure

The configuring process should take less than two seconds (but don't worry if it takes longer; only worry if there are errors printed). Ignore the message that "lipo" and "xcodebuild" are not found; they are for Mac OS X builds only. Now we can build Handbrake. It is always best to compile using as many concurrent build processes as you have cores, so the make command will now look like:

make -jX

where X is the number of cores you have in your computer. To build Handbrake, change into build and run make:

cd build
make -j4

Compiling and Running Handbrake in Ubuntu

Compiling and Running Handbrake in Ubuntu

If you see weird output and you're using a j value higher than 1, don't be alarmed; it's just that the processes are all fighting over stdout so some output gets mixed. This may take five minutes to half an hour, depending on your computer's processing speed. On my Intel Q9650, it took around five to ten minutes. Unless you see errors at the end of the output (in which case they should be fixed before moving on), you're ready to install Handbrake! Make sure that any copy of Handbrake from a repository is uninstalled first:

sudo apt-get purge ^handbrake.*\$

Finally, run sudo make install to install Handbrake. Congratulations! If all went well, you should be able to run /usr/local/bin/ghb or find Handbrake in Applications > Sound & Video and Handbrake should launch! If all didn't go well, The build docs may be able to solve your problem. Check it out; it has helped me many times before.

Getting started with Audacity 1.3 Create your own podcasts, edit music, and more with this open source audio editor
Published: April 2010
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

Working with Handbrake

In this section we will add a video source and apply picture, video, audio, and subtitle settings.

Adding a video source

Handbrake incorporates a queue system that allows you to batch-convert various titles with one click. (Excluding those used to make the queue.) To add a video source (a Handbrake term for a file or directory that can contain one or more titles, a VIDEO_TS folder being one that can have many), click on Choose Video Source:

Compiling and Running Handbrake in Ubuntu

Once you've chosen a file (or DVD or directory), the titles will be scanned. You can use the Title dropdown to select the one you wish to encode (the longest one is automatically selected, which is convenient for DVDs). You can constrain the chapters, seconds or frames that are encoded by using the controls below the title selector. Remember to choose a preset (on the right); High Profile is much better than Normal, and don't forget to select your container format (MPEG-4 or Matroska). The MPEG-4 container format only supports a limited number of streams, and doesn't allow subtitles unless they're rendered on to the video (burned in).

Picture settings

Compiling and Running Handbrake in Ubuntu

Compiling and Running Handbrake in Ubuntu

The Picture Settings window allows you to adjust cropping and aspect ratio settings. For instance, you can set up non-square pixels, which is just like DVD and SD digital TV works: a 720x576 video can in fact be 16:9 widescreen, as it's stretched to display as 1024x576. This dialog also allows you to add filters to improve the appearance of the output video, including the ability to deinterlace the video stream. Check the Show Preview checkbox to see a frame of the video, and encode a short piece of the video to observe the filter in action.

Video settings

Compiling and Running Handbrake in Ubuntu

The Video tab allows you to choose the codec, framerate and basic quality settings for the video encoding. At present, only H.264/MPEG-4 AVC, Theora and MPEG-4 ASP are supported. You must use the Matroska container for Theora. On the right hand side, you can choose a quality factor, a constant bitrate or a target video size. The quality factor is the best to use as it allows for a variable bitrate encoding; allowing more data for high-detail sequences. A lower quality factor (drag to right) outputs a higher quality video. Note that for H.264, a quality factor of zero equates to a lossless encoding, but in my experience hasn't worked properly as the output is garbled. A two-pass encoding allows for a higher-quality encoding as the encoder can analyse the input without encoding, however it can take up to twice as long as a single pass.

Audio settings

Compiling and Running Handbrake in Ubuntu

The audio tab allows you to control the audio streams that are encoded and included in the final output video file. A track may be included by default; you can remove it for video with no audio, or add more. To do so, choose a source track, and configure the output encoding settings before clicking the plus icon to add the track. These settings are not affected by a preset change, as available audio tracks may vary.

Subtitle settings

Compiling and Running Handbrake in Ubuntu

The subtitle tab can help include subtitles in the output video. If you're choosing to use the MPEG-4 output container, you won't be able to choose subtitles that can be turned off; instead they'll be rendered onto the video (in which case you shouldn't include more than one or else overlapping subtitles will arise). Like the audio tab, choose the subtitle type first before clicking the plus icon. Also like the audio tab, settings here are not affected by presets, as the available subtitles may vary.

Finalising and encoding

You can set up chapter markers and advanced H.264 encoding settings (obviously only applicable with the H.264 output encoding) in the other two tabs available. Most of the time you won't need to modify H.264 settings; the Normal, High and device profiles have good choices that create quality videos with a low file size. Once you've set up the settings for the video, you can either click Encode if this is the last or only job, or Add to Queue for adding more jobs.

If you have a queue with multiple jobs, you may find it useful to click Show Queue to observe the progress of the encoding jobs. The Activity Window is also a very helpful tool to read debugging information, especially if your videos aren't outputting correctly or even encoding at all.

Custom presets

With Handbrake's plethora of options, you may find it tiring to set up all your settings for the video each time you start Handbrake, so saving a profile with preset settings may be quite helpful. Once you've set up everything the way you want, click the save button under the preset list. Please remember that some options will not be remembered in the preset (including some audio and subtitle options) as these streams may vary from source to source.

Conclusion

As the blog post for the Handbrake 0.9.4 release says:

There's an old proverb in the video encoding world: "Speed, size, quality: pick two." It means that you always have to make a trade-off between the time it takes to encode a video, the amount of compression used, and the picture quality. Well, this release of HandBrake refuses to compromise. It picks all three.

This quote is very true compared to other encoders that lack proper optimisation. Handbrake works extremely fast and pretty soon after starting an encoding job, you'll have to put down that cocktail; your Handbrake queue is done!

Compiling and Running Handbrake in Ubuntu


If you have read this article you may be interested to view :


Blender 2.49 Scripting Extend the power and flexibility of Blender with the help of the high-level, easy-to-learn scripting language, Python
Published: April 2010
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

About the Author :


Delan Azabani is a Linux and web developer based in Western Australia. In his spare time, he writes articles about web applications and Linux topics. He has extensive experience in PHP, JavaScript and C++, and can be reached at his website, http://azabani.com/, or by email, at delan.azabani@gmail.com.

Books From Packt


Blender 3D 2.49 Incredible Machines
Blender 3D 2.49 Incredible Machines

SketchUp 7.1 for Architectural Visualization: Beginner's Guide
SketchUp 7.1 for Architectural Visualization: Beginner's Guide

3D Game Development with Microsoft Silverlight 3: Beginner's Guide
3D Game Development with Microsoft Silverlight 3: Beginner's Guide

Unity Game Development Essentials
Unity Game Development Essentials

Papervision3D Essentials
Papervision3D Essentials

Drupal Multimedia
Drupal Multimedia

MySQL for Python: Database Access Made Easy
MySQL for Python: Database Access Made Easy

Wordpress and Flash 10x Cookbook
Wordpress and Flash 10x Cookbook


Your rating: None Average: 5 (4 votes)
HANDBRAKE works now on Lucid Lynx 10.04 by Patrick O'Sullivan
Follow the link and you will get Handbrake working https://edge.launchpad.net/~stebbins/+archive/handbrake-snapshots Patrick Adelaide, South Australia
Hanbrake running on Lucid Lynx 10.04 (IT WORKS NOW!) by Patrick O'Sullivan
Hi Folks, I've had much the same problems as the responders above. Anyway I've got it working by using the following link, adding as instructed to your repositories then gone to Synaptic Package Manager and installed Hanbrake.The link comes from the Handbrake web site. https://edge.launchpad.net/~stebbins/+archive/handbrake-snapshots At the moment I'm encoding a bluray movie and all seems to be working properly. Patrick Adelaide, South Australia
libgudev-1.0-dev needed by
Hi, Tahnsk you for the writeup - I needed libgudev-1.0-dev also in order to successfully compile handbrake
instructions incomplete? by
I followed this to the letter and the end got the following on Ubuntu Lucid Lynx (10.04) No package 'gudev-1.0' found ~/hb-trunk/build$ sudo make install /bin/cp ./HandBrakeCLI /usr/local/bin/HandBrakeCLI /bin/cp: cannot stat `./HandBrakeCLI': No such file or directory make: *** [test.install] Error 1 So the latest Ubuntu does NOT work with these intructions. Thanks
gudev dependency by
Great tutorial! In Ubuntu lucid, though, there is one more dependency that should be added to the apt-get install list: libgudev-1.0-dev
build fails on Ubuntu Lucid lynx by
Hi, Thanks for the guide. Build (trunk:3285) fails on my Ubuntu Lucid Lynx with: 8<******* checking for GHB... configure: error: Package requirements (gtk+-2.0 >= 2.10 gthread-2.0 gstreamer-0.10 gstreamer-interfaces-0.10 gstreamer-video-0.10 gstreamer-pbutils-0.10 gio-2.0 libnotify gudev-1.0 webkit-1.0) were not met: No package 'gudev-1.0' found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables GHB_CFLAGS and GHB_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details. make: *** [gtk/.stamp.configure] Error 1 8<*********** Fixed with: sudo aptitude install libgudev-1.0-dev Should be added to the dependencies. Stuart
Failed by
Although everything seemed to go well through the build, when I got to sudo make install, it errors. ~/hb-trunk/build$ sudo make install /bin/cp ./HandBrakeCLI /usr/local/bin/HandBrakeCLI /bin/cp: cannot stat `./HandBrakeCLI': No such file or directory make: *** [test.install] Error 1 That directory doesn't exist, all that's in build is: contrib GNUmakefile gtk libhb log project test There were no errors during the make. arrrgh.

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
d
S
T
T
m
f
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software