PS3 Media Server And Ubuntu Foo

After I finally got my video and audio files a little bit better organized I decided that I need some kind of streaming server for all my possible devices. Blu-ray players from Sony and LG, a PS3 and some Android devices (HTC Thunderbolt and Incredible 2) want to be fed with music and movies. Seeing that eclectic collection of renderers it was immediately clear that I need some on the fly transcoding. So I looked into a couple media servers and finally decided to go with the PS3 Media Server.

Of course I wanted to run the whole thing as a service on my server. So PMS (yes, I use this as the abbreviation!) needs to run in a headless mode although it runs usually with a UI. Luckily it falls back to a headless mode when it doesn’t find a head. And on Ubuntu that means you have to switch to a real console without X! So this was easy to fix. After some more digging to find out what exactly I might need to run it on my Ubuntu “Oneiric Ocelot” (11.10) in 64 Bit I found this post on the Open Source Nirvana. So I thought “lets go for it”, but I ran into some problems. So here is my way of setting up the PS3 Media Server on a Ubuntu Oneiric 64 Bit. Some things might apply to other distributions as well, so keep reading and you might find something useful.

In general I liked Open Source Nirvana’s idea of using only repositories and only start compiling if really needed. So I stuck with that theme. I just differ in some areas from what he did. For instance I use the SUN (now Oracle) JDK and the FFmpeg from medibuntu.

And a last word before I start. This is not the final word in setting up the PS3 Media Server on a Ubuntu. It worked for me but things change and the next Ubuntu release is around the corner. I guess you can call it work in progress.  So, go ahead and use this knowledge to make your life easier.

Repositories

This is a set of commands to add the needed repositories. I assume you work as the user (not root!) and you use sudo to acquire super user rights.

MediaInfo

sudo add-apt-repository ppa:shiki/mediainfo && sudo apt-get --quiet update

Medibuntu

sudo -E wget --output-document=/etc/apt/sources.list.d/medibuntu.list \
http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && \
sudo apt-get --quiet update && \
sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring\
 && sudo apt-get --quiet update

Install Dependencies

This should also work with the SUN (now Oracle) JDK but I am currently using the OpenJDK. So the installation of all needed files should be this line:

sudo apt-get install mplayer mencoder mediainfo ffmpeg openjdk-6-jre-headless

If you later on don’t see thumbnails although the renderer (like the PS3 or my Sony Blu-ray player) supports them, then you might need to install imagemagick as well (you will see an error message in the debug or PMS log that “convert” could not be found):

sudo apt-get install imagemagick

FFmpeg

I did not use the suggested FFmpeg von Jon Severinsson because that lead to some trouble with libavformat. If you follow Open Source Nirvana’s HowTo and you get an error like this in the PMS log or debug log, then remove that repository and reinstall all FFmpeg related files from the Medibuntu repository:

mencoder: symbol ff_codec_bmp_tags, version LIBAVFORMAT_53 not defined in file
libavformat.so.53 with link time reference

This seems to be due to the different versions of FFmpeg that was used to compile mplayer/mencoder and FFmpeg itself. It seems that sometimes you will get a similar issue when you have VLC installed. So, save yourself some headaches and go with the Medibuntu version.

PS3 Media Server

Now we can finally get to the server itself. Download the latest Linux version (at the time of the post it was 1.50.1) from here using your preferred download tool. I personally like to have that kind of software to be installed into /opt so I simply extract it into /opt.

wget \
http://ps3mediaserver.googlecode.com/files/pms-generic-linux-unix-1.50.1.tgz
sudo tar zxvf pms-generic-linux-unix-1.50.1.tgz -C /opt/
sudo ln -s /opt/pms-linux-1.50.1/ /opt/pms/

Init Script

A possible start script can be found in this forum thread (at the time of this post version 3.0 was the most recent version). Just check the thread for the latest version or download the version that I use here.

Unzip the file and copy or move the start script to /etc/init.d as a root. Update the file with the unprivileged user and group information that you want to use for your PMS. The group and user name will be put into the PMS_USER and PMS_GROUP variables of the script.

Then you might need to make the script executable with:

sudo chmod +x /etc/init.d/PS3MediaServer

I guess you also want to install the server as a service. The following will add it to the start/stop sequence:

sudo update-rc.d PS3MediaServer defaults 90

Configuration

Now we get to the part that is the most tricky for most people. First of all you need to know that the server is running with lesser privileges than other services. That means that some files are not writable or even readable. This is especially true for the log and program directory itself.

Rights

Considering the user and group configuration in the start/stop script and the configuration itself you have to set the ownership of the installation directory and the log directory. Here is a sample for user <user> and group <group>:

sudo chown -R <user>.<group> /opt/pms*
sudo mkdir /var/log/pms
sudo chown -R <user>.<group> /var/log/pms

Configuration File PMS.conf

Now everything should be set up to create the base configuration for PMS which is defined in /opt/pms/PMS.conf. Well, the file is not created yet and the easiest way to create it is to start the server because we need to have a unique ID (UUID) set correctly. If all rights are set correctly the following command should start the server (including UI) and create the configuration file.

/opt/pms/PMS.sh

You can stop that process with CTRL-C without any problems. If that doesn’t create the file you can simply start and stop the newly created service:

/etc/init.d/PS3MediaServer start
/etc/init.d/PS3MediaServer stop

Just an FYI but if you start the server this way on a Ubuntu, being logged in as the main user and using su to become root, then you might see the PMS UI front end although you start the service. This is due to Ubuntu’s setup with the X forwarding.  It is actually nice for debugging or finding settings for the configuration, but a pain the butt if you really want to run headless. You just have to keep in mind to go to a real text console (ALT-F1 anybody?!) to start the server. Or simply try a reboot and see what sticks.

The created file should at least have the UUID line in it. The following additional settings should get you started:

thumbnails = true
thumbnail_seek_pos = 300
mencoder_ass = true
folders = \/mnt\/MyMusic,\/mnt\/MyVideos
hide_videosettings = true
hide_enginenames = true
audiochannels = 2

I guess it is obvious that you want to change the music and videos folders to you local set up. The most important thing here is to not leave a space between the folder names, because PMS will simply generate an error.

You can, after reading the documentation, of course play around with other parts of the configuration like the WEB.conf. How about setting up your favorite podcasts, radio or video streams?

OpenVPN / Network Adapter

If you run an OpenVPN (like me) you might run into a completely different situation. For whatever reason PMS thought that the OpenVPN IP adress is the best adress to be used. So I had to force PMS to use my local ethernet adapter. You can do this by simply adding a line to PMS.conf and restarting the service:

network_interface = eth0

Missing Library Links

In my case some libraries where installed but PMS was searching for the library using a name without the version number. You can of course start recompiling PMS but that goes too far. In my case libzen and libmediainfo gave me a hard time. But the following soft links and a PMS restart helped me a lot:

sudo ln -s /usr/lib/libzen.so.0 /usr/lib/libzen.so
sudo ln -s /usr/lib/libmediainfo.so.0 /usr/lib/libmediainfo.so

Debugging

If you have any problems with the server the log output in the debug log (/opt/pms/debug.log) and the log files themselves (/var/log/pms/*)  give ample information. That’s how I found out that some library links were not set correctly or that I had to install imagemagick. So don’t be afraid to read the log!