Monday, August 04, 2008

Videos for iPod Touch

My new iPod Touch 8G (for 8 gigabytes of storage) is a $299 marvel. Sleek-looking, too:

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

The iPod Touch shares with the similar iPhone the ability to sync with iTunes and play videos, music, podcasts, etc. The videos can be movies or TV shows downloaded from the iTunes store. Or they can be videos you yourself have created, including those you have ripped from your collection of DVDs (see earlier posts in my Ripping DVDs series for more on that).

I have an extensive library of movies (and TV shows) that I have ripped from DVDs, usually using HandBrake. They were converted by HandBrake from the MPEG-2 format used on DVDs into the MPEG-4/h.264 format, the increasingly common format used in Apple products: iTunes, Apple TV, and the iPhone and video iPods, including the iPod Touch.

Only problem is, some of my MPEG-4/h.264 videos which play fine in iTunes and on my Apple TV can't be copied to my iPod Touch. When I try to sync them, I get an error dialog such as this one:

Some of the videos in your iTunes library, including the video "Notorious", were not copied to the iPod "Eric's iPod Touch 8G" because they cannot be played on this iPod.


Expanding the dialog box reveals:

"Notorious" was not copied because the video format is not supported by the iPod "Eric's iPod Touch 8G".


I have learned that there are three usual suspects:

  1. The video file does not contain an "iPod atom."
  2. The video file was encoded with "B-frames."
  3. The video file has too high a video bitrate, over 1500 Kbps.

Of course, if any of the videos are not shown in iTunes' Get Info Summary panel as being of kind: (Protected, or not) MPEG-4 video file using video codec: H.264 with profile: Low Complexity, then that would be yet another problem entirely. Other formats/codecs/profiles are not iPod-playable.

Whether or not an MPEG-4 video file is "Protected" — copy protected, that is, per the iTunes Store's Digital Rights Management protocols — makes no actual difference to iPod playability. The files your get from the iTunes store will be protected, of course, but they'll work fine on an iPod Touch. The files you rip from DVDs will not be copy protected at all. But to also work fine on iPod Touch, a video file you make yourself must be MPEG-4/h.264/Low Complexity, and it must adhere to certain extra rules.

HandBrake knows about all these rules, and if you use one of HandBrake's built-in iPod presets — I recommend "iPod High-Rez" — you'll always get an output file that is iTouch-compatible.

But several of my "legacy" rips aren't iTouch-compatible, as it turns out. Some of them were ripped by an earlier version of HandBrake (the current version is 0.9.2) that didn't always make iPod-compatible output files. At that time, I had no idea about any restrictions on iPod compatibility, and didn't really care. I was primarily interested in getting the best possible results for my Apple TV. Now, I wish I had had more foresight.

Anyway, here is more about the three usual suspects:

1. What is the mysterious "iPod atom"? It is apparently nothing more than a sequence of bytes that starts with the four hexadecimal characters 'uuid' followed by the parameter '1200', also in hex. This goes into the so-called "MPEG-4 file container" as "metadata." It magically allows iTunes to sync the video to certain picky early video iPod models (but not the iPod Touch or iPhone, which ignores the "iPod atom").

For early video iPod owners: if a video file's only flaw is the lack of an iPod atom, I am given to understand that AtomicParsley can help. According to this discussion, one can download and install a certain special version of AtomicParsley and then use the following command line in Terminal to insert an iPod atom in any MPEG-4 video file:

AtomicParsley OUTPUT.mp4 --DeepScan --iPod-uuid 1200 --overWrite

where OUTPUT.mp4 represents the name of the video file. You need to change OUTPUT.mp4 to the name of the MPEG-4 file you wish to modify. It's best to copy the original file and work only with the copy. (I assume the extension .m4v, where applicable, works also.)

I tried this with the 0.9.0 version of AtomicParsley, which is the only one I could actually find on the Internet. It simply did not work at all as an inserter of iPod atoms. Then I read the discussion referenced above a bit more closely and learned that I really need a certain "subversion" of AtomicParsley that does support this procedure. Unfortunately, I could not locate that subversion.

However, I am also led to believe that the "iPod atom" is needed only for the so-called 5th-generation and 6th-generation video iPods, the ones with the truly tiny video screens, that came along prior to the iPod Touch and the iPhone. The iTouch and iPhone don't care about the presence or absence of the "iPod atom," one way or the other.

2. MPEG-4 videos can optionally use so-called "B-frames." When they do, no iPod model to date can play them.

B-frames are "bidirectional," in that they are streamlined video frames that represent only the video information that has changed in that particular frame, compared to a prior video frame or a following video frame. B-frames make for smaller MPEG-4 files, because the ability to key off a later frame, not just an earlier one, can result in there being far fewer bits in the file.

Forcing the MPEG decoder to scan ahead to look at following frames, though, is not supported for iPods. It requires too much memory and too much processing overhead. However, iTunes can do it; so can the Apple TV.

If you rip a DVD especially for Apple TV in HandBrake, HandBrake will use B-frames ... and the resulting output file won't play on an iPod, no matter what you do.

3. Every MPEG-4 file has a certain "total bitrate." If you look at iTunes' Get Info Summary for the file, you'll see both a bitrate (such as 159 kbps) and a total bitrate (such as 1657 kbps). The first is how many bits (or thousands of bits) per second are used for the audio. The latter is how many are used for the video and audio, together. If you subtract the former from the latter you'll get the video bitrate, in this case, 1498 kbps. It has to be 1500 or less to work on an iPod.

(Actually, I seem to have some files where the crucial figure is just a little over 1500 kbps, but the videos play OK on my iPod. I can't explain why this is.)


So those are the three "usual suspects" that can keep an otherwise good MPEG-4/h.264 video file from working on an iPod Touch or iPhone. The first doesn't actually affect the iPod Touch or iPhone, only earlier video iPod models.

The second and third affect all video iPods. If you have a file which uses either B-frames or too many bits per second for the video (or both) you'll need to do one of two things to get the movie, TV show, or whatever to work on an iPod. Neither choice is easy.

The first choice is to re-rip your video from scratch. It's the choice I recommend, where feasible, for reasons that will be made clear as I discuss the second choice in my follow-on post, Videos for iPod Touch, Part 2.

If you do elect to re-rip your video, you need to make sure you do it in such a way as to produce an iPod-playable output file. You need to include an iPod atom, assuming you are using an earlier-model video iPod (even if you aren't, including the iPod atom doesn't hurt anything). You need to make sure no B-frames are used in the output. And you must make sure the video bitrate is 1500 kbps or less.

If you are using HandBrake 0.9.2 to do the ripping, the easiest way to avoid going wrong is to use one of the included presets for the iPod or iPhone. These include:

  • iPhone / iPod Touch
  • iPod High-Rez
  • iPod Low-Rez

I find "iPod High-Rez" ideal for my purposes, as it automatically includes the iPod atom in case it's needed, spurns B-frames, and sets 1500 kbps as the maximum video bitrate.

I actually have created my own modified version of this preset, as I (owing to poor hearing) like to include English-language subtitles on all my rips. I strongly 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. More on what that means can be found in Videos for iPod Touch, Part 2.


The second workaround for getting a non-iPod-playable video to play on your iPod is to use special software to do a conversion. I'll cover that option in Videos for iPod Touch, Part 2.

2 comments:

Anonymous said...

I've finally managed to figure out how to encode videos for the iPod 5G partly through experimentation and this guide...

The mystery SVN link would be http://sourceforge.net/svn/?group_id=153768 . Follow the instructions to get the 0.9.2 version of AtomicParsley.

The rest would include simply encoding the video into h264 with the encoder of your choice which complies with Apples specifications of iPod video and get AP to insert this mystery atom. For me, my video encoder of choice is ffmpeg and i've managed to successfully encode(3 as of me discovering this) videos which sync and plays on the ipod. To achieve this, I've found these ffmpeg settings to work. `ffmpeg -i INPUT -vcodec libx264 -b BITRATE -acodec libfaac -ab AUDIOBITRATE -level 13 OUTPUT`. Replace the stuff in caps with whatever you want(following the Apple specs).

AP from SVN didn't seem too happy to compile even following the instructions due to an error with AP_NSImage.mm saying that _NSBitmapImageFileType isn't defined so I poped open my text editor and did a quick hack and replaced `_NSBitmapImageFileType` with `int`on line 204. After this quick hack, AP compiled happily. Although I really didn't spend any time to see what functionality this like of code corresponds to, I'm just gonna guess it's gonna blow up if I touch artwork or anything to do with bitmaps... As for a quick fix for getting videos on the iPod 5G however, I find this works.

Have fun ;3

You can send questions to NicholasChin666 [at] Hotmail [dot] com . I rarely check that but if your email doesn't look too much like spam and I just happen to see it, I can attempt to help you to the extent of my abilities...

Anonymous said...

Random typos and stuff, sry ;P

*syncs, link