Faster HLS preparation

Santiago Seifert
AndroidX Media3
Published in
4 min readJan 10, 2018

My last medium story outlines some good practices that HLS content producers can follow to make client-side media playback easier. This post aims to describe how chunkless preparation in ExoPlayer can now take advantage of rich master playlists to shorten the initial buffering period by avoiding chunk downloads. In simple terms, chunkless preparation can help playback start faster.

Sounds good, how do I opt-in?

Available today on our dev-v2 branch, and to be available from the 2.7 release, you just need to set allowChunklessPreparation to true when creating your HlsMediaSource. Like so:

new HlsMediaSource.Factory(dataSourceFactory)
.setAllowChunklessPreparation(true)
.createMediaSource(uri, mainHandler, eventLogger)

That's it. HlsMediaSource will try to prepare without downloading any media chunks.

Will it work with any HLS master playlist?

Almost. The only essential piece of information is the CODECS attribute. It must be present in every EXT-X-STREAM-INF tag for chunkless preparation to work. If not present, traditional preparation will take place instead (look below for details).

How much faster will preparation be?

It really depends on the stream and the network conditions. Streams that benefit the most are those with multiple alternative renditions, like multiple audio languages. A simple benchmark on a nominal bandwidth of 6 Mbps yielded the following results using the demo app with the first few HLS sample streams. The preparation duration seems to be consistently shorter, but also the results show less deviation from the average.

HLS 4x3 basic stream

Chunkless average preparation duration: 1.12 seconds. Sample standard deviation: 0.77 seconds.

Traditional average preparation duration: 1.41 seconds. Sample standard deviation: 1.34 seconds.

HLS 16x9 basic stream

Chunkless average preparation duration: 1.38 seconds. Sample standard deviation: 1.14 seconds.

Traditional average preparation duration: 2.08 seconds. Sample standard deviation: 1.82 seconds.

HLS Master playlist advanced (TS)

Chunkless average preparation duration: 4.56 seconds. Sample standard deviation: 1.87 seconds.

Traditional average preparation duration: 5.75 seconds. Sample standard deviation: 3.05 seconds.

HLS Master playlist advanced (fMP4)

Chunkless average preparation duration: 2.34 seconds. Sample standard deviation: 0.72 seconds.

Traditional average preparation duration: 3.01 seconds. Sample standard deviation: 0.85 seconds.

The following two sections roughly describe how preparation works. It’s definitely worth reading before enabling chunkless preparation in a production environment, as it will help you to understand the differences compared to traditional preparation, and their implications.

Traditional preparation

Some master playlists, particularly older ones, might include incomplete or incorrect track information. To work around this, ExoPlayer also extracts information from the media content itself. This generally requires downloading a single chunk from one of the variants and one from each non-muxed audio track. This approach has two positive points:

  • Information that is missing in the playlist is completed if available in the media. Example: closed captions language.
  • Tracks that are not declared by the master playlist can still be available for selection. Example: undeclared closed captions and ID3 tracks.

However, for newer high quality playlists we expect all this information to be declared correctly, in which case it’s not ideal because it adds preparation overhead, and wastes some bandwidth.

Chunkless preparation

Chunkless preparation uses whatever information is available in the master playlist to build the list of tracks. The steps are:

  1. If the CODECS attribute is not present, proceed with traditional preparation.
  2. Add a track group for every EXT-X-MEDIA tag.
  3. EXT-X-STREAM-INF tags may produce both audio and video track groups. If CODECS contains a video entry, add video track group. If in addition to the video entry there is an audio entry, then add a multiplexed audio track group if and only if there are no EXT-X-MEDIA tags or there is an EXT-X-MEDIA tag with no URI attribute.
  4. If CODECS does not contain a video entry but does contain an audio entry, then add an audio track group.
  5. If CODECS does not contain an identifiable audio or video entry, preparation fails.

Other relevant points are:

  • Closed caption tracks are exposed if and only if they are declared by the master playlist.
  • Currently, the only mechanism for DRM signaling in HLS supported by ExoPlayer is the EXT-X-KEY tag which is carried in media playlists. Chunkless preparation does not rely on media playlist information, so HlsMediaPeriod will not expose DRM related information as part of the TrackGroups. This only means that track selection will not consider DRM capabilities. If supported, DRM-protected tracks will play fine. But if not, an exception will be thrown instead of avoiding the selection of unsupported tracks. At the time of writing, this only affects Widevine encrypted content. It does not affect full segment encryption in any way. Once EXT-X-SESSION-KEY is supported, it could be used to advertise audio and video tracks as DRM protected.

Please give chunkless preparation a try and see if it works for your apps. Let us know if you can think of ways to improve it!

--

--