Video encoding strategy for all Apple devices

Video encoding strategy for all Apple devices

I’ve had an Apple TV for a number of years, along with an iPod Touch and now (finally!) and iPhone. Before I had any of those things I made a conscious decision to transfer all my CD’s to iTunes and change the way I manage and access my music. This was clearly a success, as I can’t remember the last time I got one of my CD’s out of its case, (come to think of it, I can’t even remember where my CDs are!).

This setup was ideal. The music was wherever I wanted it to be: Streamed through the Apple TV, played off a PC or laptop, or copied to my iPhone. This got me thinking, “why can’t I do the same with my DVDs?”. With the cost of storage being so low I bought myself a 2Tb Lacie drive with that very same thought in mind.

The first problem I ran into is that encoding movie or TV shows is very different to ripping a CD. It’s by no means streamlined or built into the iTunes interface. Hopefully one day this will change (in my crazy utopian vision of the future), but for now we’re stuck with it. I’ve spent quite some time finding the best approach, so I thought I’d share the final solution here.

My aim was to approach the encoding of video for iTunes with the same approach I took with my music: I wanted the quality to be such that I wasn’t aware I was listening to compressed audio (hence my decision to use AAC at 192 or 256kbps). The challenge was to encode the video such that I wouldn’t be distracted by the difference in quality from the original DVD. The aim was to create a library of video (movies and TV shows).

My other aim was to only encode the video once: to produce one file that would play back on the Apple TV, iTunes and iPhone. In theory this aim should be easy to be achieve, but with my background in video production I was unwilling to compromise on quality: the videos had to be full frame, full framerate. Not re-sized in any way. This proved to be a bit of a challenge for the iPod and iPhone, but it is possible.

The final aim was to reach some realistic tradeoff between quality and filesize. This was not only to save my HDD from exploding, but also to keep within the specifications for the iPhone/iPod which couldn’t handle high bitrate video.

I’m both a PC and a Mac user, and for convenience I manage my iTunes library on my PC. I’m using the freely available Handbrake software to encode the videos, which is available for both Mac and PC – so don’t be put off by the screenshots. This solution is multi platform. This article was written for Handbrake v0.9.3 (PC).

Please note that both the PC and Mac versions of Handbrake do not allow encoding directly from encrypted/commercial DVDs. I’m not going to discuss how you get around this limitation – but there are plenty of solutions. Google will help you find them ;o)

So (finally) here we go:

  1. Firstly, download and install Handbrake from the web. When you run the application you’ll see a number of built in preset, including ones for our target devices. The problem is that these built in presets only target individual devices (i.e. videos encoded with the Apple TV preset will NOT work on your iPhone). The built in presets for the iPod and iPhone significantly resize the video for those devices, which in turn look bad when played on the Apple TV.
  2. Select the preset “iPhone and iPod Touch“. This is a good starting point for our custom preset, as we know this preset will work with the lowest common denominator in our system: The iPod.
  3. Under the “Picture Settings” tab change the “Anamorphic” setting to “Strict“. This will force the videos to be encoded anamorphically which will help increase the quality at a lower bitrate. The strict mode also forces the video to be encoded at the exact same frame size as the source. For Europe/PAL videos this will be 720×576 pixels, and USA/NTSC DVDs it will be 640×480 pixels. You may have spotted that those pixel ratios are actually 4:3, not 16:9. Anamorphic widescreen works by squeezing the 16:9 image into a 4:3 frame, which is then stretched during playback. This is how DVD players display 16:9 content, and we want to use the same method here. Our encoded videos will technically be 4:3, but with instructions to the players to stretch the image during playback. It’s also worth noting that 720×576 is beyond the specifications for the iPhone and iPod (according to Apple), but the videos playback fine without problems. Trust me :o)
  4. Under the “Video” tab enter “1900” as the “Avg Birtate (kbps)“. This is the parameter I’ve spent the most time experimenting with: 1900kbps will give you a decent trade off between quality and filesize. If you want to increase this be my guest, but be aware that the iPhone will not accept videos over 2500kbps.
  5. Under “Audio and Subtitles” you may wish to add a second audio track with the original AC3 (5.1 surround sound) track from the DVD. Currently only the Apple TV supports playback of this 2nd audio track, but it makes such a difference to watching movies that you may wish to include it. It will increase the file size a little. (Note that under my PC version of Handbrake you can’t add this 2nd track unless you open a DVD – with AC3 – to start with. Just open a DVD and go back to step 2)
  6. Finally (and after much tweaking) there’s a few extra parameters under the “Advanced” tab you may wish to change:
    1. Reference Frames = 3
    2. Sub-pixel Motion Estimation = 7
    3. Deblocking = -2 | -2
      (The deblocking has the most impact. The encoding process blends the edges of the individual DCT blocks to make encoding artifacts less noticeable – however I feel it blurs the video too much. To make the final video closer to the original DVD I’ve found that this setting does the trick – particularly with widescreen video.)
  7. … and that’s your lot. Save the preset and give it a friendly name. You’re all set to encode high quality videos that will playback on all your Apple devices.

handbrake-screenshot1

Because of the nature of these settings, this solution will work for both NTSC and PAL DVDs. I haven’t tried the preset with 4:3 TV shows yet – nor have I worried too much about interlacing. I find the best strategy is to do a quick test encode of a video you’re unsure about. If it needs it, apply the “deinterlace” filter or change the “anamorphic” setting to “none” if necessary. I’ve not needed to do either of these things yet.

For the encoding of TV shows I find it best to copy the DVDs to my HDD before encoding, and then set up a batch list in Handbrake so it can crunch away overnight.

The step after encoding is of course to import them into iTunes. I’ve been using iTunes to edit all the meta data (and IMDB for the source of that data). It’s a bit tedious, but well worth it. If you’re using a Mac you may want to look at getting MetaX for this step. I haven’t used it, but it looks ideal and has plenty of good reviews. (There is a PC version, but give it a wide berth for now!)

You may be surprised at the bitrate, given that it’s less than 2Mbps. To be honest, I found this to be more than adequate for my needs. You also need to consider the source material. Most commercial DVDs encode the video at between 2-4 Mbps MPEG-2. The codec we’re using (H.264) is more complex than MPEG-2, and more efficient at compressing video to lower bitrates. With that in mind, it’s clear that anything over 2.5Mbps is unlikely to yield better results. After all, the only purpose for these videos is playback – not editing or re-encoding.

So there you have it. I’m certainly happy with this setup. I’ve encoded about 30 of my movies using it, and I’m working my way through 4 seasons of Battlestar Galactica using both the Apple TV and iPhone for viewing. The files can be a little large of the iPhone – but for the convenience of not having to re-encode the video it’s fine. Also, if you own an AV cable for your iPhone you’ll be amazed at the quality of these videos on playback!

If you have any suggestions feel free to add them to the comments. Also, please let me know if there’s any specifics for the Mac version that I missed.

Enjoy!