A streaming pile of Pi

Continued from here.

First page here.

11. Setting up your uPNP media server

A uPNP media server allows you to stream videos from your Pi to any device that can talk to it.  A lot of tellies do this these days, along with PS3s, XBoxs, iPads, tablets and your PC.  With a server on your Pi, you can watch what you have downloaded on any compatible device in your house without the hassle of moving files or memory sticks about.  Let’s rock.

You could try doing an apt-cache search for “upnp server” if you want the practice in finding suitable packages, or I could tell you that the one you want is Mediatomb.  So sudo apt-get install mediatomb

naich@raspberrypi ~ $ sudo apt-get install mediatomb
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following package was automatically installed and is no longer required:
 mtools
Use 'apt-get autoremove' to remove it.
The following extra packages will be installed:
 javascript-common libavcodec53 libavformat53 libavutil51 libdirac-encoder0
 libexif12 libffmpegthumbnailer4 libgsm1 libjs-prototype libmozjs185-1.0
 libmp3lame0 libmysqlclient16 libnspr4 libnspr4-0d libschroedinger-1.0-0
 libspeex1 libswscale2 libtag1-vanilla libtag1c2a libtheora0 libva1 libvpx1
 libx264-123 libxvidcore4 mediatomb-common mediatomb-daemon mysql-common
 wwwconfig-common
Suggested packages:
 apache2 httpd speex mysql-client postgresql-client
The following NEW packages will be installed:
 javascript-common libavcodec53 libavformat53 libavutil51 libdirac-encoder0
 libexif12 libffmpegthumbnailer4 libgsm1 libjs-prototype libmozjs185-1.0
 libmp3lame0 libmysqlclient16 libnspr4 libnspr4-0d libschroedinger-1.0-0
 libspeex1 libswscale2 libtag1-vanilla libtag1c2a libtheora0 libva1 libvpx1
 libx264-123 libxvidcore4 mediatomb mediatomb-common mediatomb-daemon
 mysql-common wwwconfig-common
0 upgraded, 29 newly installed, 0 to remove and 0 not upgraded.
Need to get 11.4 MB of archives.
After this operation, 25.2 MB of additional disk space will be used.
Do you want to continue [Y/n]?

It’s the same as when you installed Transmission.  Apt tells you what it is going to install and you say Yes.  It nips off, installs everything and sets it up.  It doesn’t need much configuring either.  It’ll work straight away but we’ll make a little adjustment or two.  Or three if you own a Samsung TV.  Our Samsung TV could connect to the server OK but wouldn’t play the videos.  If you have the same problem, the fix for it is here.  Read what it says and add the lines to the config file after you have made the following changes:

The configuration file for Mediatomb is /etc/mediatomb/config.xml (note that it’s in /etc, as usual) and is a bit unusual in that it’s an XML file.  Let’s not pussyfoot around here.  XML is a horrible way to present data and to use it in a configuration file is a crime against humanity.  I could rant on for a while but I will spare you that – you have enough problems, being faced with a configuration file in XML format.  So, open it up with sudo nano /etc/mediatomb/config.xml and let’s get started.  As you can see, it’s nice and easy to read – if you are a robot…

<?xml version="1.0" encoding="UTF-8"?>
<config version="2" xmlns="http://mediatomb.cc/config/2" xmlns:xsi="http://www.$
     Read /usr/share/doc/mediatomb-common/README.gz section 6 for more
     information on creating and using config.xml configration files.
    -->
  <server>
    <ui enabled="yes" show-tooltips="yes">
      <accounts enabled="yes" session-timeout="30">
        <account user="mediatomb" password="mediatomb"/>
      </accounts>
    </ui>
    <name>MediaTomb</name>
... and so on ...

Straight away, you should see something that needs changing.  The user interface web page has a default username and password, which is bad.  Change that user=”mediatomb” password=”mediatomb” to something else.  Or, if you are feeling brave, you can change “accounts enabled” to “no” and you won’t have to log on at all. This is a bad idea if you want to access it from outside your home network.

On the line after “<server>” add <port>49152</port> this forces it to use that port rather than pick one of its own choosing.  Done that?  CTRL-X, [Y]es you want to save, return to save it over the top of the original.

I’ve set up a download of a config.xml file with all those changes applied to it.  Feel free to replace yours with it.  The username is “mediatomb”, password is “wibble”.  Please change them on your system.

A quick sudo service mediatomb restart and you are done with the setting up.  To use the web interface, point your browser at http://your_pi_ip:49152 , log in (if you have to) and you should see this:

or something like that anyway.  To get it to index your media, click on the “Filesystem” tab (next to “Database”), then the cross next to “mnt” (to expand that branch) and “downloads” to highlight it.  Over on the right, there will appear a swirly cross which says “Add as autoscan dir” when you hover over it.  Click on it to select that directory as one you want Mediatomb to scan.  Choose “Inotify” for Scan mode, “Basic” for Initial scan and check “Recursive”.  Click on “Set”, it will perform a basic scan and then when you click on the “Database” tab on the left, all your stuff should appear under the “Video” branch.  Documentation for the user interface is available for those who want to tinker.

And that’s it.  Your Pi should appear  as  a media server when your TV/PS3/whatever does a scan.  Any new downloads should appear automatically but be aware that if you swap the external storage, it might not be rescanned when you plug it back in, so you will have get Mediatomb to do it manually.

Put the kettle on, make a cup of tea and enjoy your videos.  That’s pretty much it for now.  There’s one more chapter of useful things to know about Linux.

Continued here.

14 Responses to “A streaming pile of Pi”

  1. Coops says:

    Excellent tutorial. Is there a way to stop windows trying to download the files when accessing mediatomb? I’d prefer it just started to stream them.

    Thanks

  2. Naich says:

    That’s a bit of a windowsy question, I’m afraid. I try to avoid using Windows whenever possible, so my knowledge is limited. Best thing to do is just stick the question into Google.

  3. Maak says:

    Thanks for the great tutorial. My pi is in the post and I was planning on using it to run XBMC to my non Upnp TV, was wondering if it is possible to use the HDMI out to play movies on my dumb TV as well as downloading to my external HD.

  4. Naich says:

    You certainly can, and many people have. http://www.raspbmc.com/

  5. coops says:

    Hi Naich, I’ve spent hours trying to access mediatomb from the internet with no success. I have ports 80(https), 51413(torrents) and 22 (ssh) forwarded to my Pi’s IP address and also set my Pi’s IP to static. I’ve used curl http://icanhazip.com to find out my external IP address but still cant access it when trying the external IP address such as; 90.245.xx.xxx:49152

    Clearly i’m doing something wrong I just don’t know what at the moment, any ideas?

    • Naich says:

      Have you set port 49152 (web control panel for Mediatomb) to forward to the Pi too? You will also need to forward port 9091 to the Pi if you want to access Transmission’s web control panel. In both cases, make sure that password authentication is turned on or that you have whitelisted the IP of the computer you will be connecting from. Otherwise anyone will be able to get in.

  6. coops says:

    Hi Naich – I keep going back to getting this work but still fail. Is there any possibility that my hosting company dont allow connections to open ports through the external IP address? I’ve read a number of posts on how to host your own website, your posts here and still can’t access anything externally, can you recommend anything?

  7. coops says:

    So it was port forwarding problems it was set to ‘customer’ so I changed it to server which works

  8. coops says:

    One last question 🙂 now that i’ve successfully logged on from an external IP address I’m surprised to see that no popup box appears as it does with transmission, any ideas?

    49152

    MediaTomb
    uuid:c26da27c-efab-423f-8c0c-2d65bbf80d72
    /var/lib/mediatomb
    /usr/share/mediatomb/web

    mediatomb.db

    localhost
    mediatomb
    mediatomb

  9. coops says:

    fixed 🙂

  10. Mitesh says:

    thank u for this wonderful tutorial…
    i m facing just 1 problem while accessing external media (external hard disk) on my PC browser it won’t open it says
    ERROR: COULD NOT LIST DIRECTORY /MEDIA/NEW VOLUME : PERMISSION DENIED
    PLZ PLZ PLZ HELP

  11. Naich says:

    Mitesh – you are going to have to give a few more details. What are you using for sharing the files? Samba? It’s obviously a permission thing, so check all the permissions when it’s mounted, check the user you are mounting it under and check the permissions in Samba on the Pi for that directory.

  12. Mitesh says:

    thnks for your response…
    i m trying to stream movies stored in my external hard disk to b stream to my android device.
    but i try to run sudo mediatomb command in lxterminal then i was able to browse external HDD on web browser as well as i can stream to my android device too…
    but to do this everytime i have to run this command in terminal…it’s not auto starting by its own…
    n after this command i can see 2 mediatomb in my android bubbleUPnP application …
    plz help how to fix it…
    thanking you
    regards

  13. Daniel says:

    Since config.xml is storing a plain-text password that is readable to every user by default (-rw-r–r– 1 mediatomb mediatomb). I recommend changing the permissions of it to be a bit more restrictive: sudo chmod 640 config.xml

    thanks for the great tutorial!