MediaTomb and PS3

Mediatomb is an open source (GPL) UPnP MediaServer with a nice web user interface. It allows you to stream your digital media through your home network and listen to/watch it on a variety of UPnP compatible devices.

Sony's PlayStation 3 is one of those UPnP compatible devices - but it's got its quirks. It took me a while to get my setup working the way I like it, so I guessed I might just as well post my config up here.

First of all the config file, located in /etc/mediatomb/config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config version="1" xmlns="http://mediatomb.cc/config/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mediatomb.cc/config/1
http://mediatomb.cc/config/1.xsd">
  <server>
    <interface>eth0</interface>
    <port>50000</port>
    <pc-directory upnp-hide="yes"/>
    <ui enabled="yes">
      <accounts enabled="no" session-timeout="30">
        <account user="mediatomb" password="mediatomb"/>
      </accounts>
    </ui>
    <name>MyMediatomb</name>
    <udn>uuid:4105837b-0437-4848-9bea-xxxxxxxxxxxx</udn>
    <home>/var/lib/mediatomb</home>
    <webroot>/usr/share/mediatomb/web</webroot>
    <storage>
      <sqlite3 enabled="yes">
        <database-file>sqlite3.db</database-file>
      </sqlite3>
      <mysql enabled="no">
        <host>localhost</host>
        <username>mediatomb</username>
        <database>mediatomb</database>
      </mysql>
    </storage>
    <protocolInfo extend="yes"/>
  </server>
  <import hidden-files="no">
    <filesystem-charset>UTF-8</filesystem-charset>
    <metadata-charset>ISO-8859-15</metadata-charset>
    <scripting script-charset="UTF-8">
      <common-script>/usr/share/mediatomb/js/common.js</common-script>
      <playlist-script>/usr/share/mediatomb/js/playlists.js</playlist-script>
      <virtual-layout type="js">
        <import-script>/etc/mediatomb/import-custom.js</import-script>
      </virtual-layout>
    </scripting>
    <mappings>
      <extension-mimetype ignore-unknown="no">
        <map from="mp3" to="audio/mpeg"/>
        <map from="ogm" to="video/oggmedia"/>
        <map from="mkv" to="video/matroska"/>
        <map from="iso" to="video/dvdiso"/>
        <map from="wmv" to="video/x-ms-wmv"/>
        <map from="flv" to="video/x-flv"/>
        <map from="avi" to="video/avi"/>
        <map from="rm" to="video/realmedia"/>
        <map from="srt" to="video/subtitle"/>
        <map from="sub" to="video/subtitle"/>
        <map from="mpg" to="video/mpeg"/>
      </extension-mimetype>
      <mimetype-upnpclass>
        <map from="audio/*" to="object.item.audioItem.musicTrack"/>
        <map from="video/*" to="object.item.videoItem"/>
        <map from="image/*" to="object.item.imageItem"/>
      </mimetype-upnpclass>
      <mimetype-contenttype>
        <treat mimetype="audio/mpeg" as="mp3"/>
        <treat mimetype="image/jpeg" as="jpg"/>
        <treat mimetype="video/avi" as="avi"/>
      </mimetype-contenttype>
    </mappings>
  </import>
  <transcoding enabled="yes">
    <mimetype-profile-mappings>
      <transcode mimetype="video/transcode" using="mencoder-int"/>
      <transcode mimetype="video/realmedia" using="mencoder-int"/>
      <transcode mimetype="video/oggmedia" using="mencoder-720"/>
      <transcode mimetype="video/matroska" using="mencoder-720"/>
      <transcode mimetype="video/dvdiso" using="mencoder-iso"/>
      <transcode mimetype="video/subtitle" using="mencoder-sub"/>
    </mimetype-profile-mappings>
    <profiles>
      <profile name="mencoder-sub" enabled="yes" type="external">
        <mimetype>video/mpeg</mimetype>
        <accept-url>yes</accept-url>
        <first-resource>yes</first-resource>
        <accept-ogg-theora>yes</accept-ogg-theora>
        <agent command="/usr/local/bin/mediatomb-mencoder-sub" arguments="%in %out"/>
        <buffer size="1000000" chunk-size="512000" fill-size="20480"/>
      </profile>
      <profile name="mencoder-int" enabled="yes" type="external">
        <mimetype>video/mpeg</mimetype>
        <accept-url>yes</accept-url>
        <first-resource>yes</first-resource>
        <accept-ogg-theora>yes</accept-ogg-theora>
        <agent command="mencoder" arguments="%in -oac lavc -ovc lavc -of mpeg -lavcopts vcodec=mpeg2video:keyint=1:vbitrate=200000:vrc_maxrate=9000:vrc_buf_size=1835 -ofps 25 -mpegopts muxrate=12000 -af lavcresample=44100 -vf harddup -o %out"/>
        <buffer size="1000000" chunk-size="512000" fill-size="20480"/>
      </profile>
      <profile name="mencoder-720" enabled="yes" type="external">
        <mimetype>video/mpeg</mimetype>
        <accept-url>yes</accept-url>
        <first-resource>yes</first-resource>
       <accept-ogg-theora>yes</accept-ogg-theora>
        <agent command="mencoder" arguments="%in -aid 0 -sid 0 -oac lavc -ovc lavc -of mpeg -lavcopts vcodec=mpeg2video:keyint=1:vbitrate=200000:vrc_maxrate=12000:vrc_buf_size=1835 -mpegopts muxrate=12000 -vf harddup,scale -zoom -xy 720 -font /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf -subfont-autoscale 0 -subfont-text-scale 20 -slang nl,en -noautosub -ofps 24000/1001 -o %out"/>
        <buffer size="1000000" chunk-size="512000" fill-size="20480"/>
      </profile>
      <profile name="mencoder-iso" enabled="yes" type="external">
        <mimetype>video/mpeg</mimetype>
        <accept-url>yes</accept-url>
        <first-resource>yes</first-resource>
        <accept-ogg-theora>yes</accept-ogg-theora>
        <agent command="/usr/local/bin/mediatomb-mencoder-iso" arguments="%in %out"/>
        <buffer size="1000000" chunk-size="512000" fill-size="20480"/>
      </profile>
    </profiles>
  </transcoding>
</config>

As you can tell, there's a lot of transcoding profiles in there. The mencoder-int profile is used to transcode anything that should play, but doesn't - DIVX movies with QPeL, wonky audio codecs, realmedia files, ... All of those are tagged "video/transcode" - some automatically, like realmedia, others manually in the mediatomb web UI - and piped through mencoder: audio and video become MPEG2.

The mencoder-720 profile is used only for funky container formats here, such as OGM or MKV. The ones I have usually contain more than one audio track and a few subtitles, so I tell mencoder to select the first audio and subtitle track. Don't worry about the -ofps option; that one was needed to fit one particular set of files.