Sunday, April 17, 2011

sopcast on AppleTv 2 with my macbook pro

Ever wanted to watch a soccer game with sopcast on your TV with your AppleTv 2 and your mac?
I've just managed to do it yesterday and thought it would be a good idea to explain the whole process.

Before we dive in the whole process, I'd like to thank Erica Sadun for her article on playing DVD on appletv and her excellent tool Airflick.
Secondly, I'd like to thank rfuilrez for his article about playing sopcast on OS X.
The following recipe is based on these 2 articles, you can have a look at them if you find my explanations not clear enough.

Like any good recipe, let's start with the ingredients. You'll need to download the following software before starting:

Start by installing VLC, Virtualbox, Keka and Airflick. I won't cover the installation of these 3 software in this article, they are straightforward.
If you have never used Airflick before, I suggest you play a little with it before going on, as you need to check if it works well with your AppleTV before starting.

I suggest you create a folder named sopcast and put sp-auth.tgz, libstdcpp5.tgz and Ubuntu_server_10-04-2.7z inside this folder.

Installing sopcast on Ubuntu server

  1. Unzip Ubuntu_server_10-04-2.7z with Keka, you should end up with a folder named Ubuntu server 10.04.2 that contains a few files.
  2. In folder Ubuntu server 10.04.2, double-click on Ubuntu server 10.04.2.vbox to launch Virtualbox with this image
  3. Start the image and log in (login: ubuntu, password: reverse)
  4. Check that linux is connected properly to your LAN (gets an IP with ifconfig address and can ping your OS X machine). If you encounter some problems, check the network settings of the image in Virtualbox (network adapter enabled, in bridge mode).
  5. Open a terminal on your OS X machine, and go to your sopcast folder
  6. Copy sopcast files to ubuntu server using scp: scp *.tgz ubuntu@UBUNTU_IP:/home/ubuntu where UBUNTU_IP is the IP address of your Ubuntu server
  7. Login to your Ubuntu server with ssh : ssh ubuntu@UBUNTU_IP and provide the password
  8. Execute ls and you should see files sp-auth.tgz and libstdcpp5.tgz
  9. Untar sp-auth.tgz: tar -zxvf sp-auth.tgz
  10. Untar libstdcpp5.tgz: tar -zxvf libstdcpp5.tgz
  11. Copy libstdcpp5 files to /usr/lib : sudo cp -v ./usr/lib/* /usr/lib
  12. Check if sopcast can be run: sp-auth/sp-sc-auth , it should show the usage message

Find a sopcast stream, basically it is an URL with the following form: sop://broker1.sopcast.com:3912/XXXX where XXX is the stream identifier (a large number).
Once you have find your stream, you can launch sopcast in your ssh shell with the following command:

sp-auth/sp-sc-auth sop://broker1.sopcast.com:3912/XXXX 3908 8908


You should see some text displayed, that means that the stream is being downloaded from your Ubuntu server and forward HTTP to port 8908

Run VLC and the apache server on OS X

  1. Run VLC, in the menu select File > Network Stream and enter http://UBUNTU_IP:8908
  2. After some time, you should see the sopcast video
If everything is fine, stop VLC and let's move on to showing the video on your AppleTv.
  1. On OS X, create a directory named stream in /Library/WebServer/Documents , it will contain the data that will be streamed to AppleTv
  2. Add two lines to file /etc/apache2/mime.types:
application/x-mpegURL m3u8
video/MP2T ts
  1. Enable OS X apache server by going to System Preferences>Sharing and checking web sharing
  2. On the right side on the System Preferences, you can see the http URL to access your server, remember it
  3. Enter the URL in Safari, you should see "It works" displayed in the browser
  4. Open a new Terminal window and launch the following: /Applications/VLC.app/Contents/MacOS/VLC -vv http://UNBUNTU_IP:8908 --intf=rc '--sout=#transcode{vcodec=h264,vb=2048,acodec=mp4a,ab=192}:standard{mux=ts,dst=-,access=file}' | mediastreamsegmenter -f /Library/WebServer/Documents/stream -D
  5. Open a new terminal window, go to /Library/WebServer/Documents/stream and type ls
  6. You should have file prog_index.m3u8 and several files with ts extension...so far so good

Send data to AppleTv

  1. Launch Safari and enter the http URL followed by /stream/prog_index.m3u8 , it should be downloaded properly (it is just a test)
  2. Launch Airflick and wait for it to detect your AppleTv
  3. Enter the URL of step 1 in the text box and press the Play button

If everything is fine, you can now watch your program on your TV. Enjoy!!