How to build a linux media server to stream local files and spotify using dlna

If you own a Chromecast, be sure to check this!


Lately I have been trying different alternatives to build a media server. My main needs are:

  • DLNA compatible (plenty of options)
  • To be able to transcode in realtime to add subtitles (only 2 o 3 can do this in linux)
  • To be able to stream a live music URL as a online channel (only 2 o 3 can do this in linux)
  • To be able to stream to PS3 (I found only 1 that can do this)
  • To be able to remote control spotify so I can pick songs using my cell phone

Right now, spotify do not support streaming using DLNA, do not have a PS3 app and do not support chromecast; so I haven’t found any better way to send spotify to my living room but to use a live stream through DLNA. It is not the best solutions as it adds delay in the transmission and you are forced to use a third party app to control it remotely. Also if spotify API o client change, it is probably that this remote control app won’t work until it is updated.

To fulfill this requirements I used:

  • A virtual machine (Virtual box, vmware or hyper-v, its the same)
  • Ubuntu server + LXDE (low resources alternative)
  • Samba mapping of my media library
  • fake or dummy sound card to avoid spotify music in the server and to avoid install a sound card in the VM
  • lame + ezstream to capture sound and encode it in MP3
  • icescast to publish the spotify stream in the web (as an online radio)
  • Ps3 Media Server as DLNA server (which streams local library and remote url to PS without problems, also transcode videos to add subtitles)
  • Spotcommander as a remote control for spotify

Here we go…

Install base software

  1. Create a new VM with: 2-4 processors (needed for transcoding), 1GB of ram and 20 GB of disk
  2. Install ubuntu server
  3. sudo apt-get update
  4. sudo apt-get upgrade
  5. sudo apt-get dist-upgrade
  6. sudo apt-get install htop openssh-server lxde xinit chromium-browser
  7. run “startx” and check lxde is shown, from now on we will have an X environment to go on the configuration

Install fake/dummy sound card

  1. sudo modprobe snd_dummy
  2. sudo apt-get install alsa-base pulseaudio
  3. sudo alsa force-reload
  4. sudo modprobe snd_dummy
  5. sudo alsa force-reload
  6. reboot: sudo shutdown -r now

Install Spotify

  1.  Detailed info: spotify for linux

Install Media Server

  1. Install oracle java in ubuntu
  2. sudo apt-get install lame mencoder ffmpeg mplayer vlc flac mediainfo dcrawInstall PS3 Media Server. PS3 Media Server depends on certain versions of encoding tools to work, so if you install it as is, won’t transcode as can not interop with mencoder and ffmpeg included in ubuntu distribution. Good info can be found here, but anyway to fix this I did:
    1. First install using this ppa:
    2. Check ~/.config/PMS/PMS.conf and copy to a safe place all the tools it uses. (check for the keys that ends in “_path”)
    3. Uninstall package
    4. Download tar distribution, uncompress and put it in a common location (I used /opt/pms)
    5. Copy all the tools previously backed up in /opt/pms/tools
    6. Edit ~/.config/PMS/PMS.conf and change all paths so they point to tools/{prog_name} (example: mencoder_path = tools/mencoder)
    7. Create a link in /usr/local/bin to (ln -s /opt/pms/ /usr/local/bin/psmediaserver)
    8. Add ps3 media serve plugin for live streaming
    9. Download pmsencoder
    10. Put in in ps3 media server plugins folder (/opt/pms/plugins)
  3. Mounts for windows shares
    1. sudo apt-get install cifs-utils
    2. Edit /etc/fstab to automount windows share with media content. Detailed instructions can be found here

Install Broadcast App

  1. sudo apt-get install icecast2
  2. sudo apt-get install ezstream

Install Spotcommander

  1. Follow this simple guide

Sound Capture Script

  1. Create an script that captures sound card output, encode it to MP3 and add it as source to icecast2
  2. Here is the code:
    1. parec -d auto_null.monitor | lame -r -V2 --tt "spotify" --quiet - - | ezstream -c ezstream.xml
      1. where ezstream.xml is this:
        <svrinfodescription>Spotify real time streaming</svrinfodescription>
  3. Put the script in /opt/ and created a link in /usr/local/bin

Media Server Setup

  1. Start psmediaserver
  2. Add local libraries from mount points
  3. Configure transcoding settings so it add subtitles (won’t include detailed information about ps3 media server configuration)
  4. Close it
  5. Open ~/.config/PMS/WEB.conf
  6. Add the following line to stream spotify
    1. audiostream.Internet=Spotify,http://{this_machine_ip}:8000/sp.mp3,


  1. Testing
  2. Start spotify-client
  3. Run capture script
  4. Access http://{this_machine_ip}/spotcommander
  5. You should see a mini-spotify client, pick a song and play it
  6. Access http://{this_machine_ip}:8000
  7. You should see a mp3 player that plays the selected song
  8. Start ps3 media server
  9. Check that you can access local media and live stream from remote locations using DLNA


Once you have all working, I recommend setting up autologins and startups (so the server can work unattended)

  1. Autologin in LXDE
    1. sudo nano /etc/lxdm/default.conf
    2. uncomment line that says “autologin” and put your user there
  2. Autostartup for capture script, spotify, psmediaserver and spotcommander
    1. .desktop files for each app should be put here /etc/xdg/autostart/
    2. Just copy one that exists and replace values inside

Final Note

  • I have installed all custom software and scripts to /opt/ and link them from /usr/local/bin, but you can pick any location you want.
  • I probably missed some step in the process but I am sure this will get you moving
  • icecast2 have buffers that add a delay of about 20-30 secs in the stream. So when you change a song won’t be fast. You can play with this buffers in /etc/icecast configuration (low buffer => less delay but can lead to choppy playback or even disconnections)
  • PS3 Media server is memory hungry (and have some leaks too), so is not a bad idea to restart it each X time. You can make a cron for it.

3 comentarios en “How to build a linux media server to stream local files and spotify using dlna


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s