« "I hope it feels so good to be right. There's nothing more exhilarating than pointing out the shortcomings of others, is there?" | Main | "The rounded world is fair to see, / Nine times folded in mystery." »
May 28, 2006
Overview: Video streaming under Mac OS X Tiger with Apache, PHP, VLC, and Spotlight
Wow I feel incredibly nerdy.
I just spent the last 36 hours or so perfecting video streaming under Mac OS X.
The easiest way to stream is with QuickTime/Darwin Streaming Server. It has a directory, and if you drop any video in it, the Streaming Server recognizes it and if anyone connects over RTSP and asks for that URL, the video starts playing. Easy as pie.
Unfortunately, it doesn't have on-the-fly transcoding. That means each video has to be pre-ripped at a low bitrate and "hinted" for streaming. Pain in the ass and a waste of space. I want to stream over the Internet, but anything I rip has a bitrate in the megabits. Real-time transcoding is a necessity.
So that leaves me with Video LAN Client, which is...a work in progress. Sometimes it crashes when I add a few hundred videos at once to the playlist. Plus, when it does work, it doesn't save the playlist with hierarchies. It's just a flat list of videos, without even their full filepaths, making it damned near impossible to identify what is what. That means I can't depend on VLC to keep track of my whole library.
Now, VLC works admirably for streaming a small playlist. It has a limited VOD service called VLM, but it's awkward to have more than half a dozen videos listed in it. VLC streams single files like a champ, but it crushes under the weight of a few hundred gigs of moving pictures.
Instead, I had to find another way to build a playlist. My solution is a mix of VLC, Apache, PHP, and Spotlight.
3 http sessions running on different ports: The first encapsulates the video. The second is the VideoLAN http interface. The third is Apache.
I made a CGI script in PHP. It scans my hard drives using Spotlight, looking for all video files. It then outputs a list of them in HTML. Each line of the playlist PHP composes is a link, that, when clicked, loads the selected movie into VLC and presents the VLC web remote. Press play, and the movie is transcoded in real time to a sane bitrate and streamed over http.
Example workflow:
Colin in South Korea wants to see the latest episode of Lost some video podcast that certainly isn't protected by intellectual property rights..
In Safari, he goes to http://mymachine:23423, which is the PHP-generated playlist.
He scrolls down the alphabetical list until he sees the TV episode video podcast, and clicks on it.
The browser window refreshes and the VLC web remote appears, with the Lost episode video podcast in its playlist.
Colin clicks play.
In VLC on his laptop, Colin selects "Open Network Stream" from the File menu, and enters http://mymachine:23421 as the media resource locator.
A second later, the video starts playing.
My friend Asher made it even better, by redoing the PHP script to sort files into directory hierarchies instead of just display the full file path.
The benefit of this system is that I don't have to keep an ordered playlist of movies for video on demand. Instead, the second a video hits my hard drives, it'll show up in this list. From anywhere in the world, I can access my whole video library and select anything I want to play.
If I can make this a little easier, and maybe even if I can't, I'll try to put together a full tutorial.
Useful links:
The power of mdfind has a lot more info about Spotlight's command line interface than "man mdfind" provides.
Some faint inspiration came from episode 1x09 of Hak5.
Enabling PHP on Mac OS X was invaluable, as was Kevin Hemenway's introduction to PHP and Apache in Tiger
Direct lifting of code from streaming MythTV to your cellphone.
The idea of trans-Pacific streaming came from Miles Evans' VLC streaming tutorial.
Posted by Jon Rubin at May 28, 2006 11:33 PM
Trackback Pings
TrackBack URL for this entry:
http://www.ubiquit.us/movabletype/mt-tb.cgi/162
Comments
colin in south korea can confirm that this insanity actually works, trans-pacific. thanks again jon. now how about figuring out a way to stream cable tv ;P
Posted by: colin at May 29, 2006 12:52 AM
Dude thats awesome! Now I have even more reason to get that macbook I've been eyeballing. Way to go on the sweet hack.
Darren
Hak.5
Posted by: Darren at May 31, 2006 11:10 AM