Encoding settings for perfect iPad/iPhone video
You already know this, but iOS video is a big deal. Any serious video publisher either already supports iPad and iPhone, or needs to think hard about adding support. For some major publishers, iPad delivery represents 1/3 of total video views - or more. Encoding for iOS is a little tricky, though. iOS devices have gone through several generations of technical capabilities, and the ideal video settings for the iPhone 4 are not ideal for the iPhone 3GS or for the iPad. Fortunately, with just a few encoding profiles, you can stream high quality video to every iOS device, from the first iPhone to the iPad 2, and even prepare for future generations of mobile hardware. We've written about this before but our previous guide only described how to ensure mobile compatibility - not how to find the best settings. This article is the first in a series of encoding recommendations. At Zencoder, we get asked for encoding recommendations all the time, and we end up recommending the same (or similar) settings over and over. We're going to start publishing our recommendations to our blog and to our docs in an effort to help Zencoder customers (and non-customers) make good decisions about how to encode video for a wide range of targets: mobile devices, Flash, Silverlight, HTML5, connected devices, and more. (For deeper information on HLS and iOS video, be sure to download our guide to iOS video, which goes into more detail about HTTP Live Streaming and iOS video delivery.)
Like most video today, use H.264 video and AAC audio when targeting iOS. On the audio side, consider using HE-AAC at <64kbps, for App Store compliance. HE-AAC sounds reasonably good at these bitrates, even for complex audio. On the video side, use multiple profiles to target each device. iPhone 3GS and earlier only support H.264 Baseline profile, level 3.0 (and some support a more constrained version than that), whereas newer devices support Main and High profile. For the best user experience, HTTP Live Streaming is a must. Apple requires it of any video app in the App Store that plays content longer than 10 minutes, and it is the only true streaming format supported by iOS. HLS is also being adopted by Android (version 3+), Roku, and a range of other destinations. Zencoder fully supports HLS, and does so better than anyone else in the cloud.
|Resolution||Profile||Bitrate||@ 16:9||@ 4:3||Audio||Comments|
|400x288||Baseline@3.0||200kbps||400x224||384x288||56kbps HE-AAC||decimate frame rate|
|N/A (Audio Only)||56kbps HE-AAC|
Why these recommendations?
- These are just recommendations. Different resolutions and bitrates are perfectly valid, and may actually be preferable in some circumstances. For example, extremely complex content may warrant higher bitrates.
- 720p is the largest video playable on iPad 1 and iPhone 4, and iPad 2/iPhone 4S play anything up to 1080p. But since the native display is only 1024 pixels wide, going all the way to 720p or 1080p isn't critical. Unless, of course, you want to reuse a video somewhere else - 720p is a great resolution for fullscreen web playback, and 1080p is entirely appropriate for connected TVs. Future iPads, by the way, are rumored to have 4x the resolution of the current iPad, so consider adding 720p for future-proofing.
- H.264 profile is important. iPad 1 and iPhone 4 both support Main profile. iPad 2/iPhone 4S support High profile, which is marginally better than Main, but given the tens of millions of iPad 1 devices in the world, it is probably better to stick to Main profile. Of course, for truly optimal device targeting, encode to both Main and High.
- These 6 resolutions and bitrates provide reasonably good coverage of varying bandwidth. You could certainly do more - Apple recommends 8
- so add or subtract resolutions and profiles as desired.
- Legacy iPhone/iPod Touch users will have three streams available to them, including a reasonably high quality 480x320 video (the screen resolution of these devices). iPad and iPhone 4 users will be able to make use of all six streams.
- The resolution scaler on the iPad is pretty good, so videos that are rescaled will generally look good.
- As much as possible, these settings allow for resolution dimensions divisible by 16. This makes for more efficient compression. The efficiency gains are small, especially at high resolutions, but at lower resolutions they start to make a difference.
- Be sure to keep the audio identical across each video. If the audio specifications change from one version to another, the user may hear pops and clicks during playback when switching streams.
- Speed: set this based on desired turnaround time. For these recommendations, we're going to use Speed 2, which improves compression a bit over the baseline but is still reasonably fast.
- Peak limiting: ensure that each segment is roughly the same size by using a peak bitrate_cap of 150% of the target bitrate, but within a long buffer_size (e.g. 5 seconds, or 5x the bitrate_cap).
- Zencoder automatically chooses proper keyframe placement when you set the type to "segmented". If you're encoding to MP4 for separate segmenting to HLS, set "forced_keyframe_rate" to "0.2" or "0.1" (for 5 or 10 second keyframe intervals, respectively).
- If you can accept slightly unpredictable bitrates, add quality to the mix, and change video_bitrate to max_video_bitrate to optimize for file size. The encoder will use the max bitrate when needed, and will use a lower bitrate when it can achieve the desired quality with fewer bits.
- Set the max_frame_rate to 30 and the max_audio_sample_rate to 48000.
- The first generation if iOS devices only allow 1 H.264 reference_frame, so enable this on the Baseline streams for max compatibility.
For more information...
The Zencoder guide to HLS encoding - Best Practices for Encoding Video for iOS Devices - goes into more detail on the HLS standard, App Store requirements, advanced HLS features, and provides six tips for expert HLS encoding.