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.

    http://www.eurotech-inc.com/single-board-computer-ebx-x86-apollo.asp

    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. http://mediatomb.cc/

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="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>
<ui enabled="yes">
<accounts enabled="no" session-timeout="30">
<account user="mediatomb" password="mediatomb"/>
</accounts>
</ui>
<name>MediaTomb</name>
<udn>uuid:b82de045-5c37-44c9-a2bc-95a0af554667</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"/><!-- 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
-->
<!--
<custom-http-headers>
<add header="X-User-Agent: redsonic"/>
</custom-http-headers>

<manufacturerURL>redsonic.com</manufacturerURL>
<modelNumber>105</modelNumber>
-->
<!-- Uncomment the line below if you have a Telegent TG100 -->
<!--
<upnp-string-limit>101</upnp-string-limit>
-->
</server>
<import hidden-files="no">
<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="builtin">
<import-script>/usr/share/mediatomb/js/import.js</import-script>
</virtual-layout>
</scripting>
<mappings>
<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"/> -->
</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="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"/>
</mimetype-contenttype>
</mappings>
</import>
<transcoding enabled="yes">
<mimetype-profile-mappings>
<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"/>
</mimetype-profile-mappings>
<profiles>
<profile name="oggflac2raw" enabled="no" type="external">
<mimetype>audio/L16</mimetype>
<accept-url>no</accept-url>
<first-resource>yes</first-resource>
<accept-ogg-theora>no</accept-ogg-theora>
<agent command="ogg123" arguments="-d raw -f %out %in"/>
<buffer size="1048576" chunk-size="131072" fill-size="262144"/>
</profile>
<profile name="mencoder" enabled="yes" type="external">
<mimetype>video/divx</mimetype>
<accept-url>no</accept-url>
<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>
<profile name="vlcmpeg" enabled="no" 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="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"/>
</profile>
</profiles>
</transcoding>
</config>


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

http://linuxowns.wordpress.com/2008/06/05/accessing-upnp-server-from-ubuntu/

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.


cheers.