PS3 Streaming Video: Mediatomb
Many of us HD junkies no doubt own a PlayStation 3 already: it’s one of the cheapest and best Blu-ray players on the market.
What many of us don’t know or fail to forget is that the PS3 also can play streaming content (video, audio, and pictures) from any Universal Plug and Play (UPnP) server on its local LAN. What is UPnP, you ask? It’s a glorified file server, essentially, that is made for media sharing.
In order to consolidate my home theater, I decided to start playing with getting my PS3 to stream videos from my Mac Pro: at home, we run almost all Macs (a Linux server here or there for Linux stuff, and a Windows partition here or there for stubborn video games and Netflix). This presents a greater challenge for running a PS3-compliant UPnP server, since there are almost no UPnP servers for OS X, and fewer free ones.
However, after perusing around the tubes for quite a while, I stumbled upon the open-source UPnP server Mediatomb. It works on OS X and Linux currently. It’s really meant for Linux, and there are already other guides out there for installing and using it on Linux, like this one (which also makes a great reference for OS X users, too). We’ll focus on OS X, since it’s where my media is, and it’s a bit less trivial to get working there.
Note that this software very beta-quality, with a few gremlins here and there. I’ll point them out where I know some to be.
First, you’ll need Fink (or your other favorite UNIX package manager for OS X). Use it to install Mediatomb.
Next, you’ll need to configure Mediatomb. If you just run mediatomb from your Terminal, it should give you a fairly decent default config file in your home directory, under .mediatomb/config.xml. You need to change one line that says <protocolInfo extend=”yes”/>
At this point, with Mediatomb started, you should might see it pop up on your PS3 Videos menu. If so, you can then point your web browser at http://your-server:49152 (insert the correct server name for your Mediatomb server, and whatever port it happens to be running on, which is spit out when you start Mediatomb).
Click on “File System”, and browse to the folder that your media are in. (It can often have a medium delay before it expands folders — if the eyes on the skull in the upper left are glowing red, then it’s busy working.) Once in that folder, you need to press the + button the upper-right to add that to your media library. The + button with the circle gives you options to automatically scan the directory at certain intervals.
What if your PS3 doesn’t see it? Well, the most likely reason is that it is bound to the wrong IP address. It seems to bind to one almost randomly on my box, so it chose my VMware interface at first. The way around that is to run it with a command-line option specifying an IP address to bind to. For example, to bind to 10.0.0.10, you would run the command mediatomb -i 10.0.0.10. (Note that you cannot bind to 0.0.0.0, which is normally an alias for all IP addresses — this seems to break the UPnP functionality.)
Also, make sure that your PS3 is connected to the same physical LAN segment as your Mediatomb server. I’d recommend using the Ethernet jack in the back, since streaming video can be sensitive to jitter and interference, as well as being a bandwidth hog.
…
Now, there are two revelations you might make at this point. First, you’ll notice that Mediatomb dumps all of your videos into one giant “Videos” folder. Sorry, there doesn’t appear to be a way around this. It does auto-sort your music by album, artist, year, etc., though. Hopefully this will be addressed in future versions.
Next, you’ll note that the PS3 has rather limited support for video files. It supports MPEG2 and MPEG4 (including DivX), along with a handful of other formats, like VC-1. The best way to ensure compatibility is to use a tool that knows PS3 preferences and can output them (like the PS3 setting in Handbrake). Fortunately, there is a way around that, mostly, but it’s kind of ugly.
We can use ffmpeg to transcode some of that video, live and streaming, to your PS3. First, install ffmpeg using Fink.
Now, you will need to create two files to transcode video and audio, respectively. These are adapted from the Gentoo tutorial referenced above. (Just save them somewhere and make sure they are executable.)
The audio transcoder (mediatomb-transcoder-audio)
#!/bin/bash
INPUT="$1"
OUTPUT="$2"
AUDIO_CODEC="pcm_s16le"
AUDIO_BITRATE="192k"
AUDIO_SAMPLERATE="44100"
AUDIO_CHANNELS="2"
FORMAT="s16le"
exec /sw/bin/ffmpeg -i "${INPUT}" -acodec ${AUDIO_CODEC} -ab ${AUDIO_BITRATE} \
-ar ${AUDIO_SAMPLERATE} -ac ${AUDIO_CHANNELS} -f ${FORMAT} - > "${OUTPUT}" 2>/dev/null
and the video transcoder (mediatomb-transcoder-video):
#!/bin/bash
INPUT="$1"
OUTPUT="$2"
VIDEO_CODEC="mpeg2video"
VIDEO_BITRATE="4096k"
VIDEO_FRAMERATE="25"
AUDIO_CODEC="mp2"
AUDIO_BITRATE="192k"
AUDIO_SAMPLERATE="44100"
AUDIO_CHANNELS="2"
FORMAT="dvd"
exec /sw/bin/ffmpeg -i "${INPUT}" -vcodec ${VIDEO_CODEC} -b ${VIDEO_BITRATE} \
-r ${VIDEO_FRAMERATE} -acodec ${AUDIO_CODEC} -ab ${AUDIO_BITRATE} -ar ${AUDIO_SAMPLERATE} \
-ac ${AUDIO_CHANNELS} -f ${FORMAT} - > "${OUTPUT}" 2>/dev/null
Now, modify your .mediatomb/config.xml file to have transcoding enabled:
First, ignore the line that says “Uncomment the following line for PS3 divx support”. It breaks transcoding. Then, add the following lines to your config file:
<transcoding enabled="yes">
<mimetype-profile-mappings>
<transcode mimetype="video/x-msvideo" using="video-common" />
<transcode mimetype="video/x-flv" using="video-common"/>
<transcode mimetype="application/ogg" using="video-common"/>
<transcode mimetype="application/ogg" using="audio-common"/>
<transcode mimetype="audio/x-flac" using="audio-common"/>
</mimetype-profile-mappings>
<profiles>
<profile name="audio-common" enabled="yes" type="external">
<mimetype>audio/L16
<accept-url>yes
<first-resource>yes
<accept-ogg-theora>no
<agent command=”mediatomb-transcode-audio” arguments=”%in %out”/>
<buffer size=”1048576″ chunk-size=”131072″ fill-size=”262144″/>
</profile>
<profile name=”video-common” enabled=”yes” type=”external”>
<mimetype>video/mpeg
<accept-url>yes
<accept-ogg-theora>yes
<agent command=”mediatomb-transcode-video” arguments=”%in %out” />
<buffer size=”14400000″ chunk-size=”524288″ fill-size=”524288″/>
</profile>
</profiles>
</transcoding>
Now restart Mediatomb, and it should work.
One disadvantage is that you can’t seem to pause, rewind, or fast forward using this method. Second, video support is still a bit spotty: some videos, work, and some don’t. Often it’s due to poorly encoded video, other times because it’s just a bizarre or mislabeled video. YMMV.
Two final notes: Mediatomb won’t start automatically on its own. You have to do it yourself, and leave it running (either in daemon mode by giving it a -d on startup, or launching it in a screen. You could probably use OS X’s launch services to manage this, too.
And finally, Fink’s Mediatomb package does not come with MySQL support by default. This makes it run a bit slow, and the database tends to become corrupt fairly easily. I’d suggest being a bit careful, and try not to load it down with more than a few hundred videos and songs, if possible.
Have fun!
Tags: Blu-Ray, fink, linux, mediatomb, os x, PS3, Streaming, video
4 opinions for PS3 Streaming Video: Mediatomb
Owen
Jun 26, 2008 at 1:09 am
Hey, I just tried your config snippet for the transcode bit and I get an XML error. What version mediatomb are you using?
Christopher Swenson
Jun 27, 2008 at 9:34 pm
I installed using Mediatomb 0.11.0. I know that the transcode feature has only been included fairly recently, so you may just try upgrading.
Good luck.
Brad
Jul 3, 2008 at 2:32 am
Has anyone used Leopard’s launchd service to set mediatomb to start on startup, I have very little programming knowledge and couldn’t work it out. At the moment I’m just strong-arming it with an applescript that starts automatically on startup.
Probably the least eloquent way possible.
tell application “Terminal”
activate
tell application “System Events” to keystroke “mediatomb -d”
tell application “System Events” to keystroke return
delay 2 — (seconds)
quit
end tell
If anyone writes a launchd daemon, I’d love to see a copy
Cheers
Christopher Swenson
Jul 8, 2008 at 6:15 am
@Brad,
I can write a launchd script for mediatomb later today. I’ll admit that they’re a little confusing, but I just hadn’t written one because I have mine permanently running in a screen so that I can see what is going on.
Have an opinion? Leave a comment: