This "How To" recipe builds a transcoder to process live multicast streams into live and on-demand streams suitable for iPhone and similar devices. 

This single-stream example uses a multicast transport stream containing MPEG-2, but could easily use a multicast or unicast stream in a different format. This example runs on Xserve and MacPro machines, it's a requirement that mediastreamsegmenter runs on OS X.

Warning: Reticulation of broadcast TV services requires the permission of the broadcaster.

Thanks to ANU for the opportunity to test this on a multicast-rich network.

 

Live BBC stream on iPhone via HTTP at 750Kbps

 

The Result

One live MPEG-2 transport stream transcoded to be visible on the iPhone. VLC (and x264) transcode the stream to the required format for mediastreamsegmenter, which then saves the stream on disk under the webserver. It continually updates the index file so viewers can keep up. Depending on the content, the bitrate of the stream can be 500-900Kbps.

 

Web page on iPhone with text links to .m3u8 index file

 

Viewing the stream in the iPhone simulator

 

Screen shot of iPhone movieplayer without controls overlaid

 

A mid-range server can transcode three standard-definition 720×576 MPEG-2 services.

 

 

Required Parts

Documentation

mediastreamsegmenter Man Page

Apple's HTTP Live Streaming Documentation

IETF Standard Submission

VLC Command Line Help

Installation

The Apache webserver is running above a directory that will contain the media.
/Volumes/mydisk/www/abc/ in this example).

The webserver is available to the outside
(http://mywebserver.edu/abc/  in this example)

Apache mime types to be added:
AddType application/x-mpegURL m3u8
AddType video/MP2T ts

VLC is expected to be at /Applications/VLC.app/

mediastreamsegmenter gets installed to /usr/bin/mediastreamsegmenter

Your source stream is playable in VLC.
udp://@239.224.0.2:1234 in this example)

The Script

Save the script below to a text file, say abcstreamer.sh - ensure there are no carriage returns in the command lines. Customise the bold items in the command lines to suit your environment.


#!/bin/sh

rm -rf /Volumes/mydisk/www/abc/*

/Applications/VLC.app/Contents/MacOS/VLC udp://@239.224.0.2:1234 –intf=dummy –sout-transcode-audio-sync –sout='#transcode{vcodec=h264,venc=x264{aud,profile=baseline,level=30,keyint=30,bframes=0,ref=1,nocabac},acodec=mp4a,ab=56,deinterlace}:duplicate{dst=std{access=file,mux=ts,dst=-}}' | mediastreamsegmenter -O -b http://mywebserver.edu/abc/ -f /Volumes/mydisk/www/abc/ -t 10 -s 4 -D  


Change permissions for you to execute it
chmod 744 abcstreamer.sh

Run it with
./abcstreamer.sh

The Stream

Watch the directory in the Finder to see the segments arrive.  After a while the index file will be written, so you can now get the stream from your iPhone.

 

Screenshot of Folder collecting video segments

 

The stream should be available at
 
http://mywebserver.edu/abc/prog_index.m3u8
 
Open the URL in Safari on your iPhone. You can also use QuickTime Player X on a Mac desktop to "Open URL".
 
 
 
 
 


Serve It Up

Here's an index.html file for your web server showing text links to your stream. Alternatively, try the video tag in that fancy new HTML5 browser you downloaded.
 
 
<html lang="en">
<head>
<title>iPhoneTV</title>
</head>
<body>

iPhone TV<P>
<HR>
<H1><a href="./abc/prog_index.m3u8">ABC</H1>
<HR>
<H1><a href="./bbc/prog_index.m3u8">BBC</H1>
 
<!-- <video width="320" height="240">
<source src="./bbc/prog_index.m3u8" />
</video>
 -->

</body>
</html>

Stats

 
Peaks are starting a new stream.
 
 
 

Tips

  • These are by no means optimal settings, please post improvements in the comments.
  • Reset VLC's preferences to be sure you don't have any clashing settings.
  • Use mediastreamvalidator to debug the transport stream.
  • Consider DVBlast or Multicat as additional tools for streaming and routing. 

Updates

  • Added stats

 

 


 
Many thanks to the Videolan and x264 devs, and hats off to ioncannon and nerdlogger for prior art.