How to Fix the H.264 Gamma Shift Bug in Quicktime, FCP, & iMovie




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

Have you ever exported h.264 video only to find the colors washed out or faded? Maybe your blacks have become crushed into dark grays? When exporting episodes for Byteful Video, I encountered this problem, too. And today, I’d like to clear away the confusion and openly show how I solved this problem once and for all, creating beautiful video that looks good on your computer, as well as video sharing sites like YouTube and Vimeo.

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. So let’s clarify it!

A False Solution

Originally, I heard this problem was easily solved using the Handbrake encoder 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. Instead, the video gets lighter and washed out (some call it “brighter”, but that’s not technically accurate). But the solution I’m about to share with you prevents this distortion of color and washed out gamma levels. It’s a “one gamma-color-shift fix for Quicktime to rule them all”, kinda thing.

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 right 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.

What finally saved me was a newer plugin by a Japanese genius 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. Most importantly, it corrects the problem! 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. I’d finally discovered the best video compression technique for color consistency. But before you can delve into the powerful controls of this new plugin, you have to install it and relaunch your video editor. (I prefer Final Cut Pro, but it also works with iMovie.)

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.



Sign up to receive my free email newsletter, sent once every month or so, featuring the best of Byteful Travel.

Email Address:

Print Friendly

52 Responses to “How to Fix the H.264 Gamma Shift Bug in Quicktime, FCP, & iMovie”


  • @rick and to all,
    I tried the procedure quitting Adobe CC after the codecs settings.
    To keep the software I had to try the export with failure results, then quit Adobe CC
    and then reopen it. At this point the settings were the ones I wanted.
    So I export the file but the final result does not seems to have the gamma correction.
    I mean the exported video compared to the original one when no other action but the
    gamma correction from the x264 was applied, looks different.
    This is really a problem.
    I’d like to compile a movie with lots of shots I recorded with a GoPro hero 3.
    The original videos looks great and it is extremely important to keep their original quality in the exported one. Especially for those underwater shoots.

    I do not know if I have some Adobe CC installation problem, and I do not know how to fix this very annoying gamma shift.

    Please, any further help?

    Thanks to all
    Max

  • J Thaddeus Toad

    Thanks very much for sharing this research, it worked for me!

Leave a Reply

CommentLuv badge
You can add a link to follow you on twitter if you put your username in this box.
Only needs to be added once (unless you change your username). No http or @