This post is also available in: Russian
Creating technically seamless applications has always been a pretty tough task in terms of time and complexity. Moreover, helpful data is scattered across multiple sources. This also applies to iOS video applications development. In this post, we have aggregated the most vital and helpful information on efficient use of all the features of HTTP Live Streaming, with detailed data source list. These materials are prerequisite to anyone who intends to ensure high quality of viewing experience.
To achieve the utmost interactive user experience in your video services, you have to enable fast start and rewind, with no buffering. For maximum efficiency, we propose the following sequence of actions.
- Start with low-quality video. To start video, at least one chunk is needed. So the smaller the size of a chunk, the faster your video would start. By reducing your starting stream bit rate and chunk length, you can achieve a faster video start. We recommend chunk duration of 4-8s and starting bitrate of 200-300 kbps. In this case, the user would have to download a maximum of 300 KB to start playback.
- Playlist Optimization Playlists may consume a significant portion of the total data flow, especially at small chunk size or lengthy content (a few hours). In most cases, it is recommended to back up playlists before sending video to a player.
- Keyframes It is advisable to have at least one IDR frame per segment, preferably at the beginning. Also, when transmitting video over cellular networks, it is recommended to insert keyframes at least once every 3 seconds.
- TS Overhead HTTP LS uses MPEG TS as a container, so it is important to minimize the TS overhead (even for low bitrates, it should be under 10%). In this case, make sure to measure the actual bit rate using traffic dumps and optimize the use packagers (segmenters).
- Target duration playlist parameter This parameter affects launch time, however Apple recommends 10s for it, as lower values may increase the probability of congestion, especially in high-latency networks. However, it is not to exceed 20s in segment length.
- Dynamic bit rate iOS has a built-in adaptive streaming mechanism that works best with explicit bitrates in a variant playlist (making allowance for playlist-generated traffic also), with close-to-maximum value specified for variable bitrate streams. Otherwise, invalid decisions to switch the current stream might be made. Neighboring bitrates should differ by the factor of 1.5 – 2.
- Audio only streams. The HE-AAC audio codec is substantially more efficient and is supported by most devices. Audio-only channels should be delivered as MPEG Elementary Stream rather than the MPEG Transport Stream, as the former has a substantially smaller overhead).
In developing the video player, you can access information about using HTTP Live Streaming content (accessLog), from which you can fetch data on how automatic switching occurred, which bitrates were used, etc. For more details on logged information, please follow this link. Based on these data, you can collect video analytics data from your users.
Additional recommendations In live video streams, buffering may also occur due to CDN latency and, if the the playlist update time is too small and the server fails to timely generate segments. To optimize rewind, it is recommended to use non-integer segment lengths corresponding to their actual duration, as otherwise an error is accumulated.
If you intend your application for different devices, the player may automatically choose the bitrate, based on screen resolution, if it has been indicated in the playlist. This way, you can feed different streams to an iPad with the Retina display and to a relatively old iPhone.
HTTP Live Streaming also provides for fault tolerance (e.g., by indicating alternative video sources), contributing to robustness of your services.
Knowledge sources Basic prerequisites to be read before implementing HTTP Live Streaming in your applications:
HTTP Live Streaming draft
HTTP Live Streaming Frequently Asked Questions
Best Practices for HLS
Finally, it is worth noting that, for Mac/iOS/Safari registered developers, free videos from WWDC 2012 technical sessions are available, containing plenty of helpful details on video processing, use of HTTP Live Streaming, and beyond.