Thursday, August 07, 2008

Videos for iPod Touch, Part 2

In Videos for iPod Touch, I talked about my sleek-looking new iPod Touch 8G:

No, I said, it's not an iPhone, but iPhones are wait-listed right now.

The iPod Touch shares with the iPhone the ability to sync with iTunes and play video movies and TV shows, music, podcasts, etc. But not all videos that iTunes (or my Apple TV) will play can go onto the iPod — even though the offending videos are nominally in the MPEG-4/h.264 format that the iPod expects. I expect other iPod owners have the same kinds of problem. This post is about ways around the problems.

There are actually two kinds of problem here:

  1. If a video has been encoded with a video bitrate of over 1500 kbps, the iPod won't sync to it or play it.
  2. The iPod can't sync to or play videos that have been encoded with B-frames, space saving representations of individual video frames that record differences between themselves and following frames (and from preceding frames, but that's not a problem).

The iPod simply doesn't have enough memory or processing power to cope with high-bitrate videos or with deriving current frames from following frames in the video stream.

One solution to either incompatibility problem is to re-rip the video from an original DVD. I use HandBrake to port videos from DVD to iTunes. HandBrake 0.9.2 (the current version) has several presets for iPod-compatible rips. The one which I use a slightly modified version of is "iPod High-Rez." Any of the iPod-related presets will work, in that they carefully avoid giving you B-frames and video bitrates in excess of 1500 kbps. (They also insert the mysterious "iPod atom," making the output compatible with pre-Touch video iPods.)

However, I recommend that you modify the preset, as I did, to turn on Anamorphic: Strict under Picture Settings. This allows your output file to use "anamorphic encoding" if the DVD itself does. For more on what that means, see below.

The second workaround for getting a non-iPod-playable video to play on an iPod is to do a conversion of an existing rip into a form that works with iPod.

The simplest way to do a conversion is to select the movie or TV show in iTunes and select "Convert Selection for iPod/iPhone" in the Advanced menu. iTunes will verify that the video is not already iPod-playable, and if not it will start to convert it to an iPod-usable format — a lengthy process. The output file automatically goes into ~/Music/iTunes/iTunes Music/Movies (or ~/Music/iTunes/iTunes Music/TV Shows). The file name is the same as that of the original file, modified as necessary to ensure uniqueness. The original file is left untouched.

Using iTunes to do the conversion has several drawbacks:

  • The process is super-slow. It takes iTunes much longer to convert a file than it would take HandBrake to re-rip it.
  • You can't direct the output to any folder or hard drive you want. You have to be content with iTunes' default folder.
  • You can't name the converted output file anything other than iTunes' automatic choice of file name.
  • You can't control parameters like the resolution in pixels of the video frame. In my admittedly limited experience, iTunes seemingly insists on giving the output video file a frame width of 640 pixels, with a corresponding pixel height designed to reproduce the original's aspect ratio.
The second way to do a conversion is to use QuickTime Player. That allows you more control over such things as the destination drive and folder, the output file name, the video resolution, and other useful parameters. But, like iTunes itself, QuickTime is slow, slow, slow.

I'm currently investigating a third alternative: using a third-party video converter.

I'm presently trying the $29 ImTOO iPod Video Converter for Mac:

ImTOO's website says it "can convert video and audio files such as AVI, MPEG, WMV, DivX, MP4, MOV, XviD, VOB (the video format used in DVD), MP3, AAC, AC3, etc., to iPod supported formats, including MP4, MOV, MP3, and M4A."

I have just begun to experiment with ImTOO, and I find it pretty much works as advertised. And it's fast ... as long as it isn't butting heads with a HandBrake DVD rip, in which case it slows down to a crawl in favor of HandBrake.

Still, I have found at least two of my HandBrake rips that ImTOO's conversion attempts stall out on. At least using the settings I have tried, ImTOO gets to a certain point in the conversion and then just sits there ... forever.

One drawback with ImTOO is that MPEG-4/h.264 conversions for iPod are automatically given the .mp4 file extension, which means they automatically open in QuickTime Player, when double-clicked in the Finder. The .m4v extension, allowing automatic opening in iTunes, would be better.

A second drawback with ImTOO is that if your original file was created by HandBrake with chapter stops/names, ImTOO won't carry them over to the converted file. Bummer.

Another ImTOO drawback, one that applies to other third-party converters I've tried as well, is pretty technical, so bear with me as I try to describe it. I'm going to present this somewhat technical discussion in blue, in case you want to skip it. I'll also indent it.

I have an existing rip of Harry Potter and the Prisoner of Azkaban that HandBrake made some time ago. Its video frame dimensions (per iTunes' Get Info Summary) are 853x360 pixels. This means that if I play the video in iTunes or in QuickTime Player, I'll see it in a frame that is 853 pixels wide by 360 pixels high. 853:360 corresponds to the aspect ratio of the Potter movie on DVD.

Yet if I play the video in QuickTime Player, the player's Inspector window says (under "Format") that the video frame is only 720x360! What accounts for the discrepancy between 853 and 720? And why is the default-size QuickTime viewer window actually 853 pixels wide, not 720?

The solution to this mystery is that the HandBrake output simply reproduces the 720 pixels that are physically present in each row of each video frame on the DVD. But HandBrake also detects that the widescreen DVD was "anamorphically encoded" — formatted especially for widescreen TVs — such that the DVD player stretches the 720 pixels provided per row into the space of 853 pixels, thereby widening the frame as it is being viewed.

Handbrake also detects that the nominal 480 rows of pixels in each video frame on the DVD is actually only 360 useful rows. The remaining rows at top and bottom of the screen are not even coded; they are played as black letterboxing bars. Since they're not coded on the DVD, they don't need explicit coding in HandBrake's output, either. So HandBrake outputs an MPEG-4/h.264 file that has video frames of 720x360 pixels. These 720x360-pixel frames are intended to be displayed as if each frame had 853x360 as its true dimensions.

(For a clear discussion of anamorphic encoding in general and how HandBrake deals with it, see "Guide to Anamorphic Encoding in HandBrake.")

In other words, the HandBrake output is anamorphically encoded, just like the input from the DVD. Anamorphic encoding simply means that (in this particular case) a 720x360 pixel grid is stretched at time of playback to fill an 853x360 frame.

Yet when ImTOO converts the anamorphically encoded HandBrake-ripped video, it doesn't retain the anamorphic encoding. Instead, when ImTOO is set up to use an output video size of 853x360, it internally expands the 720x360 pixels in each input frame to fit into an 853x360 box and then uses that box to derive a non-anamorphic 853x360 output file.

(Actually, the ImTOO conversion fails unless the output video size is trimmed by a single pixel to 852x360! Apparently the two numbers surrounding the "x" have to be even.)

I have found that the only way to keep the original aspect ratio and also retain all the input file's video detail is to enter iTunes' video dimensions for the input file into ImTOO's Video Size field in the "Advance" settings. In the example of Harry Potter and the Prisoner of Azkaban, that's 853x360 — trimmed to 852x360 — not the unstretched 720x360 shown in QuickTime's Inspector window. Setting the ImTOO video size to 852x360 seems to be the only way to preserve the aspect ratio of the original video frame, for this particular movie.

When ImTOO is set up to retain all the detail in the original video file and preserve the same aspect ratio, it uses more pixels in the video frame, hence contains more bits in the output file, than it really needs to. This is because ImTOO can't produce an anamorphically encoded output file even when the input file is anamorphic. So its output, in this example, has video frames whose dimensions in pixels are 852 horizontally by 360 vertically.

Unfortunately, all that careful manipulation of ImTOO's conversion parameters results in an output file from ImTOO that iTunes won't sync to the iPod Touch! The output file plays in iTunes, on Apple TV, and in QuickTime Player ... but won't work with the iTouch. My guess is that the 852x360 video frame contains too many pixels to be iPod-acceptable.

A workaround to that problem might be to use, say, 720x304 as the output frame size in ImTOO. 720:304 is basically the same aspect ratio as 852:360. When ImTOO uses a video size of 720x304 for this movie's conversion, the output file syncs to the iPod just fine.

Trouble is, there are now only 304 pixels of vertical resolution in the picture, not 360 pixels vertically. The difference is not noticeable on the iPod, whose screen resolution is only 480x320 anyway. But the video looks much softer on my Apple TV-fed HDTV.

Yet I have found that this strategy of reducing the vertical resolution to preserve the aspect ratio is what at least one other converter I've tried, TechSpansion's
VisualHub, does by default when converting videos for the iPod Touch. It is a sensible choice, given that VisualHub, like ImTOO, cannot retain anamorphic encoding.

In fact — please note this well — the only reason I have any objection at all to this conversion strategy used by ImTOO and VisualHub is that I prefer to end up with a single video file that has all the resolution of the original DVD and plays on Apple TV as well as on iPod.

Yet the only way I have found to do this is to use anamorphic encoding that is honored by iTunes, Apple TV, and iPod ... and none of the converters I've tried so far can do that. HandBrake alone seems to be able to produce anamorphically encoded output that works with all my software and all my devices. That is why I plan to re-rip all my existing iPod-incompatible DVD rips with HandBrake, rather than converting the existing rips with ImTOO or VisualHub.

Note: ImTOO has in its advanced options, in addition to the Video Size parameter, an Aspect parameter. If I set the former to 720x360 for the Potter movie and the latter to 2.37 (852 ÷ 360), I get output that mimics the input when played in QuickTime Player. That is, it shows as 720x360 under Format in the Inspector window, while actually playing as 852x360. Thus, it would seem to be anamorphically encoded. However, neither iTunes nor the iPod will play it at 852x360, only at 720x360, which gives the wrong aspect ratio and distorted image geometry. I have no idea why iTunes/iPod honor the anamorphic nature of the HandBrake-ripped file but not of the ImTOO-converted file.

OK, that's the end of the admittedly technical discussion about various iPod video converters' lack of support for "anamorphic encoding" that works in all my software and in all my devices. There is, however, an important lesson to be learned from that discussion, one that all iPod Touch owners need to hear. It is this: contrary to what you may have heard elsewhere, the iPod Touch (and presumably the iPhone) can play videos that have more pixels in the video frame than the nominal 480x320 screen resolution of the playback device, the iTouch or iPhone, can display!

iPod Touch videos can have more than 640 pixels in their video frame width, which I previously thought to be the maximum number of bits allowed! I don't know what the true upper limit is as yet, but it's at least 720 pixels of horizontal resolution! (There may also be an upper limit, at present unknown, on the product of the horizontal resolution in pixels and the vertical resolution in pixels.)

Of course, you'll see at best only 480x320 resolution on the iPod itself. But the same file can be played on, say, Apple TV with full resolution. Cool!

No comments: