The Basics of HTTP Live Streaming [u]

Posted on by Larry

UPDATE – Oct. 11, 2020

Publit.io is cloud-based Digital Asset Management software. It handles storage, processing and delivery of images, videos & rich-media files for modern web apps. With it’s URL-based API, you can resize, format, transform, watermark your media files and more. Recently, they released an article explains HLS Streaming, a necessary codec for mobile media. This is a good backgrounder. Here’s the link.

This provides a good follow-on to the information in my article, below.

UPDATE – Dec. 2, 2022

The Porch published “Live Stream Setup and Tech Guide for Beginners” – which covers getting gear together for live streaming at the consumer level. Their article includes different tips on how to take advantage of live streaming, including how to set up your studio at home and a comprehensive overview of cameras and mics. Here’s the link.

UPDATE – April 29, 2023

Updated Apple Compressor screen shots to version 4.6.3 and made text corrections for current practices in the Compressor section. The rest of this article was not touched.


The research for this article started when some of my subscription users started complaining that they could only see a few minutes of one of my longer webinars before they needed to reset their browser. At first, I thought this was caused by bad programming on our part. But, further research made me realize that iOS devices only stream about 10 minutes of continuous video content when they are connected to a cellular data network, then they stop.

Period.

This article explains why. (If you want a more technical explanation, read this Apple Support Note.)

NOTE: If any of the following conditions are true, you can ignore this article:

Understanding Live Streaming isn’t easy, but it isn’t impossible, and this article provides a cookbook you can follow which makes a lot of it fairly simple.

SOME BACKGROUND

There are two types of web video:

Progressive downloads are single files that are stored on a website. When someone wants to view them, the files are downloaded via a browser to a computer or mobile device for viewing. Downloads can be stored locally on the device doing the watching.

Streaming video is fed from a server and watched via a browser without the file actually being transferred from the server to the viewer. YouTube and Vimeo are two excellent examples of streaming video.

In the early days of web video, in the mid-1990’s, creating a high-quality progressive download video required rocket science. Today, though, we have the process nailed. However, as I am discovering, this is not the case for streaming video, which is what this article talks about.

THE ISSUE

The problem is mobile devices. Here are two scenarios involving a 30-minute training video, which is stored in a 120 MB file:

Scenario 1: Watch on a computer. When you fire up your browser to watch the program, the request goes out over your Internet connection and the file starts downloading. Except, you get a phone call about five minutes in, so you put the program on hold. Realizing that the call is going to take a while, you quit the browser and put your computer to sleep.

Scenario 2: Watch on a mobile device. Same program, same five minutes, same phone call.

The problem is that your computer has unlimited access to the Internet, while your phone most often has a data plan that charges by the megabyte transferred.

You only watched 5 minutes, therefore your phone should have downloaded only 20 MB of the program.  But it didn’t. It downloaded the whole thing because it was a progressive download. You were just charged for downloading 100 MB of data that you never used.

Worse, the phone network just carried 100 MB of data that was never used. Now, multiply that by the number of users on your cell phone data network watching video and you begin to see the size of the problem. MASSIVE amounts of data are downloaded and not being used.

To prevent this problem, iOS devices will only stream the first ten minutes of video material, then they stop. If your video is shorter than ten minutes, no problem. Everything is fine. But if your video is longer than ten minutes, the user needs to open the video again in their browser and navigate to where it left off. Annoying.

THE SOLUTION

The solution lies in compressing and segmenting your video into very short chunks, about ten seconds each, then streaming those chunks sequentially to your phone. Because you are not downloading the entire file, when you stop viewing, or simply pause the video, no additional data is transferred. This frees up huge amounts of network bandwidth. When you restart the stream, the chunks pick up where you left off.

All the heavy lifting for this to work happens at the web server, so end-users don’t need to do anything different, provided they have a reasonably current browser. Even better, this new streaming protocol senses the speed of your data connection and sends files that are optimized for that speed. This minimizes stuttering and choppy playback.

This new video protocol is called HTTP Live Streaming and was invented by Apple. Google and Microsoft each have something similar, though with a different name. This streaming protocol is supported by any HTML/5-compliant browser and requires no changes on the part of the end user.

NOTE: It is more accurate to call HTTP Live Streaming a “media streaming communications protocol.” First, you compress your files, then the Live Streaming protocol defines how to segment them and generates a playlist to adaptively choose a stream based on available bandwidth. Apple has publicly documented the protocol so it is available to all browsers and devices.

While all the streaming is handled by the web server supporting this format requires major changes in how we compress videos.

NOTE: For those that want a technical briefing, here’s the WikiPedia link:
http://en.wikipedia.org/wiki/HTTP_Live_Streaming

The good news is that we can use Apple Compressor to create the files required for HTTP Live Streaming and the quality is potentially indistinguishable from a progressive download file. Another good thing is that this protocol can be viewed by both computers and mobile devices so that once you’ve created media files to support this protocol, you can use it for all your viewers.

But there are a lot of changes you need to make to get this to work:

EXECUTIVE SUMMARY

You need to recompress your master file using Apple Compressor for HTTP Live Streaming. This creates the small chunks that get streamed by the server.

You need to transfer the folder containing these files to the website that is hosting your videos, then, following the instructions that Apple provides as part of the compression process, change the links on the webpage to point to a specific file in this compressed files folder.

For videos hosted and streamed from a local website, this works great. For videos hosted on The Cloud, for example, Amazon servers, I haven’t figured out how to get this to work yet.

IMPORTANT NOTES

  1. HTTP Live Streaming does not work with video-only, or audio-only files. You must have audio in your clips, even if it is silence. The compression process fails when compressing video-only clips.
  2. HTTP Live Streaming can also be used for live events which this article does not cover.

COMPRESSION

There are two types of files that need to be created:

While any compression software can create the MP4 files, the only application that I’ve found that also creates the segment files – called “HTTP Live Streaming” (HLS) – is Apple Compressor 4.

Here’s how this works in Apple Compressor 4.6.3.

Start Compressor 4 (Compressor 3 does not support this HLS).

Here, for example, I’ve loaded one of my recent webinars into Compressor for compression.

In the Settings tab, open the BUILT-IN folder and locate the HTTP Live Streaming folder.

NOTE: There are two versions. The one indicated by the red arrow (above) compresses using H.264. The one displaying “(HEVC)” compresses using HEVC. H.264 is appropriate for most situations because of its wide compatibility. Only use HEVC compression if you are instructed to do so. HEVC will also take longer to compress.

Drag the entire folder on top of the name of clip you want to compress (red arrow above). Seven different settings are applied to the master clip.

NOTE: These seven versions of your file range from extremely high-quality, large frame size high-bandwidth files to small frame size, low-bandwidth audio only. This allows the server to instantly vary the quality of video playback based on the connection speed of your phone. If your viewer suddenly drives into a dead spot, the server switches to low-bandwidth chunks until the data speed improves; at which point the server automatically switches back to the higher-quality version. Each chunk runs ten seconds.

The compression settings range from audio only – at the top – to high-speed, high-quality broadband – second from the top – then into other image resolutions and data rate options.

NOTE: You MUST use all seven of these settings, you can not select between them.

EVEN BIGGER NOTE: Do not alter any of these settings in any way. I’ll have more on that in a bit. They are specifically optimized for HTTP Live Streaming.

This process generates seven different compressed versions of your movie in 10 second chunks. Each version starts with the same name, but adds a specific numbered extension to differentiate between the different versions.

Each of these seven formats creates a folder containing hundreds of chunks which need to be stored in a master folder.

NOTE: Yup, you guessed it. DO NOT change these names!

So, the next step is to create that master folder. I long ago standardized on storing these in a folder I named the same as the webinar. You can name this folder anything and store it anywhere. However this folder will be what you ultimately transfer up to the web, so make sure it doesn’t contain any spaces and try to use exclusively ASCII characters.

Create one master folder for each source video.

The files displayed in Compressor are all work files. Compressor needs to create these in order to create the HLS folder. But it doesn’t need these once the HLS folder is complete. So I store these to my customary compression location, but delete them as soon as the HLS folder is processed.

A CRITICAL FINAL STEP

Before you click the Start Batch button, you have one more setting to configure. You need to tell Compressor the name and location of the HLS master folder.

In Compressor, click the Job tab at the top of the Inspector, then scroll all the way to the bottom to the Action section. All these defaults are fine, except click Choose to display the standard Mac file picker. Navigate to and open the HLS master folder.

With the HLS master folder open, enter a file name at the top which becomes the master file name for all the thousands of chunks you are about to create. For my webinars, I name the master file name the same as the folder.

Remember, no spaces and only use ASCII characters. Click the Save button when you’ve entered a file name and selected the destination folder.

This file name and destination will now be used for the job. The rest of the settings in this section are fine.

NOTE: If you don’t complete this step, all the little chunks won’t be created and you’ll need to start all over again. I learned this from personal experience.

Then, as usual, click the Start Batch button to start compression. On my M1 Pro MacBook Pro, it takes a couple of hours to create all these files. So be patient.

AFTER COMPRESSION

Once compression is complete, if you were to open the HLS master folder (which you don’t need to do unless you are curious) you would see a folder for each compression format.

Inside each of those subfolders, you will see hundreds of clips – each 10 seconds long – spanning the entire duration of your video.

MOVING TO THE WEB

Also, shown in the screen shot above, a special file is added to the master folder, called the “.m3u8” file. This is the playlist controller that tells the server which files to play and where they are located.


(Click to see larger image.)

Here’s what the m3u8 file looks like. Notice, on the right side, how the image size varies allowing your movie to play even when cell bandwidth drops.

Also in this folder is a ReadMe file that provides very specific directions on how to post this file to your website. For example:

In case you are curious, this is what this looks weblinks look like for my movie. This Read Me file should be given to your webmaster so they know exactly what links to use when posting.

UPLOADING

Once all compression is complete, it is time to upload the HLS version of your movie. However, in this case, you upload the ENTIRE FOLDER that contains all these files to wherever you store videos on your website.

BIG NOTE: Just a reminder that this process is NOT necessary if you are using YouTube or other commercial video streaming services for your videos. Only for video streamed from a local website.

A FLY IN THE OINTMENT

So far, everything is working great. However, remember that I said not to change any of the compression settings? Well, ah, that causes me a problem. Because I want to add a watermark, maybe scale the image. And none of that is possible given the default settings in Compressor.

In the past, I would use Job Chaining, which allows the output of the first job to become the input of the second job. The problem is that while this is a great idea, it isn’t reliable. I’ve struggled with Job Chaining for years and finally given up.

Instead, I create an intermediate file of my movie with all watermarks added; plus any other effects. I save this as a ProRes 4444 file, which is, essentially, lossless. Then, I use this intermediate file to create the HLS files.

The good news is this works perfectly. The bad news is that Compressor takes a LONG time to create that intermediate file. I don’t know why. But it takes as long, or longer, to create an intermediate ProRes 4444 file as it does to create the HLS chunks.

So, I start the job and do something else for a few hours until it is complete.

SUMMARY

HTTP Live Streaming is specifically designed to reduce network bandwidth required for users of cellular mobile devices to watch videos on their phones, while at the same time allowing video quality to fluctuate to compensate for changing data rates across the network.

If your viewers watch your videos on a computer with a high-speed internet connection, they will see top-quality images without worrying about data rates or any other technical issues.

However, like all web videos, compression is only half the story. The other half is working with your web team to post the videos. The best place to start, after the files are transferred, is the ReadMe created by Compressor when the job is complete. When I followed its instructions and posted the video to my website, everything worked great.

As always, I’m interested in your comments.


Bookmark the permalink.

30 Responses to The Basics of HTTP Live Streaming [u]

Newer Comments →
  1. Jack Rickard says:

    Larry:

    GREAT article. Very interested in the next step.

    We have been publishing a TWO HOUR HD video each week since November 2009 on how to convert cars to electric drive. We host this on Amazon’s Cloud using S3. We also do a blog using EC2 and WordPress. We use the JWPLayer to show the videos.

    Big fan of Amazon. I’ve written you on this topic before.

    You might find it interesting to learn. We tried selling commercial advertising on the video series as regular video commercials for several years. The companies offering components for electric vehicles actually tended to be small mom and pop shops and video production was a bridge too far for most and buying advertising kind of a new concept for most.

    We gave it up. Instead we became dealers for the components we use and like on the show and put up a web store selling batteries, motors, controllers etc. about a year ago.

    In May we sold $200,000 gross in components and we are growing about 12% per month. I think this is the new model for monetizing instructional/informational videos. Sell the frying pans while teaching cooking.

    Hanging on every word of your Amazon investigation.

    Jack Rickard
    EVtv.

  2. Nice job of researching and presenting a highly technical explanation in a manner that is much easier to comprehend.
    I seem to recall a guest on your show a few weeks back that offered this compression service for his clients. He touched upon the need for multiple versions of video in order to effectively deliver on multiple devices and platforms.

    Was he one of your resources? Might be a good idea to repurpose his expertise and invite him back for a more in depth discussion.

  3. Robert says:

    You should check into using the Wowza servers on Amazon’s service. I believe that Wowza will do the segmenting for you, all you have to provide is a H.264 file. Also I believe that there are AddOns that will give you the various broadband versions.

  4. Jack Rickard says:

    Wowza sounds like a quick way to get rid of $995, to do what I’m hoping Larry shows us how to do anyway. Better, you can let them markup ALL your Amazon charges. Good work if you can get it.

    Amazon already has streaming. I just need to learn how to use it and the work flow with Final Cut Pro X.

    Jack Rickard

  5. Jeff says:

    Hi Larry.

    I was testing your demo video to see how it performs on different web browsers. It worked ok on Safari and iCab on Mac, the same went for my iPhone.

    But when I tested on Firefox, Opera and Chrome on Mac (all latest versions installed), they didn´t seem to work. Actually on Firefox I had an error message that says that “video format or MIME type is not supported”.

    So, what is missing on my browsers? Is necessary to have something special installed to see the videos?

    Thanks…

    • Larry Jordan says:

      Jeff:

      Thanks for the feedback. At this point Google, who owns FireFox, does not support H.264/MPEG-4 videos within FireFox because they don’t want to pay royalties on the codec. Instead, they’ve created a far less competent codec called “WebM.” In order for our videos to support FireFox, we would need to create an entirely different version just using WebM. It is far easier to change browsers than to create two different encodings of our training.

      Larry

  6. Thad Macnamara says:

    Great research and writing! One question: Is the limitation on file size only on phones, or does it apply to iPads, eg a sales force in the field?

  7. Jack Rickard says:

    Amazon has a new product – Elastic Transcoder or something like that. https://console.aws.amazon.com/elastictranscoder/home?region=us-east-1#getting-started:

    I kind of like the idea of OFFLOADING this little chore to Amazon and not spending a lot of time on my machine doing it myself. Since we host on Amazon anyway, it would appear they can handle the transcode chores to make files for various platforms. How about a tutorial how to do THAT.

    Jack Rickard

    • Robert says:

      Yes Wowza does cost a bunch of money but if you are using the Amazon instance I think it is a lot cheaper. As a university we do get a discount of the purchase of the server so that is why we use it. But I like the fact that I only need one H.264 video to serve out Flash, HTML 5, HTTP Streaming(Flash and Apple) and Silverlight without having to encode all of the different versions.

  8. Peter Lonsdale says:

    Great article Larry. It begs the question: How were we to know about this if it wasn’t for you?!

    Thanks,

    Peter

  9. Larry Leake says:

    Great article – thanks for digging into this subject. This explains how some of my end users have been experiencing the cutoff after 10 mins of playback.

    Have you figured out how Vimeo is doing their back end? Nice because I upload one 5000 KBPS file, and they transcode. Wondering what encoder/workflow they use? Might be part of their mojo….

  10. Matt says:

    Larry – Great article. We’ve taken a stab at the topic as well, and we cover some points that you don’t, such as browser and device support. For example, we look at how Android supports http live streaming. Feel free to read through our article and excerpt anything you find of value. http://features.encoding.com/http-live-streaming-hls/

    Many thanks!

Newer Comments →

Leave a Reply

Your email address will not be published. Required fields are marked *

Larry Recommends:

FCPX Complete

NEW & Updated!

Edit smarter with Larry’s latest training, all available in our store.

Access over 1,900 on-demand video editing courses. Become a member of our Video Training Library today!

JOIN NOW

Subscribe to Larry's FREE weekly newsletter and save 10%
on your first purchase.