Monday, July 7, 2008

Ubuntu, Mediatomb, VLC and the PS3 - a match made in heaven.

Today, in the space of a couple of hours, I successfully setup media serving to my PS3 under Ubuntu 8.04. Not only that, but the media server works with:
  • Multiple video and audio codecs and
  • Media scanning (tracking forwards and backwards).
The following discusses how I accomplished this feat.

Introduction:

Firstly it should be noted that the PS3 is a DLNA (Digital Living Network Alliance) compatible device, this basically means you can share media to it. Currently under Ubuntu there is a limited number of DLNA compatible media server programs, these programs include
mediatomb and fuppes. I chose mediatomb as it has an installer through the symantic package manager, and for that reason updates should be automated.


Installation:

First, make sure you have
VLC installed, if you don't you can install it using the following command: sudo apt-get install vlc

Also install
ffmpeg for good measure: sudo apt-get install ffmpeg

I performed the installation of
mediatomb via the Add/Remove programs (symantic package manager) application in Ubuntu.
Simply search for
mediatomb in the "All available programs" category and select install. Having completed the previous install step, mediatomb is now successfully installed and is avaliable under "Application/Sound & Video", that said, don't open it yet!


Configuration:

Now we need to setup
mediatomb, to do this we first need to run and close mediatomb, this will cause mediatomb to do some basic setup. To run mediatomb, go to a terminal and type: sudo mediatomb
After you do this wait for some text to output, the text should look something like:


MediaTomb UPnP Server version 0.11.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

2008-07-08 22:47:45 INFO: Loading configuration from: /home/user/.mediatomb/config.xml
2008-07-08 22:47:45 INFO: Checking configuration...
2008-07-08 22:47:45 INFO: Setting filesystem import charset to UTF-8
2008-07-08 22:47:45 INFO: Setting metadata import charset to UTF-8
2008-07-08 22:47:45 INFO: Setting playlist charset to UTF-8
2008-07-08 22:47:45 INFO: Configuration check succeeded.
2008-07-08 22:47:45 INFO: Initialized port: 49152


Once the text is outputted close the program, CTRL+C.

Now edit the
mediatomb configuration file, to do this simply edit the config.xml file for mediatomb using your text editor: gedit ~/.mediatomb/config.xml

Note that the file has some comments which instruct you where to change things for PS3 support.

Line 23: Change the no to a yes, protocolInfo extend = yes
Before:
<protocolInfo extend="no"/><!-- For PS3 support change to "yes" -->
After:
<protocolInfo extend="yes"/><!-- For PS3 support change to "yes" -->

Line 65: Uncomment, map from="avi" to="video/divx"
Before:
<!-- <map from="avi" to="video/divx"/> -->
After:
<map from="avi" to="video/divx"/>

The above gives you the basic mediatomb PS3 support, this basic support will not transcode your files. This means that if a media file isn't encoded using one of the "few" supported codecs then tough luck.

To enhance the PS3 support enable transcoding, as VLC is installed, enable transcoding via VLC.

Line 87: Change the no to a yes, transcoding enabled="yes"
Before:
<transcoding enabled="no">
After:
<transcoding enabled="yes">

Line 103: Change the enabled from no to yes, profile name="vlcmpeg" enabled="yes" type="external"
Before:
<profile name="vlcmpeg" enabled="no" type="external">
After:
<profile name="vlcmpeg" enabled="yes" type="external">

Having completed the above steps, save the file.

All that remains is to re-run the mediatomb via the terminal and add media to share. Simply run mediatomb in a terminal:mediatomb. Now go to the URL stated in the mediatomb output, this is likely to be http://localhost:49152. Once at the URL you should see the mediatomb interface, to add media simply select the media you want to share from the Filesystem and press the + symbol in the top right. All shared media is shown in the Database.


Finish:

Now startup your PS3 and search for media servers, your PS3 should find the mediatomb server with your shared media, virtually all the media should be watchable via the VLC transcoding.. Enjoy!


config.xml before and after:

Before:
<?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:77026039-2855-4f76-bb54-4f7b176d4cb8</udn>
<home>/home/robertpyke/.mediatomb</home>
<webroot>/usr/share/mediatomb/web</webroot>
<storage>
<sqlite3 enabled="yes">
<database-file>mediatomb.db</database-file>
</sqlite3>
<mysql enabled="no">
<host>localhost</host>
<username>mediatomb</username>
<database>mediatomb</database>
</mysql>
</storage>
<protocolInfo extend="no"/><!-- 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="audio/L16" as="pcm"/>
<treat mimetype="video/x-msvideo" as="avi"/>
</mimetype-contenttype>
</mappings>
</import>
<transcoding enabled="no">
<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"/>
</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="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:

<?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:77026039-2855-4f76-bb54-4f7b176d4cb8</udn>
<home>/home/robertpyke/.mediatomb</home>
<webroot>/usr/share/mediatomb/web</webroot>
<storage>
<sqlite3 enabled="yes">
<database-file>mediatomb.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="audio/L16" as="pcm"/>
<treat mimetype="video/x-msvideo" 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"/>
</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="vlcmpeg" 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="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>


The associated before and after config.xml files are available at robertpyke.com

11 comments:

simon said...

as i have seen your tv i can say without fear of contradiction that this is super awesome. ps, first post! pps, can you get a nice media centre style remote for ps3?

Robert Pyke said...

Yes, you can get a nice media centre style remote for the PS3, their $50 AU RRP (It's Bluetooth).

CNET reviewed it:
http://www.cnet.com.au/games/hardware/0,239029706,339274423,00.htm

Demon said...

Regular expression is really wonderful to parsing HTML or matching pattern. I use this a lot when i code. Actually when I learn any new langauge, first of all I first try whether it supports regex or not. I feel ezee when I found that.

http://icfun.blogspot.com/2008/04/ruby-regular-expression-handling.html

Here is about ruby regex. This was posted by me when I first learn ruby regex. So it will be helpfull for New coders.

Unknown said...

This is great, I've read a lot of tutorials about Mediatomb and this is the only one that worked, far better than any other and Mediatomb is way less resource hungry that PS3MediaServer.

I'll write up about it on my blog, if that's ok with you?

Robert Pyke said...

@rupertp

Thank you for the positive feedback, and thanks for linking to me from your website :)

Unknown said...

I have been trying to watch mp4 with an h264 encoded video. But it is really jerky. I know this has something to do with vlc in Jaunty wondering if there was a way to change the transcoding to mplayer or any other player.

Robert Pyke said...

Hi Curtis,

whilst I have not tested this, I would recommend trying the following:

In your xml, create a profile (similar to the vlcmpeg profile - the start of which is seen below)
<profile name="vlcmpeg" enabled="yes" type="external">....

Use the vlcmpeg profile as a template.

You will need to specify the command, arguments, etc. as well as remap the mimetype-profile-mappings as necessary.

The command is specified as follows:
In your profile, simply specify the <agent command=... as mplayer (or whatever the command is).

As I mentioned at the top, I have not tried this, but this is how I would go about trying to get it to work.

I will give this a go at some stage in the not too distant future (next few days) and report how I went.

Robert Pyke said...

I'm afraid that next few days will probably turn into some time in the future (not sure when). I've got way too much university work at the moment to do anything fun...

When I get the chance, I will try out what I suggested and get back to you.

Unknown said...

YOU ROCK! I had my PS3 connected in less than ten minutes after installing Ubuntu. Fantastic post, and keep up the great work!

Anonymous said...

Thank you so much! I recently switched from windows to linux (circa 5 days ago), didn't know what the hell ubuntu was prior to that. I found your post about mediatomb/ps3/vlc and I am up and running; worked like a charm.

Your awesome!

Unknown said...

Im super new to linux but is there anyway to mirror subtitle files that are streamed to mediatomb ps3 onto a dialogue box on the pc screen? please email with answer, thank you <3