How to Fix the H.264 Gamma Brightness 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.

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, you’re 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, that 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


  1. How to Fix Washed-Out H.264 Video
  2. How to Stop Spam on Your WordPress Blog FOREVER (for free, with captchas)
  3. How to Encode Video for a Podcast
  4. How to Make a Widescreen Movie without any HD Camera whatsoever
Get the free Byteful Newsletter. Always fresh, always spam-free. Just exclusive travel insights, breathtaking sights, and pure adventuristic joy, sent bi-monthly. Like this site? Then you'll love this.

Email Address:

34 Responses to “How to Fix the H.264 Gamma Brightness Bug in Quicktime FOREVER”


  • Thankyou for such an informative blog. Good job!

  • OMFG thank you thank you thank you. I gave up years ago on this bug and in utter disgust with Apple. The disgust remains but IT WORKS!!! Cannot believe it. All that junk on the internet about the transparency layer in the quicktime settings, what a cruel joke that was.

    This actually worked. I wanted my video at the same resolution as the original, so I didn’t use the Ipod Tuned settings but instead the Component Tuned ones. Still worked like a GD charm. So awesome.

    SO AWESOME

  • Hey Bob!

    Thanks so much for sharing your success! I love to hear from readers, and I’m so glad that my hours of research and troubleshooting have benefitted more than just myself! (Isn’t that what makes the internet so awesome, though?)

    Actually, I’m pretty sure you can use any resolution with the “iPod Tuned” settings, but anything bigger than 640×480 just won’t play on an iPod or iPhone. (Although I’m pretty sure the new iPhone 4 can play back at resolutions higher than 640×480, but it JUST came out.)

    So glad it worked for you though!
    Spread the word! :)
    Andärin recently posted…Inspiration Strikes! New Design &amp Usability LessonsMy Profile

  • Thank you for taking the time to find and clearly explain, this no-bullshit solution. This saves me wading through the morass of posts about how there is no problem other than user error or lack of knowledge.

  • Great article man … :)

    Any solution for Windows users ?!? :(

    I’m also breaking my head on this problem ….

    BR,
    Yogi

  • Great article! But I have the same problem as Yogi. Any solution for us Windows users? Please help asap!

  • well…
    this seems to correct the gamma issue when played back in QT. without the need to manually crush blacks or even check the ‘final cut compatability’ box in the preferences.

    HOWEVER… the gamma check box in this plugin doesn’t work when uploading to youtube. the videos look gamma shifted upon final processing in youtube. seeing as youtube is the ending spot for my work, THAT’s where it has to look good, not QT.

    any advice for settings that the youtube’s encoder can identify and use accordingly?

  • Thanks for this article!

    I would like to use this codec when encoding movie from Keynote’s presentation. I don’t have an idea how to “tell” Keynote to use it, there is no preferences at all… Damn you Apple, just let us export in the ways we like it exported.

    Does anybody know how to force Keynote to use this encoder?
    CoSTa recently posted…Zagar – Wings of LoveMy Profile

  • CoSTa, when you click Share, choose ‘Custom’ instead of ‘Full Quality’… you can then select the x264 Encoder instead of the default H.264 when you click ‘Settings’ next to Video.

  • I’m converting a file but I trust this will fix the problems I was experiencing. Many thanks!

  • Oh God, please, can you PLEASE do a tutorial on how to fix this ON A PC!!! I dont have a Mac, and I don’t use FCP. I use Premiere Pro. The gamma shift is draining ANY interest in uploading my video anymore.

    Please help, I’m so desperate and drained with this bug. You guys are so lucky to have it working on a Mac!

  • i found this amazing research on h.264 a blessing, for so long h.264 and quick time suck – first is there any chance you could do a breakdown of of HD uncompressed to x264 encode without loss of quality, i mean 1 to 1 1080p to 1080p. Also i tried to follow your suggestions and reference but still a little washed out – the first time i did it i was blown away but realized that i had -7 brightness filter in QT7 i removed it and got a little washed out HD animation, so seeing that -7 brightness filter gives me the closest i have ever seen to uncompressed hd animation i might have to go with that , if you could let me know what i have done wrong would be great.

  • Sterling, if you’re following these instructions exactly, the color should not shift… unless you’re monitor calibration is at 1.8 gamma or something.

    Did you make sure to insert the 2.2 gamma flag into the video? As I said in the article, adjusting the brightness in quicktime is not necessary.
    Andärin recently posted…Coors Brewery Tour- WAY More than Free BeerMy Profile

  • Thanks for this great article! I have been searching for a solution for this for years.

    I’ll be using this in all my upcoming videos.
    Nathan Strik recently posted…HardwareInfo TV Leader 2010My Profile

  • Thank you so so much for the super helpful post! It’s exactly what I was looking for.

    Problem is: I found a bug in the encoder. It inserts random frames in the video, out of order. Case in point: I was exporting a 4 min video, and at 3:28, it inserted a frame in between two shots. I went to FCP to see if I had erroneously left a frame there, but that wasn’t the case.

    I re-exported the video a second time, and this time it inserted a frame at random in between two shots at 00:20.

    It’s a great tool – the final image is indeed as contrasty as in FCP – but ultimately unreliable because of the random frame issue…

    Do you have any suggestions on fixes?

  • Actually, I managed to eliminate the problem the fourth time I exported the file: here’s what I tweaked

    – i selected the iPod Default preset
    – adjusted the frame rate under “behavior” (it was 23.98)
    – clicked on “3rd pass”

    Surprisingly, the resulting file is only 51MB (the first three attempts gave me a 251MB file, with the random frames)

  • @Nathan

    I’m really glad that this article helped you! Feel free to spread the word :)

    @Elena

    You’re very welcome! I Suspect that the frame rate was what was causing the problem. Because, according to the plugin author, 3rd pass is very useless and impossible to tell the difference from only doing 2 passes about 99.9% of the time.

    Have you tried doing the exact same fix you describe except not doing a 3rd pass?

    I’d be very interested to hear your results, and I know I’m not the only one.

  • I cant wait to test it!!!!
    BTW how did you find this plugin?

  • Thank you for this.

    I am normally not one to be too fussy with video quality. but the difference is DRASTIC between my FCP viewer and the QT export.

    @Dave

    did you ever solve the Youtube issue?

    anyone else have this youtube issue. and how about Vimeo?

    thank you again internet people.

  • So the solution is really to use x264, rather than a fix of H264. I did a test and it works well, but it seems that this really can’t be called a fix for the H264 problem since you’re using a different codec.

  • Actually Dale, H.264 is a video standard. While x264 is a free software library used to create H.264 video without the problems of some other encoders.

    This article is about how to create H.264 video in the best way possible.

  • Really nice article man. Very helpful.

  • I can’t believe you’ve solved this with this fantastic plugin. Can’t thank you enough. The washed out look with H.264 was SO SO SO frustrating especially with company logos and jpegs and now I never have to deal with it again!!!… plus the export is even faster than H.264! Crazy good!

  • Hey–this is GREAT, but I’m wondering if there is a way to use this encoder from within Handbrake, when I’m having to rip DVDs?

  • @TonyW & Pearl

    So glad you’re finding the solution useful! It took a while to test the different configurations and then to write this article, so it’s very encouraging to hear the people continue to benefit from my many hours of testing.

    @Kirk

    As far as I know, there’s no way to do this since the encoder is built into Handbreak. However, the Handbreak guys may have a work-around. You could post on their forum and ask.
    Andärin recently posted…How Sharing Your Unique Gifts Honors Your Era- Your Soul- and Your PlanetMy Profile

  • Love it! Thanks for this. One little problem though. I have a red bar that still lose quality. I used all the settings you provided on here and everything, the red bar still sucks! Here’s an image showing the issue:
    video_compression.png

    Is there a way to fix this? Thanks!

  • Excellent question, Alex.

    Simply put, red can be tricky. Some of the best codecs I’ve ever used still distort red objects or make them blurry. And I’m not entirely sure why.

    In this case, you’ve clearly lost saturation in the red bar in the video. I have a few questions and then a few things you can try.

    1. Just to make sure, I must ask: Did you click the “add 2.2 gamma” box in the encoder?
    2. In the first dialog box (before you clicked “options”), did you choose under encoding “Best Quality Multi-Pass”?
    3. What application are you exporting from? After Affects directly or opening up an exported AE mov into QT pro and exporting it from there?

    Here are some things I’d try: apply a filter to the video that increases contrast in the red area of the spectrum. If your editor doesn’t have fine color controls, try increasing the saturation of all the colors. Or, if that red bar is an imported graphic, bring it back into your graphics editor and make the red bar more saturated. You could also try upping the bitrate.
    Andärin recently posted…How to Post-Process your Travel Photos in 3 Steps with Stunning ResultsMy Profile

  • Hi!

    Thanks for the excellent tutorial. I, however, seem to still have the washed out-problem. In our production we use both PCs and Macs so it has to work on both platforms. I used one of our macs and installed the x264-encoder and followed your instructions to the point. The video looks absolutely great on any of the macs, but playing the video on the PCs gives me the same washed out gray results as usual. The only way I can make them look good on the PC is by using the “straight alpha”-hack.

    Any ideas?

  • @Sebastian

    Those results are very unusual. First, have you tried it on another PC?
    Also, have you tried updating Quicktime on that PC?
    Does it exhibit the same problem on a mobile device like an iPod or iPhone?

    Have you tried exporting with Compressor instead of Quicktime Pro?

    Quicktime is supposed to honor the ICC profile embedded in the video, otherwise colors wouldn’t be consistent anywhere. Try each of those things I mentioned, in order.

  • Hi Andärin,

    quick question about the codec as I’m having some unbelievably frustrating problems. The x264 codec’s installed, I’ve followed all the steps you provided to the letter and still when I export from Final Cut Express, it looks exactly the same as if i’d used the H.264 codec when opened in quicktime pro, or anything else. The whole thing looks lighter and slightly washed out. I’ve tried messing around with the settings for hours testing different things, but the result’s still the same. Even in the preview in Final Cut it looks fine before I export. Just when it’s all done, the result’s still washed out and lighter etc.

    No idea what to do now really. Any suggestions?

  • Hi Matt,

    That does sound frustrating. Let’s see what we can do. There are a few things I would try, in this order:

    1. Are you choosing “x264 Encoder” and not “H264″ under “compression type”? This may sound obvious but it’s easy to confuse the two.
    2. Have you tried rebooting and then doing it all over again? Sometimes OS X needs to be restarted when you install a new codec.
    3. If you’ve chosen “x264 encoder” and have rebooted, try checking the “add gamma 2.2″ checkbox” under the “tagging” tab.

    Let me know how it goes! And good luck :)
    Andärin recently posted…What 3-Year-Old Me didn’t know about Wielding Power & Creating FreedomMy Profile

  • It just doesn’t seem to be working for some reason. I tried all those things yesterday, numerous times, and it’s still coming out the same. Are there any other things you can think of trying, or any other things that might be causing it? I honestly can’t think of what else to try now :s

  • Hi Andarin, I worked with Matt on our film and we finally got it working! We didn’t change anything, but just left the computer over night. Anyway, a huge thankyou, you’ve been a lifesaver in helping with this and the new footage looks 100X better than the washed out version: http://vimeo.com/33340378. Thanks again!

  • @Matt
    What is your playback method? Make sure that Quicktime player settings have the “enable final cut studio color compatibility” checkbox UNCHECKED. (This is kind of a cheat that apple never should have implemented.) Also, try exporting your project in the Apple Intermediate codec, then open that resulting file in Quicktime Player, and try exporting as x264 from QT Player. Be sure to DOUBLE check all of the settings since they all count.

    @Tom
    You just left it overnight! Weirdsville. You didn’t reboot or anything? Anyway, so glad it’s working for you! I really enjoyed the shortfilm, and I’ll be tweeting out about it soon. So glad I was able to help!

Leave a Reply

CommentLuv badge