Saturday, February 28, 2009

Mediatomb with mencoder as home media server

Over the past few years I have managed to gather a good music and movie collection on my external USB drives. I have been using a 60 gig drive laptop since last 2 years and coudlnt afford storing my collection on my drive. This is a home media server I built after getting fed up of moving around my USB drives around whole house to access songs and movies from my laptop and my PS3. The hardware :
  • Intel Pentium M based single board computer (1 Gig RAM) running ubuntu.Its an old board used during one of my work projects.

    The board is enclosed in an industrial box and contains tons of I/O (yeah ,device programmers love this language :) The green strip on front panel is bunch of digital I/o's. And my tv serves as the monitor

My Tv serves as a decent 42" monitor
  • Two 200 gig Pata drives connected via USB convertor (NTFS formatted)

  • PS3

  • My tv as monitor

The software :

  • Operating system : Ubuntu 8.04 but should work for other versions of ubuntu

  • MediaTomb is an open source (GPL) UPnP MediaServer which allows you to stream your digital media through your home network and listen to/watch it on a variety of UPnP compatible devices like PS3 and some of latest DLNA compatible HDTV's.

The Installation

mediatomb is a Upnp server using VLC to transcode avi and other format files to be played on PS3 and other Upnp based devices. The first thing I was required to do was download Java. You can use apt-get command to download java the following way : apt-get install sun-java6-jre

Once Java is installed the next step is to install mediatomb. Mediatomb is included in Ubuntu 8.04 as third party package. To install mediatomb on updated ubuntu 8.04 go to :Applications>add/remove and select show all packages. Type mediatomb in search box and you should be able to queue up mediatomb for installation.

Configuring mediatomb to use mencoder

The steps so far were relatively easy and here comes the tricky part. Getting mediatomb to use mencoder. I prefer mencoder because it has quite a rugged transcoding engine and is able to transfer almost any file throwned at it.

Mediatomb is configured using a config.xml file located in /etc/mediatomb/config.xml . I wont go in details on how to add ps3 support for mediatomb cause googling mediatomb ps3 should give you plenty of links. However I had difficulty finding right modifications for config.xml file to use mencoder . So gathering inputs around net I was able to modify the config.xml file to use mencoder for playing avi files . This is how my config.xml looks like. Please note the changes I made to the original config.xml file in blue font.

Note the ps3 support added and also the mencoder mimetype script I added that mediatomb calls to transcode the video's from the PC to a format the PS3 can understand using mencoder. I would suggest picking up the highlighted scrip part amd making modification in your script rather than copying and pasting the whole script.

<?xml version="1.0" encoding="UTF-8"?>
<config version="1" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<ui enabled="yes">
<accounts enabled="no" session-timeout="30">
<account user="mediatomb" password="mediatomb"/>
<sqlite3 enabled="yes">
<mysql enabled="no">
<protocolInfo extend="yes"/><!-- For PS3 support change to "yes" -->
Uncomment the lines below to get rid of jerky avi playback on the
DSM320 or to enable subtitles support on the DSM units
<add header="X-User-Agent: redsonic"/>

<!-- Uncomment the line below if you have a Telegent TG100 -->
<import hidden-files="no">
<scripting script-charset="UTF-8">
<virtual-layout type="builtin">
<extension-mimetype ignore-unknown="no">
<map from="mp3" to="audio/mpeg"/>
<map from="ogg" to="application/ogg"/>
<map from="asf" to="video/x-ms-asf"/>
<map from="asx" to="video/x-ms-asf"/>
<map from="wma" to="audio/x-ms-wma"/>
<map from="wax" to="audio/x-ms-wax"/>
<map from="wmv" to="video/x-ms-wmv"/>
<map from="wvx" to="video/x-ms-wvx"/>
<map from="wm" to="video/x-ms-wm"/>
<map from="wmx" to="video/x-ms-wmx"/>
<map from="m3u" to="audio/x-mpegurl"/>
<map from="pls" to="audio/x-scpls"/>
<map from="flv" to="video/x-flv"/>
<!-- Uncomment the line below for PS3 divx support -->
<map from="avi" to="video/divx"/>
<!-- Uncomment the line below for D-Link DSM / ZyXEL DMA-1000 -->
<!-- <map from="avi" to="video/avi"/> -->
<map from="audio/*" to="object.item.audioItem.musicTrack"/>
<map from="video/*" to="object.item.videoItem"/>
<map from="image/*" to="object.item.imageItem"/>
<treat mimetype="audio/mpeg" as="mp3"/>
<treat mimetype="application/ogg" as="ogg"/>
<treat mimetype="audio/x-flac" as="flac"/>
<treat mimetype="image/jpeg" as="jpg"/>
<treat mimetype="audio/x-mpegurl" as="playlist"/>
<treat mimetype="audio/x-scpls" as="playlist"/>
<treat mimetype="audio/x-wav" as="pcm"/>
<treat mimetype="video/x-msvideo" as="avi"/>
<treat mimetype="video/divx" as="avi"/>
<transcoding enabled="yes">
<transcode mimetype="video/x-flv" using="vlcmpeg"/>
<transcode mimetype="application/ogg" using="vlcmpeg"/>
<transcode mimetype="application/ogg" using="oggflac2raw"/>
<transcode mimetype="audio/x-flac" using="oggflac2raw"/>
<transcode mimetype="video/divx" using="mencoder"/>
<profile name="oggflac2raw" enabled="no" type="external">
<agent command="ogg123" arguments="-d raw -f %out %in"/>
<buffer size="1048576" chunk-size="131072" fill-size="262144"/>
<profile name="mencoder" enabled="yes" type="external">
<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
-mpegopts muxrate=12000 -vf harddup -o %out"/>

<profile name="vlcmpeg" enabled="no" type="external">
<agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit"/>
<buffer size="14400000" chunk-size="512000" fill-size="120000"/>

After this config I was able to have mediatomb up and running and using mencoder to stream video files onto my PS3 . Right now my linux media box using mediatomb serves up movies and music on my ps3 and laptop over my home network. Other possible addidtions could be PSP or Nokia tablet detecting this media server and being able to play off it. In that case I guess PSP can detect remote upnp server and just play off medai through it and nokia tablet should be able to play media by installing a Upnp client. These last two applications really excite me and actually wont require any sort of modifictaions to config.xml files. Right now I neither have a nokia tablet nor PSP so I am not able to try them out.

Right now my laptop plays off media from the server following steps from given link

Next thing on my mind is to use the linux box for some other application while its serving media over my home network at same time (remember the comment I made earlier about the linux box having tonns of IO's). Possible additions include a home automation application, for example monitoring and manipulation power consumption using the front panel IO's (green strip) , home security surveilance application like zoneminder and a mythtv application.



  1. was goin this same way....mera config file looks a bit diff tho 4 now....need some time to do this of now m just streaming stuff of mediatomb.....

    n avoid using the inbuilt package manager/apt in ubuntu....try using adept...
    adept is very very updated...n also gives you the details/versions/etc etc. about the rpm before you go n install it....
    just be careful using adept cos unknowingly you may end up uninstalling something rather critical...(I know as initially I had serious kernel issues.)...

    I just got off watching 'tropic thunder' off mediatomb right now....:)...kickass

  2. Congratulations Dhake!!
    Now this is revolutionary work !!!! People will never forget your contribution to the Science!! you have literally changed the world today!!!
    I think you have achieved what every mankind on the earth dreams of, now what are your future plans?