HLS video test
Published on December 15, 2024
Most of the videos served on this site are pre-encoded for static playback. With such short videos, the client downloads the video easily without too much buffering. These videos are served over a simple http server using an HTML video tag.
Recently though, I've been curious about adaptive bit rate streaming. This concept basically implements a procedure where the player on the website makes a decision as to what video bit rate quality to serve, based on the user's bandwidth. This improves video performance by reducing buffering time.
Of course for this to happen, the http server must have multiple versions of the same video at different qualities that it can serve for a player to switch to. The player itself is reading off instructions from the 'Manifest' file. This is a playlist sort of file that declares what quality should be played within a given bandwidth range. In fact the source attribute within your video tag will usually point to this manifest file at the root of the directory containing the many streams and video segments.
There are two popular protocols for adaptive bit rate streaming. One is Mpeg-Dash, which I tried unsuccessfully to implement on this site for a bit. The other was developed by apple and is called HLS, which is what the video below uses.
My approach was very minimal. I used one ffmpeg command that took in a mp4 video as input, and generated different streams at different bit rates that where furthered segmented into smaller bits.
Originally I wanted to use DASH, but I found the tutorials publicly available to be either incorrect, outdated or perhaps made assumptions on my intelligence that where unwarranted. The tutorial below on creating an HLS Video On Demand via ffmpeg meanwhile, worked first time.
By the way, Jon Dahl from MUX again, has a great philosophical lecture on Video in which he mentions among other things, adaptive streaming.