How-Tos

Final Cut Pro X Tutorial: How to Get Better Encoding Results


When you compress video for on-demand streaming, you primarily care about three things; quality, quality and… let’s see, oh yes, quality. If you’re been encoding H.264 video with Apple Compressor using the codec that Apple provides, you definitely haven’t been optimizing the quality of your video. In this tutorial, you’ll learn how to install and use the x264 codec within Apple Compressor, which will improve the quality of your encoded video, particularly at lower data rates.

Figure 1. The x264 codec on the left, Apple on the right in this HD test clip.

Figure 1. The x264 codec on the left, Apple on the right in this HD test clip.

Note that this tutorial will focus exclusively on using the x264 codec within Compressor; it’s not a comprehensive tutorial on how to use Compressor to produce H.264 files. For an overview of using Compressor, check out this video tutorial “Producing H.264 files for Flash distribution with Apple Compressor.” It’s not directly on point, in that it covers using the Apple codec, not x264, but it will provide an overview of Compressor’s encoding workflow. For an overview on H.264, check out the tutorial “Understanding the Key H.264 Encoding Parameters.”

About H.264: What It Is, Why You Should Use It

Let’s start with some background. H.264 is a video standard adopted by multiple standards organizations, and there are multiple H.264-compliant codecs available on the market, including Apple’s, x264, and others. Significantly, x264 is an open source and free option that’s been rated as the highest quality H.264 codec for the last few years in the highly-regarded codec comparison published annually by Moscow University.

In contrast, the Apple codec lacks critical features like support for the High profile or CABAC entropy coding, and produces much lower quality than x264, though the difference is most noticeable at aggressive encoding parameters. For example, Figure 1 shows how the x264 codec compares to Apple’s when encoding my standard 720p test file to 800kbps. To be clear, I produced both in Compressor, the file on the right using the Apple codec and the file on the left using the x264 codec.

As you can see, the Apple codec looks faded and preserves much less detail. Figure 2 shows a similar comparison when encoding an SD file to 640×480 resolution at 468kbps. Again, in this high motion shot the Apple codec looks faded and preserves much less detail.

Figure 2. The x264 codec on the left, Apple on the right in this SD clip.

Figure 2. The x264 codec on the left, Apple on the right in this SD clip.

 

Of course, the quality differential will vary according to the source content and the encoding parameters that you use. For example, Apple encodes some of the marketing videos shown on its website at 848×480 resolution with a video data rate of 1.9Mbps, which is quite high. At these parameters, any H.264 codec will look great. However, if you’re seeking the best possible quality at the lowest possible bitrate, x264 is a much better option than the Apple codec.

In addition, beyond the quality issue, Compressor provides no control over common H.264 encoding parameters like B-frame interval or even the direct ability to choose the H.264 profile used in the file. You get all this and more with the x264 component discussed below.

Downloading and Installing the x264 Component

There are multiple QuickTime components available; the one I recommend is from a site called MyCometG3, which was run by Japanese developer Takashi Mochizuki. Note that Mochizuki discontinued additional development on the component at the end of 2011, so the code is frozen as of that date. This means that as the x264 development community advances the codec further, you won’t get the benefits of these advances.

That being said, the existing download available at MyCometG3 is current as of 12/30/2011. As far as I know, this is the most advanced x264-based implementation available that you can operate in Compressor. I used this update to encode the x264 files shown in the figures above, so obviously this component produces much higher quality than the Apple codec.

When you click the download link on MyCometG3, you’ll download a DMG file that you can double-click to open. Within the contents you’ll find a file named x264Encoder.component. Copy that into your Library/QuickTime folder, and the next time you run Compressor (or QuickTime for that matter) the x264 codec will be available as shown below. Though you probably won’t need it, here’s a video showing you where to copy the file.

Using the x264Encoder

To use the x264Encoder within Compressor, you can change the codec in an existing preset or create a new preset; I’ll show the latter technique. In Compressor’s Settings window, click the Create a New Setting list box and choose QuickTime Movie, which opens a new setting in the Inspector window.

Figure 3. Creating a new QuickTime Movie Setting.

Figure 3. Creating a new QuickTime Movie Setting.

 

In the Inspector window, name the setting something memorable. I usually include both the codec and the target output. Then, click the Video button to open the Standard Video Compression Settings dialog. Click the Compression Type list box and choose the x264Encoder.

Figure 4. Choosing the x264Encoder.

Figure 4. Choosing the x264Encoder.

 

Next, click the Options button to open the libavcodec settings dialog. While the settings are very comprehensive, there are only one or two that you need to adjust, which I’ll come back to in a moment. First, click Load preset on the bottom left to load an encoding preset.

Figure 5. The libavcodec settings dialog with the myriad options enabled by the x264Encoder.

Figure 5. The libavcodec settings dialog with the myriad options enabled by the x264Encoder.

 

Briefly, the developers of x264 created the ten presets shown in Figure 6 to enable x264 users to simply and easily balance encoding time against quality. You’ll see the same presets whether you access x264 via plug-ins like x264Encoder, free programs like Handbreak, or professional encoding tools that offer x264 encoding like Sorenson Squeeze or Telestream Episode. As with these tools, when you choose a preset, the x264Encoder applies a certain set of parameters which you can later customize. If you’re interested, here’s a complete breakdown of the encoding parameters used in each preset and some performance (but not quality) comparisons.

I produced the file comparisons shown in Figures 1 and 2 using Medium preset, which is the default preset, and one that I find represents the best balance of encoding speed and quality. Note that if you choose slower presets you increase the risk of creating files that may not play on your target platforms.

Figure 6. Choosing an encoding preset.

Figure 6. Choosing an encoding preset.

 

As an example, if you encode using the Slower preset, the encoder uses 8 reference frames. If you scan through the readme file included with the x264Encoder download, you’ll note that files with over 6 reference frames may not play in older versions of QuickTime. To avoid potential problems like these, it’s best to use the Medium preset unless you’re certain that you can correct any potential problems before encoding.

In addition to choosing a preset, you can also choose an x264 tuning option as shown in Figure 7. On its website, Zencoder, a cloud encoding facility that uses the x264 encoder, explains the tuning options as follows:

Possible values:

  • Film: optimized for most non-animated video content (not only feature films)
  • Animation: optimized for animation. Note that most 3D animation behaves more like film and not like hand-drawn animation, so only use this for hand-drawn animation (anime, classic Disney, etc.)
  • Grain: optimized for film with high levels of grain
  • PSNR: uses “peak signal-to-noise ratio” to optimize video quality
  • SSIM: uses “structural similarity” to optimize video quality
  • Fastdecode: reduces encoding complexity to allow for easier decoding
  • Zerolatency: x264 will keep an internal buffer of frames to improve quality; this setting removes that buffer, but reduces quality
Figure 7. Choosing a tuning option.

Figure 7. Choosing a tuning option.

 

In general, if your video falls in one of the first three categories, or is a Touhou game, you should apply the fine-tuning option. Otherwise, I’d recommend you choose None.

Once you choose your preset and tuning option, click OK to close that dialog and return to the Libavcodec settings screen shown in Figure 5 (and again in Figure 8, below, for convenience. Here’s where you can customize one or two specific parameters for your target playback platforms. For example, if encoding for older mobile devices, you should limit the H.264 profile to the Baseline profile. Unless you absolutely know what you’re doing, I would leave all other parameters at those selected by your preset.

Figure 8. Customizing H.264 encoding settings.

Figure 8. Customizing H.264 encoding settings.

 

When you’re done, click OK to return to the Standard Video Compression Settings screen. In general, you can configure these and all other Compressor settings as you have in the past.

Figure 9. Finalizing your video encoding parameters.

Figure 9. Finalizing your video encoding parameters.

 

Any time you change codecs or encoding parameters, there’s a potential compatibility risk. Remember, however, that since YouTube, Zencoder, Sorenson, Telestream, and many other companies use the x264 codec, there’s nothing inherently wrong with the codec; if there is a problem, it almost certainly relates to your settings. You can minimize the impact of any incompatibility by testing the first few files that you encode on all relevant target platforms.

Note that potential incompatibilities are most likely on devices that have the least tolerance for out-of-spec video encoding. Test tablets and other mobile devices first.




Discussion

Comments for “Final Cut Pro X Tutorial: How to Get Better Encoding Results”

  1. Nice post. I like finding any posts and info on the web about using x264, especially with quicktime or FCP X.

    I am starting to be concerned though about using this codec in the future as development has ceased on the qt component. I know Squeeze and Telestream keep it updated for their products but I much rather export directly from Final Cut than having to create a master file.

    Posted by Paul | January 19, 2013, 6:55 pm
    • Paul:

      I hear you. I was sad to hear that development had ceased, but the quality is still so much better than Apple’s codec that it’s still recommended for those outputting from Compressor.

      I’ll see if I can compare x264 output via this technique and from Squeeze or Episode in the next few days. I’m guessing that at this point, it will be pretty similar, but that’s just a guess.

      Thanks for your post.

      Jan Ozer

      Posted by Jan Ozer | January 20, 2013, 1:25 pm
  2. Thank you very much for this post!!! The most usesful information I’find about this problem of Final Cut & Compressor

    Posted by Vladimir | May 27, 2013, 7:07 pm
  3. Would you mind adding an addendum to your excellent article that gets more specific about ideal optimizations for preparing video to be uploaded to YouTube?

    Right now your article makes two mistakes with regard to YouTube Uploads. YouTube recommends:

    1) Turn OFF Frame Reordering
    2) Leave Data Rate to AUTOMATIC

    More details here: http://tinyurl.com/m6rt7to

    Thanks.

    Posted by James Wages | June 30, 2013, 9:10 pm

Post a comment