iPhone streaming

i’ve been looking for info on how to do this for ages. in the end it took two different sources to make sense of what needed to be done!

pre-reqs

  • osx 10.6
  • web sharing is enabled and we’ll be using your ~/Sites directory (http://macs.ip.address/~yourUserID)
  • vlc 1.0.5
  • mediastreamsegmenter (bundled with snowleopard, yes there’s an open source implementation see [1], but the command line usage is different. you’re better off using carson’s tutorial if you’ve only got this option)
  • some sample videos

how to
http live streaming allows you to stream video to an iphone. one of its coolest feature is the ability to switch to different video bitrate streams based on the data connection to your iphone i.e. switches to 96Kbps on 3g and 384Kbps on wlan. for this “how to” i don’t plan on utilising the variable bandwidth support, instead i will stick to 96Kbps video bitrate.

here’s a simple block diagram to explain how we get from the full fat video to something an iphone on the road can deal with

[video/divx] => [vlc] =transcoding=> [video/h.264/video bitrate 96kbs/audio bitrate 64kbs] => [mediastreamsegmenter] =um segmenting=> [*.ts and prog_num.m38u] => [webspace] => [iphone]

finally, here’s the bit you came for (via google no doubt). a nice script to transcode and segment the stream:

stream2iphone.sh:

#/bin/sh
/Applications/VLC.app/Contents/MacOS/VLC -vvv -I dummy "$1" \
--sout-x264-level=31 --sout-x264-profile=baseline \
--sout-x264-aud \
--sout="#transcode{vcodec=h264,samplerate=44100,vb=96,fps=30,\
acodec=mp3,ab=64,height=240,width=320,scale=1}:\
standard{access=file,mux=ts,dst='-'}" | \
mediastreamsegmenter -f /Users/booyaa/Sites

# perform some housekeeping
rm ~/Sites/*.ts
rm ~/Sites/*.m3u8

before you run the script you’ll also need to create the index.html (nicked from [1]):

<html>
  <head>
    <title>NSFW FTW LOL</title>
    <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
  </head>
  <body style="background-color:#FFFFFF; ">
    <center>
      <video width='150' height='150' src="prog_index.m3u8" />
    </center>
  </body>
</html>

script usage: stream2iphone.sh

finally you can now point your iphone to your mac’s webspace http://ip.address.of.mac/~yourUserName/

of course, now that you stream a video file, there’s no reason why you can’t stream a live video feed. which is what i did in the next youtube video: i streamed me playing animal crossing on the wii!

sources
[1] http://www.ioncannon.net/programming/452/iphone-http-streaming-with-ffmpeg-and-an-open-source-segmenter/
[2] http://forum.videolan.org/viewtopic.php?f=4&t=67661&p=225262#p224915

http://linux.goeszen.com/http-live-streaming-to-the-iphone.html