Avatar
Entrepreneur, Software Architect & Developer, etc.

How to Stream Video to an iPhone or iPad

This might seem like a simple process, and it really is, after you scour the web looking for the right documentation and bug fix workarounds from other developers.

This article covers the simple technical details of streaming a single video from a web server on an iOS device.

Our requirements were simple.  Take a simple video, in MP4 format (or .MOV or something similar), and stream this video from an Apache web server to an iPhone.

Steps to follow:

  1. Get familiar with the Apple HTTP Live Streaming documentation.

  2. Download and install the HTTP Live Streaming tools at http://connect.apple.com.  You’re going to need a Apple Developer License to get to this website.  Once logged in,click on the iPhone link under Downloads to get to the HTTP Live Streaming tools.  You should see the following page:
  3. We’re now ready to segment our video using the Media File Segmenter.  On the command line, type something like this: mediafilesegmenter movie.mp4.
  4. (From Apple Documentation) The Media File Segmenter (mediafilesegmenter) divides a .mov, .mp4, .m4v, .m4a, or .mp3 file into small media segments and creates an index file. The index file and media segments can be deployed using almost any web server infrastructure for streaming to iPhone and Mac OS X 10.6 Snow Leopard. The Media File Segmenter only produces VOD streams.

    The mediafilesegmenter will produce a series of .ts files (fileSequence0.ts, fileSequence1.ts…) and and index file (prog_index.m3u8).

    NOTE: If mediafilesegmenter does not create .ts files for you, you’ll need to open the Quicktime Player, open your video file and then choose “File/Save for Web…”.  This will convert the file to the proper format for mediafilesegmenter.

  5. Copy the .m3u8 and .ts files to your web server.  Put them in a separate folder if you like.

  6. Test to make sure the video is ok.  This can be done a few ways.  You could load the url into the Quicktime Player (via File/Open URL…)  Make sure that you use the url of the .m3u8 file (i.e. http://hostname/prog_index.m3u8).  Or just open the url in Safari.  You should see the video playing if everything is ok.

  7. If the video does not play in step 5, your web server might not support these file types by default.  You’ll need to add support for the specific media file types.  For Apache servers you can add the following settings in the http.conf file:
  8. Finally, you’ll need to write some iOS code to play the video.  We couldn’t get the Apple sample code to work with streaming video, so we wrote a simple test app to get it working. 
  9. NOTE: Make sure you address the .m3u8 file in the URL of the video to be streamed (i.e. http://hostname/prog_index.m3u8).  We couldn’t find any documentation that made this clear.

    Download the code here to try it out yourself.

1 noteShowHide

  1. toddfearn posted this