HTTP Live Streaming
HTTP Live Streaming is a streaming standard proposed by Apple. See the latest draft standard .
Files involved
.m4a for audio (if you want only audio stream)..ts for video. This is an MPEG-2 transport, usually with a h.264 / AAC payload. It contains 10 seconds of video and is created by splitting the original video file or converting live video..m3u8 for the playlist. This is a UTF-8 version of WinAmp format.
Even when it is called streaming, there is usually a delay of one minute or so during which the video is converted, ts and m3u8 files are written, and your client updates the m3u8 file.
All these files are static files on your server. But in live events, more .ts files are added, and the m3u8 file is updated.
Since you tagged this iOS question, it is important to mention the relevant App Store rules:
- You can only use progressive download for videos of less than 10 minutes or 5 MB every 5 minutes. Otherwise, you should use HTTP Live Streaming.
- If you use HTTP Live Streaming, you must provide at least one stream with a speed of 64 Kbps or lower bandwidth (a stream with a low bandwidth can only be audio or audio with a still image).
example
Get Streaming Tools
To download the HTTP Live Streaming Tools, do this:
Installed command line tools:
/usr/bin/mediastreamsegmenter /usr/bin/mediafilesegmenter /usr/bin/variantplaylistcreator /usr/bin/mediastreamvalidator /usr/bin/id3taggenerator
Help page descriptions:
- Media Stream Segmenter: Create segments from MPEG-2 transport streams for streaming over HTTP.
- Media File Segmenter: Create segments for streaming over HTTP from media files.
- Variant Playlist Creator: Create a playlist to switch streams from HTTP Live streaming segments created by the mediafilesegmenter.
- Media Stream Validator: checks HTTP streaming streams and servers.
- ID3 Tag Generator: Create ID3 Tags.
Create video
Install Macports, go to the terminal and sudo port install ffmpeg . Then convert the video to a transport stream (.ts) using the FFMpeg script:
# bitrate, width, and height, you may want to change this BR=512k WIDTH=432 HEIGHT=240 input=${1}
This will create a single .ts file. Now we need to split the files into segments and create a playlist containing all these files. We can use the Apple mediafilesegmenter to do this:
mediafilesegmenter -t 10 myvideo-iphone.ts
This will create one .ts file for every 10 seconds of video, plus a .m3u8 file pointing to all of them.
Set up a web server
To play .m3u8 on iOS, we point to a file with a mobile safari. Of course, first we need to host them on a web server. In order for Safari (or another player) to recognize ts files, we need to add its MIME types. In Apache:
AddType application/x-mpegURL m3u8 AddType video/MP2T ts
In lighttpd:
mimetype.assign = ( ".m3u8" => "application/x-mpegURL", ".ts" => "video/MP2T" )
To link this from a web page:
<html><head> <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/> </head><body> <video width="320" height="240" src="stream.m3u8" /> </body></html>
To determine the orientation of the device, see the section βDefining and Setting the Orientation of the View Area of iPhone and iPad Using JavaScript, CSS and Meta Tagsβ .
Other things you can do is create different versions of the bitrate video, insert metadata for reading during playback as notifications, and, of course, enjoy programming with MoviePlayerController and AVPlayer.