iOS devices support the delivery of multimedia content via HTTP progressive download or HTTP Live streaming . As per Apple's guidelines to App developers, "If your app delivers video over cellular networks, and the video exceeds either 10 minutes duration or 5 MB of data in a five minute period, you are required to use HTTP Live Streaming. (Progressive download may be used for smaller clips.)".
This article discusses a method for generating HTTP live streaming content using freely available tools. If your needs are large scale, then you may need to explore commercial encoders such as the Sorenson Squeeze 7 or other commercial video platforms. This article does not describe commercial video platforms.
HTTP Live Streaming – A (Very) Brief Overview:
In HTTP Live streaming, the multimedia stream is segmented into continuous media segments wherein each media chunk/segment holds enough information that would enable decoding of the segment. A playlist file is a list of media URIs, with each URI pointing to a media segment. The media URI’s are specified in the order of playback and the duration of the playlist file is the sum of the durations of the segments. Media playlist files have an “.m3u8” extension. The servers host the media segments and the playlist file. In order to playback content, the media streaming app on the device fetches the playlist file and the media segments based on the media URIs specified in the playlist . The transport protocol is HTTP.
Now, you can have multiple encodings/renditions of the same multimedia content. In this case, you can specify a variant playlist file that will contain URIs to the playlist files corresponding to each rendition of content. In this case, the iDevice can switch between the various encodings thereby adapting to changing network bandwidth conditions. HTTP Live Streaming is essentially a form of adaptive streaming. You can get more details from the IETF I-D available here. Other well-known adaptive streaming protocols include that of Microsoft’s Smooth Streaming , Adobe’s Dynamic Streaming and the DASH standards specification .
Encoding the content using Handbrake:
-
Among the free tools, I’ve found Handbrake to be the best in terms of performance and supported formats. Versions are available for Windows and the Mac. In my experience, the Mac version stalled a few times during encoding and at times hogging all the CPU cores on my Macbook Pro. The Windows version worked flawlessly.
-
Use the following encoding guidelines provided by Apple to encode your content. If you expect your app users to be able to access the content under a variety of network conditions (wifi, cellular etc), you would want to support multiple encodings of the content .
The Tools for generating content for HTTP Live Streaming :
Once you have encoded your content, you would have to prepare it for delivery via HTTP live streaming. There are a command line utilities available for the Mac that can be downloaded for free from http://connect.apple.com/ (You would need an Apple developer Id for installing the tools, which again is free). You would need the following tools –
-
mediafilesegmenter
-
variantplaylistcreator
Once installed, they would be available in/usr/bin directory of your Mac.
Segmenting your encoded content:
Use the mediafilesegmenter tool to segment the encoded media files. You would need to be “root” user in order to run the tool.
/usr/bin/mediafilesegmenter [-b | -base-url <url>]
[-t | -target-duration duration]
[-f | -file-base path] [-i | -index-file fileName]
[-I | -generate-variant-plist]
[-B | -base-media-file-name name] [-v | -version]
[-k | -encrypt-key file-or-path]
[-K | -encrypt-key-url <url>]
[-J | -encrypt-iv [random | sequence]]
[-key-rotation-period period]
[-n | -base-encrypt-key-name name]
[-encrypt-rotate-iv-mbytes numberMBytes]
[-l | -log-file file] [-F | -meta-file file]
[-y | -meta-type [picture | text | id3]]
[-M | -meta-macro-file file]
[-x | -floating-point-duration] [-q | -quiet]
[-a | -audio-only] [-V | -validate-files] [file]
- Open a terminal window on your Mac.
- Type “man mediafilesegmenter”at the command link prompt to get a full description of the usage of the tool.
<command prompt>$ man mediafilesegmenter
- An example of using the tool to segment a media file named “mymedia_hi.mp4” is as follows-
<command prompt>$
sudo /usr/bin/mediafilesegmenter -I -f mymedia_hi -f mymedia_hi.mp4
You will be prompted for the root password (which you must provide)
In the example, the media file “mymedia_hi.mp4” is assumed to be present in the current directory from which the command is executed. Otherwise, be sure to specify the path to the media file. The segments will be generated in a subfolder named “mymedia_hi” within the current directory.
<command prompt>$ cd mymedia_hi
<command prompt>$ ls
<command prompt>$
fileSequence0.ts fileSequence14.ts fileSequence6.ts
fileSequence1.ts fileSequence15.ts fileSequence7.ts
fileSequence10.ts fileSequence2.ts fileSequence8.ts
fileSequence11.ts fileSequence3.ts fileSequence9.ts
fileSequence12.ts fileSequence4.ts prog_index.m3u8
fileSequence13.ts fileSequence5.ts
The fileSequence*.ts files correspond to the media segments which are MEPG2 transport streams. The prog_index.m3u8 is the playlist file corresponding to the segmented media file and specifies the media URIs to the segments.
- The “-I” option that I specified in the example command will generate a variant plist file. The variant plist file would be subsequently required to generate the variant play list file as described in the next step. You don’t need this option if you don’t plan on streaming multiple encodings of your content.
Assuming you are in the “mymedia_hi” folder, type the following to get the list of generated variant plist files.
<command prompt>$ cd ..
<command prompt>$ ls *.plist
<command prompt>$
mymedia_hi.plist
Generating variant playlist file :
If you do not intend to stream multiple renditions of the content , you can skip this step and proceed to the “Streaming the Content” section.
-
Follow the procedures specified in “Segmenting your encoded content” section to segment every encoding of the media content that you wish to stream. For example, if you plan on supporting three renditions of your media content for high, medium and low network bandwidth conditions respectively, you will have to use the “mediafilesegmenter” tool to segment each of those renditions.
-
Use the tool variantplaylistcreator for generating the variant playlist file.
/usr/bin/ variantplaylistcreator [-c | -codecs-tags] [-o | -output-file fileName]
[-v | -version] [<url> <variant.plist> ...]
-
Type “man variantplaylistcreator” at the command link prompt to get a full description of the usage of the tool.
<command prompt>$ man variantplaylistcreator
-
An example of using the tool to generate a variant playlist file named “mymedia_all.m3u8” is as follows-
<command prompt>$ sudo /usr/bin/variantplaylistcreator -o mymedia_all.m3u8 http://mywebserver/mymedia_lo/prog_index.m3u8 mymedia_lo.plist http://mywebserver/mymedia_med/prog_index.m3u8 mymedia_med.plist http://mywebserver/mymedia_hi/prog_index.m3u8 mymedia_hi.plist
You will be prompted for the root password (which you must provide)
The URL that is associated with the prog_index.m3u8 files for each encoding corresponds to the URL of the webserver that will be used for hosting/streaming the media content.
-
The generated variant play list file “mymedia_all.m3u8” will specify the URIs to playlist files (prog_index.m3u8) corresponding to each encoding of the media file. The contents of the file (viewable using your favorite text editor) should be something like this
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=87872
http://mywebserver/mymedia_lo/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=100330
http://mywebserver/mymedia_med/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1033895
http://mywebserver/mymedia_hi/prog_index.m3u8
Streaming the Content:
-
Upload the variant playlist file (mymedia_all.m3u8 in our example) and ALL the sub-folders that contain the generated segments for every rendition of the media file to the web server that will stream the content. You do not have to copy the media files (eg .mp4 files) from which the segments were generated. You could host it on any regular web server such as the Apache Webserver or Microsoft's IIS. For instance, on an Apache server on Windows, you would copy all this to the “htdocs” folder. This would be something like this- c:\Program Files(x86)\Apache Software Foundation\Apache2.2\htdocs.
-
Typically you would need to make no changes to the web server in order to stream the content. In some cases, you may need to update the webserver configuration file to add support for the .m3u8 MIME type . I had to do this for my IIS web server where I associated the .m3u8 extension with “application/octet-stream” MIME type.
Note: If your needs are large scale, you would employ the services of a Content Distribution Network (CDN) such as Akamai to publish and distribute your content.
Accessing the Content from your iDevice:
-
In order to access the streaming content on your iDevice, the media URL must point to the appropriate playlist (.m3u8) file. This would correspond to either the Variant playlist file if you support multiple encodings of the content (mymedia_all.m3u8 in our example) or the prog_index.m3u8 playlist file for the specific encoding of the content.
Example: http://<webserver>/<path to the .m3u8 playlist file>
If you do not have a streaming app, you can open the URL in the Safari browser on your device. If everything goes well, the stream should start playing on your device.
22 comments
Trackback e pingback
-
Generating HTTP Live Streaming Content | HTML5 and Adaptive Streaming Video | Scoop.it
[...] Generating HTTP Live Streaming Content iOS devices support the delivery of multimedia content via HTTP progressive download or Live… -
My first HLS video stream delivered on CDN « Andre's Blog
[...] smartphone web traffic, 95% of tablet traffic -there is a very good article from Priya Rajagopal: Generating HTTP Live…
Hi, i found this blog on Yahoo, It is a good Blog
Hi, the blog is good ….but i have a question this is all related to segmenting and creating a variant playlist for A VIDEO … if i have 100 videos then there should be some step to write once get it done for all the videos????
Also, if my server is not on my mac then i according to blog … i will have to do all the steps of TOOLs in MAC first and then take all the files to my server (on windows) , FOR EACH NEW VIDEO ADDED !!! ….
AM i right?
I think there should be some way to just add a video – > it segments as needed… -> we can add that files to server -> stream it
Looking forward to your reply!!!.
Thanks,
Sumit K Gupta.
Hi Sumit
The post describes generating content ready for HLS using freely available Mac tools. If you have a large number of videos, you can write appropriate scripts that can batch process /prepare the videos for HLS using the tools. That said, if you are looking for larger scale deployments, you can look at commercial encoding and content preparation and media servers – Notable ones are (a) Sorensen Media Squeeze servers (b)Zen Coder -http://zencoder.com/ios/ (c)livetranscoding.com. Also, there are CDNs such as Akamai HD and Amazon AWS that can take care of preparing the content for you in addition to distributing them.
Hi Pirya,
Thank you for posting this article.
In the case of live broadcast, how does one have to physically upload the variant playlist files manually via when the broadcast is occurring, or can you rely on http to automatically change the playlist files on the remote server.
I don’t quite see how unless instead of a path you specify a url to the remote files on the server?
Kind Regards John
Hi John
HTTP will not take of automatically changing the playlist files . The paths that are specified in the variant playlist files can be URLs that can point to the playlists that are generated for the braodcast. Alternatively, you can do the content preparation using the tools specified in the article and leave it to a CDN such as Akamai or Amazon to do the distribution.
-Priya
Sorry actually it appears to be using the scp option in the mediastreamsegmenter…
Hey priya , i created a client side code to play it , it works but works only for HLS or downloaded video ata a time. If i play HLS first (success) then downloaded video (failure) , also the vice-versa is same…any idea… ???
Thanks…
Hi Sumit- I don’t think I understand. Do you mean “progressively downloaded” video when you are referring to “downloaded video”. I don’t think the issue has anything to do with the content that’s being played. .
What is the difference between RTSP & HLS Streaming. Also is the “HTTP Streaming” is same as “HLS Streaming” ?
Hi Rohit
RTSP is what’s typically referred to as “true streaming protocol”- there is no chunking of video streams as in the case of HLS. HTTP streaming could loosely refer to HTTP progressive download.
Please refer to http://www.priyaontech.com/2012/02/mobile-video-streaming/ for overview on various streaming technologies. There is a link to a downloadable presentation in that post.
“(You would need an Apple developer Id for installing the tools, which again is free)”
not free
I’m having trouble getting the -I command to produce a .plist file – not sure what I am doing wrong. Any suggestions? Thanks in advance!
Some of the meta files discussed above allow multiple entries so as to constitute a playlist. For Windows Media Player and for Real Player simply add lines to the corresponding meta file (i.e. m3u or ram) for each of the media files in the playlist, in the same format.
Hi Priya
Thanks for the very useful blog on HLS. Are these below tools available for windows XP/7 along with HandBrake?
mediafilesegmenter
variantplaylistcreator
I want to generate complete HLS streams on windows PC.
Thanks
JP
Thanks JP. These command line tools are available on the Mac only. There are some commercial encoding software available on Windows. I’ve personally not looked into them. You can also try http://www.ffmpeg.org
how to configure IIS for HLS streaming…..can you give detailed step by step procedure
Hi,
I used “One click m3u8” from nacentApps to create a m3u8 variant playlist.
https://itunes.apple.com/us/app/one-click-m3u8/id607270902?ls=1&mt=12
hi priya,
i am facing a problem in hls
in my Scenario my video on amazon cloud fount s3.
and my website hosted on other server so far i have created m3u8 and ts file using mediasegmenter tool.and uploaded the file on amazon.
i am using wj6 primum player(which support HLS)but i am facing a problem when i play video it gives me error “cross domain access denied could not load m3u8” after some google i found that i need to put crossdomain.xml file on the server and i did all the stuff but still i am facing the same error as mentioned above
here is my test page http://www.becomealivinggod.com/fulfill/WebSite1/dhoni1.php
my crossdomainfile
http://www.becomealivinggod.com/crossdomain.xml
could you please help me ?
thanks in advanced.
Lakhan
I’ve been using encoding.com to create HLS outputs with great success. There segmenter have gives us more granular control over settings and has improved the quality of our outputs. http://www.encoding.com/http-live-streaming-hls/
If we need to support 3 different bitrates, then do I need to have 3 input mp4 (high, medium low bitrates files) files to feed to mediafilesegmenter and variantplaylistcreator?