Build a transcoding UPnP media server

Turn your Linux-based NAS into a fully-fledged media hub

Build a transcoding UPnP media server

UPnP Media Server 1.0 is a protocol that removes the effort from getting a media-streaming device to access and play your content.

If your NAS box stores movies, music and photos, a UPnP server running on this NAS will enable a PlayStation 3 or any other UPnP compatible player to access any player-supported formats from your storage box without any further configuration.

JPG images, DIVX movies and MP3 audio will all appear according to sorting options and arrangements, and will all play automatically. Which formats will work and which won't depends on the capabilities of your player device. A PlayStation won't play MKV movie files or Ogg Vorbis music files, for instance, but a good UPnP server should also be able to convert one format to another in real time.

This is known as transcoding, and it enables a player to receive transcoded formats as devices access them. One of the best UPnP servers you can install and configure is MediaTomb. The latest major update, from early 2010, was a year late, but added dozens of new features.

It transcodes, checks for new files automatically, streams YouTube, supports thumbnails and animated previews of movies, and accommodates even the most awkward of media players. Its configuration file can be used to accommodate almost any format and client eventuality.

But the best thing about MediaTomb is that it's free. You can run it from either a Linux-based Arm or x86 NAS, from your own Linux machine or modest server, or even from a spare Apple OS X machine. You just need to know where to start.

1. Installation

Getting MediaTomb installed isn't difficult. Most distros carry the package, and you can install it using nothing more than your distribution's package manager. Ubuntu 10.10, for example, currently comes with the latest version of MediaTomb – version 0.12.1 – which is a security update to the major 0.12 release.

You can install it by launching the Synaptic package manager, searching for 'MediaTomb', and clicking 'Apply'. This will also grab a few other dependencies, including the daemon and common packages that are listed alongside in Synaptic when you search for MediaTomb.

Install mediatomb from the synaptic package

INSTALLING MEDIATOMB: You can install MediaTomb from the Synaptic package manager, along with a few other dependencies. Search for 'mediatomb', then click 'Apply'.

If you're using Ubuntu Server and don't have access to a GUI, typing sudo apt-get install mediatomb should perform the same trick.

MediaTomb is a combination of four elements. First is the daemon. This needs to be configured to run silently in the background and wait for requests from media players. Second is the main MediaTomb server process, which handles the request and spits out the functionality. Then there's an epic configuration file that informs the rest of MediaTomb what needs to be done for each device, such as converting Ogg Vorbis files to WAV files for the PS3. Finally, there's content itself.

You can place your movies, music and photos anywhere, and use MediaTomb's web interface to add them to its database, or configure the server to check for additions to a specific directory automatically. But before we get to that stage, we need to delve into the config file.

2. Configure MediaTomb

With a default Ubuntu installation, you can find the configuration file at '/etc/ mediatomb/config.xml' on your filesystem. On a NAS box, 'etc' can usually be found within '/opt'. You need to open the configuration file into a text editor, but you also need system admin rights to be able to save your changes. Typing sudo gedit on the command line is one solution.

When opened, you'll notice that the configuration file uses XML to encapsulate the various parameters, and these are then further split into sections that are indicated by their tabbed position within the file. This isn't necessary for the configuration file to work, but it makes it easier to see which parameters are attached to which elements.

The default configuration file will work for many general devices, and you might want to try MediaTomb at this stage to see how far you can get. However, even a small amount of tinkering can tailor the file to better support your setup and media formats.

Configuring mediatomb to support the ps3

PS3 SUPPORT: If you have a PlayStation 3, you can enable support within MediaTomb by making a few simple changes to the default configuration file.

By default it doesn't include support for the PlayStation 3, or the ability to create thumbnail previews for films. Both options can be enabled by editing a single parameter, or by removing the comments from the beginning of the appropriate lines within the configuration file.

To enable support for the PlayStation 3, look for the line that includes '<protocolInfo extend="no"/>'. It will be followed by a comment, highlighted blue in Gedit. All you need to do is swap the word 'no' for 'yes'. After the file has been saved and the server restarted, you'll have PlayStation 3 support.

Further down the file, if you want to enable support for DivX streaming to the PlayStation 3, look for the line '<map from= "avi" to="video/divx"/>'. This is commented out, meaning that it's encapsulated by '<!--' and '-->' elements. Copy the line from the comments and paste it onto a new one directly above the commented area. Your PlayStation 3 will now be able to play DivX movies.

3. Enable transcoding

MediaTomb's strongest feature is its ability to convert a file from one format to another while it's playing, but before this can work, it needs to know more about your system and which tools you intend to use for the process.

You might want to convert your Ogg Vorbis music files into raw PCM format so they'll work on players with no native support for Ogg Vorbis. The tool you need in this instance is ogg123 – a command line utility that takes an Ogg Vorbis file as an input and spits out PCM when used with the correct arguments.

You can find that exact example hidden within the MediaTomb configuration file, but before you reconfigure the command, you first need to enable transcoding. Transcoding is disabled by default, because each conversion process requires a specific tool. Without those tools installed, the transcoding will fail.

You need the 'ogg123' command for Ogg Vorbis conversion. You can install this by grabbing the 'vorbis-tools' package with Synaptic, and you can see which other command line tools are needed by skimming through the configuration file. After you've installed this, change 'no' to 'yes' on the '<transcoding enabled="no">' line.

Enabling transcoding in mediatomb

ENABLE TRANSCODING: Transcoding is disabled by default because each file format requires a specific conversion tool, without which the transcoding will fail. The configuration file will tell you which tools you need to convert which formats.

Following this, you'll see the transcode mapping section. This is where MediaTomb takes the requested mimetype for a format, and turns it into a profile within the config file. It's within this profile that the conversion takes place. For Ogg Vorbis conversion, find the profile named 'oggflac2raw' and change the enabled field to read 'yes'.

Below this, you'll find the lines that deal with the execution of the 'ogg123' command. If you run into problems with the transcoding, this is the first place to look.

The last option that needs to be changed involves enabling the web-based user-interface, which for some reason is disabled by the Ubuntu package. Search for '<ui enabled="no" show-tooltips= "yes">' and change the 'no' to 'yes' before a final save of the file.

4. Running MediaTomb

With the configuration file saved, MediaTomb needs to be restarted from the command line. Just type 'sudo/etc/init.d/ mediatomb restart' to get it going. You should now be able to access the web interface we've just enabled in the configuration file.

This can be accessed by opening a browser on the same machine MediaTomb is running on, and typing http://localhost:49152 into the location bar. You can change the port number within the configuration file if you feel '49152' is too random, or if some other service is already using the same port. By default, MediaTomb increases the port number by one until it finds one that's free.

To access MediaTomb from another machine on the same LAN, substitute 'localhost' for the IP address of the MediaTomb server. The browser UI is used to add content to the MediaTomb database, and after this content has been added, your various UPnP clients will be able to access that media, whether it's photos, music files or movies.

To get started, click the 'Filesystem' link in the panel on the right. You will now see all the files and folders within the top directory of your system's main drive. Use this to navigate to your media collection.

When you find a folder containing the files you want to stream, you can either add the directory to the database using the '+' symbol adjacent to your current location, or add file and folders individually using the '+' symbols to the right of their names. Alternatively, use the '+' symbol over a reload arrow to configure MediaTomb to watch for new contents in the folder, automatically adding any new and compatible files to the database.

5. Using MediaTomb

The final step is to find a UPnP client to test the setup. In your living room, this might be a PS3 or standard media streamer, and you should see the MediaTomb server as part of the UPnP browser without further configuration.

On a PS3, for example, the 'Video', 'Photo' and 'Movie' sections will contain a link to that kind of media on your MediaTomb server. You'll also find the same functionality behind your favourite UPnP client.

From a Linux box, the easiest way to test your UPnP library is to use VLC, the Video LAN Client media player. It's supported UPnP connections for the last few years, and because it's capable of playing most music and video formats, it's the perfect way to access your media collection. It's only a search and apply away within Synaptic.

Using mediatomb

MEDIATOMB UI: Use the plus symbols to add files and folders to your database. You can also configure MediaTomb to watch for new content in a particular folder.

To enable support for UPnP, open VNC's 'Preferences' window and click 'All' on the 'Show Settings' switch in the bottom left of the window. This will show all the possible options rather than just a select few, and you should see that the 'Service Discovery' option appears under 'Playlist' in the panel on the left.

Select this, and in the services listed in the main window, enable 'Universal Plug'n'Play'. Click on 'Save', then 'Playlist' from the 'View' menu. This will show a media browser panel on the left. You should be able to see the contents of your UPnP server by clicking 'Local Network | Universal Plug'n'Play'.

MediaTomb should appear as a source, and you'll then be ready to test your media content.


First published in PC Plus Issue 303

Liked this? Then check out How to build the ultimate home media network

Sign up for TechRadar's free Weird Week in Tech newsletter
Get the oddest tech stories of the week, plus the most popular news and reviews delivered straight to your inbox. Sign up at

Follow TechRadar on Twitter * Find us on Facebook

Article continues below