About once a year I dabble with trying to setup a video streaming server so I can watch movies on my Mac which doesn’t have a DVD reader on it. Usually this all falls apart because the debug loop is the scale of a DVD, the free tools are all full of personality, and the world of video encoding is quite confusing. This time I think I got it. So here some tricks I picked up along the way.
Darwin Streaming Server isn’t hard to set up. I have it serving up files who’s extension is m4v, which I assume stands for mp4 video.
I use HandBrake on the Mac to rip the DVDs. In fact I use HandBrakeCLI to rip them. A command like:
HandBrakeCLI --preset Universal --input /dev/disk3 --output foo.m4v rip and convert DVD into a single file that is 1 to 2.5 Gig in size.
While that foo.m4v file can be served by Darwin Streaming Server your better off if you add so called hints to the file. These are apparently nonstandard mark up that Apple invented to make it possible to seek to arbitrary points in your movie. While there are signs that “QT Sync” can do hinting I ended up using mp4creator to do it. In addition to hinting you can optimize, so while I have no idea what that does, I do that as well. Hinting is a pain because you need to do one pass to hint the video track and another pass to hint the audio track. So you end up doing something like this:
mp4creator --hint=1 "foo.m4v" ; mp4creator --hint=2 "foo.m4v" ; mp4creator -optimize "foo.m4v"
In that example the numbers 1 and 2 are denote the track number to hint. Those are reasonably dependable; but to be save you can use
mp4creator -list foo.mp4v to be sure. I wrote a bit of perl to glean out the right numbers and gin up the commands to do the hinting.
Usually when you stick a DVD into a mac the operating system launches the DVD player, but you can change that behavior in the CDs and DVDs Preference Panel. Using that I launch an apple script. Since I’m more fluent in shell scripting I have that turn around an launch a shell script. That script devolved from other examples I found around the net. The essoteric bit-o-clever in it are useful; so it appears below. It has an unfortunate flaw that the heuristic for guessing which disks are DVDs sometimes gets the wrong answer; but it’s good enough for now.
My shell script then: 1) runs HandBrakeCLI, 2) ejects the DVD, 3) hints, optimizes, and 4) moves the result into appropriate directory for the Darwin Streaming Server. A little cgi script then enumerates what’s available to machines on my household’s local network.
tell application “System Events” to set DVDs to name of disks whose capacity is less than 8.589934592E+9
set dvdPath to quoted form of (POSIX path of item 1 of DVDs)
do shell script “/Users/bhyde/bin/snarf_dvd.sh “ & dvdPath