Streaming Local Video With Your Roku
Ever since I switched from Dish Network to a Roku player a few months ago I have had a couple of things I wanted my player to be able to do. The ability to categorize my Netflix queue is at the top of my list and it would be very cool to be able to play video from a local server. The SDK won't help me modify the Netflix application, but streaming from a local source is actually not a huge problem.
On Friday Roku finally released the SDK for their handy little Roku Video player (sometimes called a Netflix box since that was originally the only content you could stream). The SDK is free, all you have to do is signup at the developer page. The zip archive contains everything you need to get started hacking together a new channel for your Roku player.
For the most part development is cross platform. You are restricted to using their language, BrightScript, so there are no compilers or IDE needed. It helps if you have the make utility available on your system, the examples come with makefiles that will zip up the application and install it into your player with a single command. If you want nice images to show up while scanning through a video you will need to capture them from the file and create a BIF file to tell the player when to show the images. The biftool is currently only available on linux and Windows.
To be able to upload software to your player you need to enable developer mode. This is accomplished with a set of remote control keypresses. For some reason it took me about 10 tries before I got it to work. I'm still not sure if it depends on where you start from, but what finally worked for me was being at the top level channel menu with something other than settings selected.
Once that is done the box now has a simple server running on port 80 and a debug port on 8085 where you can view debug output from your app or from the system if the upload failed, or if parsing the script files failed. That's all there is to it. No cumbersome app signing needed at this point. It makes it very easy to edit, upload, try, debug, repeat. If you want to actually publish your application as a new channel for the world to use the process is more involved and requires Roku to approve your application.
The SDK includes, among other things, a couple of video examples. One simply points to a URL and plays it (the URL is hard-coded into the application). The other is more fully featured and uses TED talk videos. It allows you to setup a hierarchy of categories using a couple of XML files. This is a good place to start for streaming local content.
The first thing I did was setup an Apache 2.2.13 server on my son's Fedora11 system. I simply aliased the directory of mp4 videos and it was up and running. As a side note, Chrome (at least on OSX) can stream mp4 videos over http without installing anything else.
I then played around with the simple stream example to make sure I could actually watch the videos. They were encoded using Handbrake on either a OSX or Fedora system. Most are 1G in size or less, and I left most of the encode settings alone. I found that about the first hour streams fine, but after that point the player starts to rebuffer every minute or so. It appears to depend on the location in the file, so it may have something to do with how it was encoded.
The documentation included appears to be fairly complete. The have extensive documentation on BrightScript, and on the Roku extensions that you use to access to features of the player. I did find a couple of things that weren't described in detail, but at this point that hasn't hindered progress at all. BrightScript is a fairly simple language and anyone with programming experience should have no trouble catching on quickly.
The example video app uses a hard-coded URL for the source of the XML driving it. I added a keyboard page that prompts the user to enter the host or IP address of their video server. It saves this to the registry (persistent storage) so it only needs to be entered once. For the moment, this is really the only change I needed to make to the example application. Everything else happens on the server side.
I slapped together a Python script to take the names of my mp4 videos and generate the feed XML to drive the player. I used mp4info to pull the video's bitrate and format from the file and insert into the movie's description page. I don't have cover art for them, so that got hard-coded to a default image. The script generates a static XML file for the Roku to load when my custom application is run.
At this point I can browse the movies and play them. Mostly. I've run into a couple of glitches, and am not sure exactly what the solution for them is yet. One is that it seems that at about the 1 hour point in the video playback it starts to rebuffer every minute or two. If I stop playback, restart and skip to the 1 hour marks it still happens, so it appears to depend on the point in the file, not the time spent playing.
The other is that the aspect ratio of many of the videos isn't quite right. All of them seem to be squished to some degree or another. This is probably due to the Handbrake parameters I used when encoding them from the original DVDs. They look fine when played back on a PC but the Roku either isn't properly sizing them, or I'm doing something wrong (more than likely).
Overall I am very happy with the Roku and the SDK. They have done an excellent job of documenting the system, providing example code and especially keeping it from turning into a brick. Several times I have managed to get it to lock up and reset itself. It has always come right back up with no problems. I am looking forward to seeing what other channels people come up with. On the top of the list for me is Hulu streaming, but I'll leave that up to someone else to implement.
You can look at my code, for what its worth, at my bitbucket homevideo repository.
NOTE This project morphed into the Home Media Server project, the code for that can be found here on GitHub