Installing MediaTomb 0.12
1. Introduction
2. Install the Mediatomb dependancies
3. Install lastfmlib
4. Install Mediatomb
5. Configuring Mediatomb
5.1 Mediatomb user account
5.2 Mediatomb first test
5.3 Mediatomb init script
5.4 Last.fm
5.5 Hide PC Directory
5.6 Mediatomb PS3 Compatibility
5.7 Charsets
5.8 Audio and Video Transcoding
5.9 Video Import
5.10 Photo Import
5.11 Video Thumbnails
5.12 YouTube
5.13 Apple Movie Trailers
Introduction
After reading that Mediatomb 0.12 supports Last.fm scrobbling I needed it in my life! So, this are my notes (see the references below) about how I install Mediatomb 0.12 from source from source. At the time of writing Mediatomb 0.12 SVN 2025 was used. I install Mediatomb on Ubuntu Karmic 9.10 Server, most of the Mediatomb dependencies are installed from packages with a few built from source. My Mediatomb server runs in a virtual machine and is dedicated to media streaming, which is why I am happy to build from source rather than use packages exclusively. NOTE! These instruction are specific to Ubuntu 9.10 Karmic.Install the Mediatomb dependancies
aptitude -y install ffmpeg ffmpegthumbnailer libavcodec-extra-52 \ libavdevice-extra-52 libavfilter-extra-0 libavformat-extra-52 \ libavutil-extra-49 libavcodec-dev libavdevice-dev libavfilter-dev \ libavformat-dev libavutil-dev libffmpegthumbnailer-dev libdvdread-dev \ libdvdnav-dev libfaac-dev libfaad-dev libmp3lame-dev libmp4v2-dev \ libopencore-amrnb-dev libopencore-amrwb-dev libxvidcore4-dev libx264-dev \ libexif-dev libtag1-dev libcurl4-gnutls-dev libexpat1-dev libmagic-dev \ libmozjs-dev libmysqlclient-dev libsqlite3-dev x264 zlib1g-dev
Install lastfmlib
lastfmlib is a C/C++ library to scrobble your tracks on Last.fm, it include a patch for Mediatomb.wget -c http://lastfmlib.googlecode.com/files/lastfmlib-0.4.0.tar.gz tar zxvf lastfmlib-0.4.0.tar.gz cd lastfmlib-0.4.0 ./configure --prefix=/usr/local --enable-logging make make install
Install Mediatomb
Fetch the latest sources from the Subversion repository.cd wget -c http://lastfmlib.googlecode.com/svn/trunk/mediatomb.patch svn co https://svn.mediatomb.cc/svnroot/mediatomb/trunk/mediatomb mediatomb cd mediatomb patch -p0 < ../mediatomb.patch autoreconf -i ./configure --prefix=/usr/local --with-liblastfmlib-h=/usr/local/include --with-liblastfmlib-libs=/usr/local make make install
Configuring Mediatomb
Mediatomb user account
The first thing we should do is create a user for Mediatomb to use. The command below adds a new user, called 'mediatomb', with no password, no login capability but membership of additional useful groups.adduser --add_extra_groups --disabled-login --shell /usr/sbin/nologin mediatomb
Mediatomb first test
Run the following to enter a shell running in the context of the 'mediatomb' user we just created.sudo -u mediatomb -s -HNow start mediatomb.
mediatombYou should see something like the following...
MediaTomb UPnP Server version 0.12.0 - http://mediatomb.cc/ Copyright 2005-2008 Gena Batsyan, Sergey Bostandzhyan, Leonhard Wimmer. MediaTomb is free software, covered by the GNU General Public License version 2 2009-02-02 17:52:33 INFO: MediaTomb configuration was created in: /home/mediatomb/.mediatomb/config.xml 2009-02-02 17:52:33 INFO: Loading configuration from: /home/mediatomb/.mediatomb/config.xml 2009-02-02 17:52:33 INFO: UUID generated: 0216e42a-24a4-49d7-a6de-81c23e0129bc 2009-02-02 17:52:33 INFO: Checking configuration... 2009-02-02 17:52:33 INFO: Setting filesystem import charset to UTF-8 2009-02-02 17:52:33 INFO: Setting metadata import charset to UTF-8 2009-02-02 17:52:33 INFO: Setting playlist charset to UTF-8 2009-02-02 17:52:33 INFO: Configuration check succeeded. 2009-02-02 17:52:33 WARNING: Sqlite3 database seems to be corrupt or doesn't exist yet. 2009-02-02 17:52:33 INFO: no sqlite3 backup is available or backup is corrupt. automatically creating database... 2009-02-02 17:52:33 INFO: database created successfully. 2009-02-02 17:52:33 INFO: Initialized port: 49152 2009-02-02 17:52:33 INFO: Server bound to: 192.168.1.12 2009-02-02 17:52:34 INFO: MediaTomb Web UI can be reached by following this link: 2009-02-02 17:52:34 INFO: http://192.168.1.12:49152/You should be able to connect to the Mediatomb Web UI using the URL shown in your log.
Mediatomb init script
I want Mediatomb to automatically start and stop when the computer boots up or shutdown. The init script and associated configuation files is a blant rip off of what comes with the Mediatomb 0.11 packages ;-)Mediatomb defaults
First create the default settings file for Mediatomb.sudo nano /etc/default/mediatombAdd the following code, the save the file.
# Set whether the daemon should be started. Set this value to anything # but 'yes' to enable the daemon NO_START="no" # Additional options that are passed to the daemon. OPTIONS="" # The network interface for MediaTomb to bind to and for which the multicast # routing entry should be added; "" if the route shouldn't be added at all. # For example: INTERFACE="eth0" INTERFACE="eth0" # The route command and arguments to be used if INTERFACE is defined. # These variables should normally be left unmodified. ROUTE_ADD="/sbin/route add -net 239.0.0.0 netmask 255.0.0.0" ROUTE_DEL="/sbin/route del -net 239.0.0.0 netmask 255.0.0.0" # The user and group that MediaTomb should be run as. USER="mediatomb" GROUP="mediatomb"
Mediatomb Script
Now create the Mediatomb init scriptsudo nano /etc/init.d/mediatombAdd the following code, the save the file.
#! /bin/sh # # MediaTomb initscript # # Original Author: Tor Krill <tor@excito.com>. # Modified by: Leonhard Wimmer <leo@mediatomb.cc> # Modified again by Andres Mejia <mcitadel@gmail.com> to # base it off of /etc/init.d/skeleton # Modified again by Flexion.Org <flexiondotorg@gmail.com> to # reference /usr/local/ and ~/ for a simple from source build # # ### BEGIN INIT INFO # Provides: mediatomb # Required-Start: $all # Required-Stop: $all # Should-Start: $all # Should-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: upnp media server ### END INIT INFO # Do NOT "set -e" # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin DESC="upnp media server" NAME=mediatomb DAEMON=/usr/local/bin/$NAME PIDFILE=/var/run/$NAME.pid LOGFILE=/var/log/$NAME.log SCRIPTNAME=/etc/init.d/$NAME DEFAULT=/etc/default/$NAME # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present [ -r $DEFAULT ] && . $DEFAULT # Load the VERBOSE setting and other rcS variables [ -f /etc/default/rcS ] && . /etc/default/rcS # Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions # Start the daemon if NO_START is disabled in DEFAULT if [ "$NO_START" = "yes" ]; then test "$1" = "start" && \ { log_warning_msg "$NAME: Not starting $DESC." log_warning_msg "$NAME: Disabled in $DEFAULT." } exit 0 fi # Run as root if USER not specified if [ ! $USER ]; then USER=root fi # Check for an invalid user or one without a home directory eval USERHOME=~$USER if [ "${USERHOME#/}" = "${USERHOME}" ]; then log_failure_msg "$NAME: The user '$USER' specified in $DEFAULT is invalid." exit 1 fi if [ "$INTERFACE" != "" ] ; then INTERFACE_ARG="-e $INTERFACE" else INTERFACE_ARG="" fi DAEMON_ARGS="-c /home/$USER/.mediatomb/config.xml -d -u $USER -g $GROUP -P $PIDFILE -l $LOGFILE $INTERFACE_ARG $OPTIONS" # # Function that starts the daemon/service. # do_start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started touch $PIDFILE chown $USER:$GROUP $PIDFILE touch $LOGFILE chown $USER:$GROUP $LOGFILE start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \ --test > /dev/null \ || return 1 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ $DAEMON_ARGS \ || return 2 } # # Function that stops the daemon/service. # do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 rm -f $PIDFILE return "$RETVAL" } # # Function that sends a SIGHUP to the daemon/service. # do_reload() { start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME return 0 } case "$1" in start) if [ -n "$INTERFACE" ]; then # try to add the multicast route if [ "$VERBOSE" != no ]; then { log_action_begin_msg \ "$NAME: Trying to add the multicast route" $ROUTE_ADD $INTERFACE \ && log_action_end_msg 0 } || { true && \ log_warning_msg "Failed to add multicast route. skipping." } else $ROUTE_ADD $INTERFACE >/dev/null 2>&1 || true fi fi log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0) log_end_msg 0 ;; 1) log_warning_msg "$DESC" "'$NAME'" "was already started" ;; 2) log_end_msg 1 ;; esac ;; stop) log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0) log_end_msg 0 if [ -n "$INTERFACE" ]; then # try to add the multicast route if [ "$VERBOSE" != no ]; then { log_action_begin_msg \ "$NAME: Trying to delete the multicast route" $ROUTE_DEL $INTERFACE \ && log_action_end_msg 0 } || { true && \ log_warning_msg \ "Failed to delete multicast route. skipping." } else $ROUTE_DEL $INTERFACE >/dev/null 2>&1 || true fi fi ;; 1) log_warning_msg "$DESC" "'$NAME'" "was already stopped" ;; 2) log_end_msg 1 ;; esac ;; reload|force-reload) log_daemon_msg "Reloading $DESC" "$NAME" do_reload log_end_msg $? ;; restart) # # If the "reload" option is implemented, move the "force-reload" # option to the "reload" entry above. If not, "force-reload" is # just the same as "restart". # log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) sleep 1 do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 exit 3 ;; esac :Make the script executable
chmod 755 /etc/init.d/mediatombNow test it.
/etc/init.d/mediatomb startCheck that it is running OK and you have a log file in '/var/log/mediatomb.log'. If everything is all good, then enable the script.
update-rc.d mediatomb defaultsAll done.
Last.fm
Update the following section in Mediatomb configuration file, adding your Last.fm account details. sudo nano /home/mediatomb/config.xml
<lastfm enabled="yes">
<username>theuser</username>
<password>thepassword</password>
</lastfm>
Restart Mediatomb.
sudo /etc/init.d/mediatomb restart
Hide PC Directory
I prefer to hide the PC Directory folder on the PS3. Adding this option only hides this directory on the PS3, not the Mediatomb Web UI.sudo nano /home/mediatomb/config.xmlAdd the following line after the opening '<server>' tag.
<pc-directory upnp-hide="yes"/>Restart Mediatomb.
sudo /etc/init.d/mediatomb restart
Mediatomb PS3 Compatibility
Now we need to enable PS3 compatibility.sudo nano /home/mediatomb/config.xmlFind the following and change it to "yes"
<protocolInfo extend="no"/><!-- For PS3 support change to "yes" -->Also find the following and uncomment it as directed to enable DivX/XviD playback on the PS3.
<!-- Uncomment the line below for PS3 divx support --> <map from="avi" to="video/divx"/>Then add the following mappings underneath.
<map from="mts" to="video/mpeg"/> <map from="ts" to="video/mpeg"/> <map from="m2ts" to="video/mpeg"/> <map from="mkv" to="video/mpeg"/> <map from="mkv" to="video/x-matroska"/> <map from="flac" to="audio/x-flac"/> <map from="mov" to="video/x-quicktime"/> <map from="vob" to="video/mpeg"/> <map from="m4v" to="video/mp4"/> <map from="iso" to="application/x-iso9660-image"/>Finally add the following in the 'mimetype-contenttype' section.
<treat mimetype="video/quicktime" as="mov"/> <treat mimetype="video/x-quicktime" as="mov"/>Restart Mediatomb.
sudo /etc/init.d/mediatomb restart
Charsets
Add the following to the import section of the config file, just after '<import hidden-files="no">'<filesystem-charset>UTF-8</filesystem-charset> <metadata-charset>UTF-8</metadata-charset> <playlist-charset>UTF-8</playlist-charset>
Audio and Video Transcoding
The PlayStation 3 supports a limited selection of audio and video formats. However, Mediatomb can transcode them on the fly and then stream them to the PS3 in a format it can play. Find the 'transcoding' section and update it as shown below. <transcoding enabled="yes">
<mimetype-profile-mappings>
<transcode mimetype="application/ogg" using="audio-generic"/>
<transcode mimetype="audio/x-flac" using="audio-generic"/>
<transcode mimetype="video/x-ms-asf" using="video-generic"/>
<transcode mimetype="video/x-matroska" using="video-generic"/>
<transcode mimetype="video/x-quicktime" using="video-generic"/>
<transcode mimetype="video/quicktime" using="video-generic"/>
</mimetype-profile-mappings>
<profiles>
<profile name="audio-generic" enabled="yes" type="external" >
<mimetype>audio/L16</mimetype>
<first-resource>yes</first-resource>
<accept-url>yes</accept-url>
<sample-frequency>44100</sample-frequency>
<audio-channels>2</audio-channels>
<hide-original-resource>yes</hide-original-resource>
<agent command="ffmpeg" arguments="-ac 2 -ar 44100 -y -i %in -f s16be %out"/>
<buffer size="1048576" chunk-size="4096" fill-size="1024"/>
</profile>
<profile name="video-generic" enabled="yes" type="external">
<avi-fourcc-list mode="ignore">
<fourcc>DX50</fourcc>
<fourcc>DM4V</fourcc>
<fourcc>M4S2</fourcc>
</avi-fourcc-list>
<mimetype>video/mpeg</mimetype>
<accept-url>yes</accept-url>
<first-resource>yes</first-resource>
<hide-original-resource>yes</hide-original-resource>
<accept-ogg-theora>yes</accept-ogg-theora>
<agent command="/usr/local/bin/mediatomb-video-generic" arguments="%in %out"/>
<buffer size="1048576" chunk-size="26214" fill-size="52428"/>
</profile>
</profiles>
</transcoding>
Now create the video transcoding script.
nano /usr/local/bin/mediatomb-video-genericAdd the following and save the file.
#!/bin/bash INPUT="$1" OUTPUT="$2" VIDEO_CODEC="mpeg2video" VIDEO_BITRATE="4096k" AUDIO_CODEC="mp2" AUDIO_BITRATE="192k" AUDIO_SAMPLERATE="48000" AUDIO_CHANNELS="2" FORMAT="dvd" exec /usr/local/bin/ffmpeg -threads 2 -i "${INPUT}" -vcodec ${VIDEO_CODEC} -b ${VIDEO_BITRATE} \ -acodec ${AUDIO_CODEC} -ab ${AUDIO_BITRATE} -ar ${AUDIO_SAMPLERATE} -ac ${AUDIO_CHANNELS} \ -f ${FORMAT} - > "${OUTPUT}" 2>/dev/nullMake it executable.
chmod 755 /usr/local/bin/mediatomb-video-genericRestart Mediatomb.
sudo /etc/init.d/mediatomb restart
Video Import
I prefer a different directory structure for my Video folder than the Mediatomb default. I like to see the hierarchy I file them in. First of all we have to change the 'config.xml' so it uses the import script.nano /home/mediatomb/config.xmlFind...
<virtual-layout type="builtin">and replace it with...
<virtual-layout type="js">Now modify 'import.js' as follows.
sudo nano /usr/local/share/mediatomb/js/import.jsFind the following...
function addVideo(obj) { var chain = new Array('Video', 'All Video'); addCdsObject(obj, createContainerChain(chain)); var last_path = getLastPath(obj.location); if (last_path) { chain = new Array('Video', 'Directories', last_path); addCdsObject(obj, createContainerChain(chain)); } }...and replace it with...
function addVideo(obj) { var chain = new Array('Videos', 'All Video'); addCdsObject(obj, createContainerChain(chain)); //create an array of the directorys of the location of the file var location = obj.location.split('/'); chain = new Array(); var dirList=new Array(); var j=0; for (i=location.length-2;i>=0;i--) { dirList[j]=location[i]; //Find the parent dir Videos and break the loop //If you have a different parent dir then you should change it here if (location[i]=='Videos') {break;} j++; } //Build the chain array by adding the parent and subdirs starting with the parent dir. for (i=j;i>=0;i--) { chain.push(dirList[i]); } addCdsObject(obj, createContainerChain(chain)); }Finally, restart Mediatomb.
sudo /etc/init.d/mediatomb restart
Photo Import
I want my photos to be categories using EXIF tags I have inserted into them.nano /home/mediatomb/config.xmlAdd an extra child to the import tag with the following do this just below the end tag of 'mappings'.
<library-options>
<libexif>
<auxdata>
<add-data tag="EXIF_TAG_MODEL"/>
<add-data tag="EXIF_TAG_PIXEL_X_DIMENSION"/>
<add-data tag="EXIF_TAG_PIXEL_Y_DIMENSION"/>
<add-data tag="EXIF_TAG_IMAGE_DESCRIPTION"/>
<add-data tag="EXIF_TAG_USER_COMMENT"/>
</auxdata>
</libexif>
</library-options>
Now update the import script.
sudo nano /usr/local/share/mediatomb/js/import.jsReplace the function addImage(obj) with the following code.
function addImage(obj)
{
var chain = new Array('Photos', 'All Photos');
addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER);
var xpixel=obj.aux['EXIF_TAG_PIXEL_X_DIMENSION'];
var ypixel=obj.aux['EXIF_TAG_PIXEL_Y_DIMENSION'];
//check if there is x and y pixel
//and if both are below 800px add them only to small photos
if ( ((!xpixel) && (!ypixel)) || ((xpixel<800) && (ypixel<800)) )
{
chain = new Array('Photos','Small photos');
addCdsObject(obj,createContainerChain(chain),UPNP_CLASS_CONTAINER);
}
else
{
//If there is a date add them to the date folder
var date = obj.meta[M_DATE];
if (date)
{
chain = new Array('Photos', 'Date', date);
addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER);
}
//camera directory with subject subdirectory
var model = obj.aux['EXIF_TAG_MODEL'];
if (model)
{
var subject=obj.aux['EXIF_TAG_IMAGE_DESCRIPTION'];
if (subject)
{
subject = firstUppperCase(subject);
chain = new Array ('Photos','Camera',model,subject);
addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER);
}
else
{
chain = new Array ('Photos', 'Camera',model,'Unknown description');
addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER);
}
}
else
{
var subject=obj.aux['EXIF_TAG_IMAGE_DESCRIPTION'];
if (subject)
{
subject = firstUppperCase(subject);
chain = new Array ('Photos','Camera','Unknown camera',subject);
addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER);
}
else
{
chain = new Array ('Photos', 'Camera','Unknown camera','Unknown description');
addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER);
}
}
//subject directory in the parent directory
var subject=obj.aux['EXIF_TAG_IMAGE_DESCRIPTION'];
if (subject)
{
subject = firstUppperCase(subject);
chain = new Array ('Photos', 'Subject', subject);
addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER);
}
else
{
chain = new Array ('Photos', 'Subject','Unknown description');
addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER);
}
//keyword directory in the parent directory to add this function I use the format
//Keyword-1;Keyword-2;Keyword-3 in the exif tag user comment I also change all letters
//to lower case and the first letter to upper of every keyword in the script
//This to avoid getting multiple dirs with Holiday 2007 and holiday 2007. This with
//the function firstUppperCase(str).
var keyword=obj.aux['EXIF_TAG_USER_COMMENT'];
if (keyword)
{
var keywordArray=new Array();
var keywordArray=obj.aux['EXIF_TAG_USER_COMMENT'].split(';');
for (i=0;i<keywordArray.length;i++)
{
keywordArray[i] = firstUppperCase(keywordArray[i])
chain = new Array ('Photos', 'Keyword', keywordArray[i]);
addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER);
}
}
else
{
chain = new Array ('Photos', 'Keyword','Unknown keyword');
addCdsObject(obj, createContainerChain(chain), UPNP_CLASS_CONTAINER);
}
}
}
// script to turn string to lower case and the first to uppercase
function firstUppperCase(str)
{
var remainChar = str.substring(1);
remainChar = remainChar.toLowerCase();
var firstChar = str.substring(0,1);
firstChar = firstChar.toUpperCase();
return firstChar+remainChar
}
Restart Mediatomb.
sudo /etc/init.d/mediatomb restart
Video Thumbnails
Providing you install the ffmpegthumbnailer as describe above, all that is required now is to enable the thumbnails. Thumbnails are generated on the fly.sudo nano /home/mediatomb/config.xmlFind the following and change it to "yes"
<ffmpegthumbnailer enabled="no">Restart Mediatomb.
sudo /etc/init.d/mediatomb restart
YouTube
You'll need to have a valid YouTube account and know which video feeds you'd like access to.sudo nano /home/mediatomb/config.xmlFind you following line and insert your YouTube account details in the 'user' and 'password' fields.
<account user="mediatomb" password="mediatomb"/>Now find the YouTube section in the online services and update as shown below, adding your YouTube username to the 'user' field for favorites, playlists and uploads.
<YouTube enabled="yes" refresh="28800" update-at-start="yes" purge-after="604800" racy-content="exclude" format="mp4" hd="no"> <favorites user="mediatomb"/> <playlists user="mediatomb"/> <uploads user="mediatomb"/> <standardfeed feed="most_viewed" time-range="today"/> <standardfeed feed="recently_featured" time-range="today"/> <standardfeed feed="top_rated" time-range="this_week"/> </YouTube>Restart Mediatomb.
sudo /etc/init.d/mediatomb restart
Apple Movie Trailers
This feature can be found in the Online Services menu and allows you to watch movies trailers hosted on an Apple website. This is very easy to configure. Find the following line and change 'enabled' and 'update-at-start' to "yes".<AppleTrailers enabled="no" refresh="43200" update-at-start="no" resolution="640"/>Restart Mediatomb.
sudo /etc/init.d/mediatomb restart
$Id: InstallingMediaTomb012,v 1.22 2009/12/18 14:32:32 martin Exp $
Wiki Index All Recent Edit Top


