Tag Archive for 'ipod'

How to Fix the H.264 Gamma Shift Bug in Quicktime FOREVER

Subscribe




For anyone who has ever experienced problems when exporting H.264 video, this article was meticulously researched just for you.

I wrote this article because many people benefited from my previous article about this issue regarding what I learned when encoding video for Byteful Video. This article is a followup to that article. However, if you don’t create video, you can safely skip this article; and in the next article we will return to our regularly-scheduled travel programming.

First of all, while researching this article I was shocked at what I discovered to be true versus what I’d heard. It seems there’s a lot of confusion around video, and that’s not surprising considering how absurdly complex it can be. Today, I’d like to clear away the confusion and openly show how I solved this problem once and for all.

When I set out to write this article originally, I thought that the popular video encoding program Handbrake was the solution to the dreaded H.264 gamma brightness bug that has been plaguing video creators for years. And if you export video to H.264, you’ve probably heard of this problem.

Basically, when you export a video from Quicktime Pro as H.264, the resulting video is brighter than the original, and usually it looks horrible.

A False Solution

Yet I’d heard this problem was easily solved using Handbrake because it used a different encoder than Quicktime, namely the award-winning x264 encoder. Yet after conducting various tests, I was able to repeatedly demonstrate that using Handbrake does not solve the brightness bug at all. It doesn’t desaturate the colors as some methods do, but it does change the brightness curve. Here’s a simple animation that I created that alternates between a frame from my original uncompressed video and the same frame from Handbrake’s version of the video:

Video Comparison Animation

The main problem with this gamma shift (which is sometimes inaccurately referred to as a color shift) is that your video’s “black levels” become unrealistic, and you loose the ability to have rich shadows.

Elgato Turbo.264 HD EncoderAnd in case you’re curious, this was done using a slight variant on the iPod encoding preset included in Handbrake. These results mean that Handbrake decides to treat gamma in the same inaccurate way that Quicktime Pro does. Therefore, it would never be able to solve my problem. And as far as I know, hardware encoders like the Elgato Turbo.264 HD Encoder (pictured here) don’t treat gamma the same way, either. For non-professional uses, devices like the Elgato Turbo are awesome for converting video quickly (usually they’re faster than using your computer to encode the video), but they lack the fine control of the encoder I’m going to show you today.

So now that Handbrake had failed, what could I do?

Handbreak video vs. OriginalThen it occurred to me, what if I bypassed Handbrake altogether? What if I used the x264 encoder directly with Quicktime Pro?

I decided to give it a try.

I remembered that x264 was also available as a standalone Quicktime plugin, so I did some research. At first, all I found was a stand-alone plugin from 2006, so I grabbed it off of MacUpdate. After a quick install process, I ran a few tests and exported a few different times, trying different settings each time. And, while the gamma problem was completely gone, I could not get any resulting movie files to play on any mobile devices.

Basically, I tried every variation of advanced settings, and nothing would work. This plugin simply doesn’t have the specific settings needed to create a video that will play on an iPhone or iPod.

So I had to resume my research, and I soon realized that Japan is still producing truly awesome people.

I’ll explain.

What finally saved me was a newer plugin by a Japanese guy named Takashi Mochizuki. This plugin is still based on the award-winning x264 project, but it has over ten times as many fine controls on its settings page than the other x264 plugin. This incredible beast is called x264Encoder, and it’s available on Takashi’s site, completely free.

After reading some of the documentation and conducting various tests, I finally refined a way to create flawless H.264 video that works on a variety of devices, all without any gamma bug. But before you can delve into the powerful controls of this new plugin, you have to install it and relaunch your video editor.

x264Encoder Quick Install

  1. Download the plugin on Takashi’s site.
  2. Copy the x264Encoder.component to Mac HD/Library/QuickTime/
    • Make sure you’re opening the Library folder at the root level of your hard drive. Don’t put it in the library folder in your Home, because that won’t work.
    • If you have trouble with installation, please read the directions that come with the plugin.
  3. Quit any video editing programs you have open because they’ll need to be relaunched to see the new Quicktime encoder you’ve just installed. (Although it’s best to reboot entirely.)
  4. Open your video editing program and do one of the following:
    • In Final Cut Pro, choose:
      File menu > Export > Using Quicktime Conversion
    • In iMovie, choose:
      File menu > Export > Quicktime Tab
      Choose, Compress movie for: Expert Settings
      Click “Share”
  5. Then enter the detailed settings below.

Detailed Instructions for Flawless H.264 Output

Select: “Format: Quicktime Movie”
Click “Options” button
Make sure “Video”, “Sound”, and “Prepare for Internet Streaming” are all checked.
Then, under “Prepare for Internet Streaming”, choose “Fast Start”.

Under Sound, click “Settings” button
Change the settings to this:
Format: AAC
Rate: Recommended
Render Settings: Quality: Normal
MPEG 4 AAC LC Encoder Settings: Target Bit Rate: 160kbps
Click “OK”

Under Video, click “Size” button
Just look at this to make sure that it’s the size you want. (I mention this because when testing, I noticed that this would default to “Compressor Native” which was too small.)
Click “OK”

Under Video, click “Settings” button (this is the really important part)
Change the settings to this:
Compression Type: x264 Encoder
Frame rate: Current
Key Frames: Automatic
UNCHECK Frame Reordering
Encoding: Best Quality (Multi-pass)
Data Rate: Restrict to 1500 kbps (if you want iPods to be able to play it)

Alternatively, you could just make your settings look like this:

x264 Video Compression Settings

Then click “Options” button at the bottom left of the window.

This is where it starts to look a little crazy, but it’s easier than it looks.
So hang in there! This is totally worth it.

Now, you will see this vast array of options:

x264 libavcodec settings

But you don’t have to worry about setting all of this up because presets are included!

Click the “Load Preset” button at the bottom left, and a sheet will slide down.

Presets make it easy to make iPhone-ready video

x264 load presetsIf you’d like people on mobile devices like the iPhone, iPad, or iPod touch (as well as the PSP and Zune) to be able to play your video, choose the “iPod Tuned” preset. (According to the x264 docs, this takes a bit longer to encode than “iPod Default”, but the results look better. It’s worth it.)

Click “OK”

And while we’re here, click on the “Values” tab to look at all the settings you don’t have to worry about because Mochizuki-san provided some excellent presets! Domo arigatou, Mochizuki-san!

The Key is Setting the Gamma

To finish up, let’s activate the color spacing tag that fixes the problem that spawned this entire situation.

Click on the “Tagging” tab and check the checkbox “Add gamma 2.2 (SD/HD content)”. Adding this gamma tag simply and elegantly solves the problem without any unnatural color filtering or adjusting. That’s why this method is superior to all other methods. No “BlackWhite” restore, brightness filter, or strange alpha channel methods are needed. This is an important point. Shifting the brightness or contrast during exporting in order to fix the gamma problem is a bad idea. Not only does the export take longer, but worse, you always lose more quality than if you hadn’t adjusted. That’s why I’m so thankful that Mochizuki-san has put so much work into this plugin.

x264 Color Space Tagging

Now that you’ve set the gamma, your settings are complete!

Click “OK”
Click “OK” again
Click “OK” once more

Then click “Save”, and wait. (It may take hours depending on the speed of your machine and the length of your video. I recommend that, before you spend hours encoding your entire video, you experiment on a clip only a few seconds long to confirm that it looks the way you want it.)

The result? Beautifulness.

The resulting video will not only have the same brightness as the original, but it will also play back on mobile devices like the iPhone, iPad, or iPod touch. And there should be no significant brightness shift compared to a Mac and a Windows-based PC when playing back the same video file. (Although calibrating your monitor certainly helps!)

I thank Takashi very much, because at the end of the day, using this plugin lets me say two words I love to say:

Problem solved.

Subscribe


Thanks for sharing the traveller spirit!
  1. How to Fix Washed-Out H.264 Video
  2. How to Encode Video for a Podcast
  3. How to Stop Spam with Spam Karma 2 & SI Captcha (2 Free Plugins I love)

Sign up below to receive my free email newsletter, which I send out once every one or two months. It features brief updates on my travels as well as sneak peeks of upcoming articles from my quest to the Pacific Coast and the 5 months that changed my life forever.

Email Address: