Preparing Video for the iPhone
The iPhone is a unique platform for watching video. It has a large screen for a hand-held device--480x320--but still smaller than most computers. Unlike most computers, it's easy to switch the iPhone between portrait and landscape orientation, and the video automatically resizes to fit the screen. Even more unique, a double-tap toggles the iPhone between letterbox and zoomed video, so if the image is a different aspect ratio than the screen, it can be either letterboxed or zoomed and cropped.
The iPhone plays video and audio using MPEG4 standards--H.264 video and AAC audio. It supports only audio and video: no Flash, QuickTime VR, sprites, or other media types, so you need to prepare your media by compressing it to MPEG4 standard video and audio.
You can prepare video for the iPhone using several video compressors. I'll give you the necessary specifications to do it in any program, and show you how to do it simply using Apple's QuickTime Player (pro version, $30 registration fee).
Prepare an MPEG-4 Version of Your Movie
The iPhone plays MPEG-4 movies or QuickTime movies using MPEG-4 compression (H.264 video and AAC audio). The easy way to create an MPEG-4 version of your movie is to open it in QuickTime Player (be sure to download the latest version--7.2 or later), then choose Export from the File menu, and select either "Movie to iPhone" or "Movie to iPhone(cellular)".
"Movie to iPhone" creates a movie suitable for delivery over WiFi, and "Movie to iPhone(cellular)" creates a movie suitable for delivery over the EDGE cellular network.
Once you've made your selection, click OK and stand back. That's it. There are no options. "Movie to iPhone" creates an .m4v file and "Movie to iPhone(cellular)" creates a .3gp file. Both are sized for the iPhone screen and compressed to a suitable bandwidth.
For more control, you can choose Movie to MPEG-4 and click the Options button, then choose the H.264 video compressor and the AAC audio compressor. In this case, be sure to click the Video Options button and select Baseline and Faster Encode, as shown below.
The iPhone doesn't support B-Frames, so there's no use doing a multi-pass compression that would create them.
Follow the same guidelines using any video compressor: H.264 baseline, no B-Frames, AAC audio, size no larger than 480x360.
Video Size and Aspect Ratio
To achieve the highest quality, your video should be at least as wide and tall as the iPhone display, so it's not scaled-up to fill the screen, which would make it blurry. That means a minimum width of 480 pixels and a minimum height of 320.
Apple recommends a size of 480x360 for standard 4:3 aspect images, because that's the smallest 4:3 image that's at least 480 pixels wide.
By the same reasoning, a 16:9 widescreen image should be 586x320, because that's the smallest 16:9 image that's at least 320 pixels tall.
At these sizes, your image will be scaled down slightly in landscape orientation, and scaled down more than slightly in portrait orientation, but when zoomed in landscape orientation, it will be actual size (though cropped).
Of course, you can send larger videos to the iPhone, and it will scale them down. It wastes bandwidth, but on a fast enough connection it works fine.
iPhone Video Display
Turning the iPhone switches it between landscape and portrait orientation, and the video reorients and resizes. Double-tapping it switches between letterbox and zoomed video, for images that aren't exactly 480x320.
In letterbox mode, the iPhone scales the video to just fit the screen while retaining its aspect ratio. If the aspect ratio of the movie is different than the screen (and it ususally is) there are black bars on the top and bottom or left and right sides.
For example, a 4:3 video shows at 427x320 in landscape orientation, and at 320x240 in portrait orientation. A 16:9 video shows at 480x270 in landscape orientation, and at 320x180 in portrait orientation. One of the dimensions is always 480 or 320. The other may be smaller.
In zoomed video mode, the image is expanded to fill the screen in landscape orientation. Images are displayed at 480x320, and cropped as needed. A 4:3 video shows as 480x320, cropped top and bottom, and a 16:9 video shows as 480x320, cropped left and right.
By sizing your video to at least 480x320, scaling up to the correct aspect ratio, you insure that your image will be either scaled down or cropped, but never scaled up. This will result in the sharpest possible image.
Create Alternate Movies for the iPhone
The iPhone has built in wireless networking over WiFi or cellular. The WiFi is usually connected to a shared DSL or cable modem, but it can be any kind of network really. The cellular data connection is EDGE, which is generally faster than a dial-up modem, is but definitely not a broadband connection. Ideally, you should create two versions of a movie you want to be seen on the iPhone: a higher bandwidth WiFi version and a lower bandwidth EDGE verion. Here's how:
- Export your movie twice using QuickTime Player (Pro version). The first time choosing iPhone from the Export menu, the second time choosing iPhone (cellular). This will create an .M4V file and a .3GP file, respectively, so you can use the same name as your movie, with different file extensions.
- Download the latest version of MakeRefMovieX from Apple's free QuickTime developer tools website. MakeRefMovieX appears to be a work in progress, so I'll describe how it works at the moment. Some of the limitations I'll describe will probably go away in time.
- Launch MakeRefMovieX (you'll be prompted for a filename for your reference movie: use the .mov file extension) and select Add URL from the Add menu. (Don't use the drag and drop interface; it creates movies that will only play locally). Type the URL where your lower bandwidth movie will eventually reside. This is the .3gp file if you exported your movie from QuickTime Player using the iPhone (cellular) setting.
- Make this the second priority movie, and set the data requiement to 128K Dual ISDN/EDGE. If you like, select iPhone only in the Mobility field.
- Now choose Add URL from the Add menu again, and this time choose the higher bandwidth movie (the .m4v file, if you exported from QuickTime Player using the iPhone settings).
- Make this movie your first priority, and set the data rate to 256K. Again, use the iPhone-only setting in the Mobility tab if you don't want the movie to be viewable on anything except an iPhone.
- Save your reference movie.
- Put your reference moviee, and both the .m4v file and the .3gp file, on your web server. Be sure the files are exactly where you told MakeRefMovieX they would be.
Ready, Steady, Go
Okay, you now have either an MPEG-4 movie or a reference movie and two MPEG-4 files, one with the .m4v suffix and one with .3gp.
You can test your movie by putting it on a server, clicking the Safari button on your iPhone, and entering the URL.