Earlier this year we moved our transcoding layer of our Fliva Player from a cloud provider to our own software. This move has enabled that we have much more granular control over both features and cost. We used this granularity to enable HLS streaming format in our player.
The HLS format is invented by Apple to be used to deliver video for streaming in e.g. iTunes and QuickTime Player and on Apple TV. Even though the acronym means HTTP Live Streaming it is probably used more for on-demand video instead. Many of the biggest streaming sites use this format.
The format itself is really just a specification. It has two different parts. Media files and Playlists.
Media files in HLS
The video in the hls format is encoded into an h.264 format and the audio in either aac or mp3. Then the video is split into segments of equal length called ts-files. On the client, these ts files are merged into a final playable continuous stream.
Playlist files in HLS
The smart thing about HLS is that we can have multiple resolutions and bitrates supported in a single stream. To do this we have a playlist of media files per resolution/bitrate, and then a master playlist that includes all the other playlists.
Implementation in the player
The player loads the master playlist and checks the size of the player window in the browser. It then loads the playlist of the largest size that matches the resolution on the screen – keeping in mind that it is better to have a slightly larger resolution video than a slightly smaller – this means for a window that is 600×400 it will load a 720p video instead of a 340p for instance. Finally, it begins to load segments from that playlist, and measure the speed of the downloads. This can be used to calculate whether the download of segments files can happen fast enough to get a fluid playback rate. If not, it will automatically take a lower resolution and/or bitrate to ensure smooth playback.
The player loads the first few segments from the HLS playlist before you even press play, so as soon as you press play the first segments will be ready for you, and the player will know what resolution it can download to make the playback stutter-free.
Further, if you resize the window the player will change to a resolution that matches the size, still taking your download speed into account.