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:
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.
And 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?
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
- Download the plugin on Takashi’s site. (UPDATE: A kind reader has informed me that Takashi’s site is down, but I did some digging and the plugin is still available on the archived version of his site.)
- 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.
- 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.)
- 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
- In Final Cut Pro, choose:
- 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:
Render Settings: Quality: Normal
MPEG 4 AAC LC Encoder Settings: Target Bit Rate: 160kbps
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.)
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:
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:
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
If 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.)
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.
Now that you’ve set the gamma, your settings are complete!
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: