Ok. Now, I have a confession to make. That title was cunningly designed to pull you into this post, and as cunning as I may be; I’m honest — I’ll say upfront that I haven’t got this cracked yet.

Let’s take a step back: the other night I had a random thought: you can play movies in Flash, right? And Opera, the Wii web browser, features flash! Hmmm …

My pipe dream here was something akin to the Apple TV — or at least its streaming capabilities. And cheaper. By which I mean free! I have various DIVX (and a few other formats) movies lying around, and I’d like to be able to watch them on my TV in the living room. I was hence wondering whether the Wii could stream the videos across my wireless network, from my NAS box.

I of course went looking for any software that already achieved this, but what I found I had to reject for one reason or another: many would convert the movies up front, but not stream them (e.g. Wii Transfer), and some wouldn’t work on my Mac so I didn’t even investigate them (e.g. TVersity).

Time to roll my own, then.

So, the main problem we have is that of formats; you can’t play DIVX movies in Flash. I know there are a bunch of programs out there that will convert the movies, but that rather puts me off; I’m an impatient kind of person, and I don’t want to have to convert my movies up front — that implies either keeping two copies of all my movies, or converting the movie in advance on me wanting to watch it. These ideas didn’t appeal.

Therefore, I want to convert the movies on the fly.

So I went a-Googling for converters that will write to FLV format (the Flash Video format), and quickly found ffmpeg. I’m on a Mac, and with MacPorts, installing that was as easy as “sudo port install ffmpeg +lame”.

(Side note: I didn’t discover I needed to add in LAME support for mp3 audio until later, but I’ll save you that pain :-D)

A brief skim of the manpage later, and I discovered “ffmpeg -i “my_movie.avi” -f flv -b 1000k -ar 44100 -ab 128k -” would do the job and write my FLV file to standard out. More good news: on my MacBook Pro, with my test movie, I was getting about 230/250 frames per second encoding. This was good news, because that’s way more than the 30fps I need to encode the video in real time.

I then looked for a SWF flash file that would play an arbitrary FLV file, and quickly found a good candidate in the JW FLV Player. That seems to do the job very nicely.

I originally hacked all these pieces together in a Ruby on Rails application. Things were on the verge of working, however — apart from the streaming! Both Mongrel nor Webrick — the two out-of-the-box Rails webservers — would wait until the transcoding process was complete and only then begin streaming my movie. Not good.

A fruitless search later led me to ask the guys I work with. Both Neill and Matt recommended I look at Merb; Ezra Zygmuntowicz’s lightweight ruby framework.

I was glad I did!

Within 20 minutes at most, I had that up and running, and I was exceptionally pleased to note that all my action needed to do was return the results of IO.popen(”ffmpeg etc”) - and my movie was streaming nicely through Flash. Excellent. I will definitely recommend/try Merb for projects in the future.

So, I set-up a tiny proof-of-concept app — hardcoded to play one movie — opened port 4000 on my firewall, started merb, and fired up my Wii.

To my very pleasant surprise, the movie started playing on my Wii. I was rather chuffed! The quality I had picked — pretty much entirely at random I will happily admit — wasn’t superb, but was quite watchable.

So, things were looking up! It was almost too good to be true.

It was.

After about 2 minutes, the movie stopped playing inexplicably. Some Googling reveals this appears to be a common problem; the Opera browser’s Flash plugin is crashing on other people whilst playing movies.

I’ve read a couple of opinions on why this might be; one is a running-out-of-memory problem, and suggesting the solution to stream the movie in chunks. The other suggested that it was because the movie didn’t have the Flash metadata — and it is certainly true that the SWF movie player didn’t know the length of the movie, or have working skip functionality.

So, in conclusion, this is where I’ve got. Surely this pausing problem is get-aroundable? I guess I could try watching long YouTube videos on the Wii. Has anyone tried that? (Bear in mind that if this is memory-related, I was streaming data at about 1128kbps, and I’m guessing YouTube would be a lot lower than that — so YouTube videos would “last” longer in any case.)

If any readers have any suggestions, I’m all ears! Also, if anyone wants to collaborate on getting this working with the possible aim of tidying this proof-of-concept into a working, open-source Wii movie streaming server, do let me know.

Cheers,
Neil.

P.S. Presumably one could do the same trick to play songs, and transcode songs in the iTunes format, or WMA or OGG or what-have-you into mp3 on the fly, and get them to stream to the Wii that way. I get the feeling I’ve seen this done before, but now forget where.