In this posting we are going to turn a Raspberry Pi into a media streaming device, using minidlna.
Preparation of the Raspberry Pi
- Follow the instructions at How to install the Raspbian OS on a Raspberry Pi.
- Change the hostname of your Raspberry Pi to something more meaningful by logging on to the device as user “pi” and issuing the command:
sudo raspi-config
- Select “Advanced Options” and set the following:
- Hostname = pi-media (or whatever you want to call it).
- Select Finish
- Reboot the Raspberry Pi
Install minidlna
- First, make sure that the package indexes are up to date with:
sudo apt-get update
- Installing the minidlna package is as easy as entering the commands:
sudo apt-get install minidlna
sudo chown minidlna:minidlna /var/lib/minidlna
- On completion, create a directory in which the media you wish to stream will be stored. For the moment we will save some media to subdirectories under /home/pi on the Raspberry Pi’s SD card, but once we are happy it is working, we will mount an external hard disk and serve the media up from that. For now, type:
mkdir -p "/home/pi/media/videos"
mkdir -p "/home/pi/media/pictures"
mkdir -p "/home/pi/media/music"
- To ensure that the minidlna user has the privilege to read from the directories under the pi user, add minidlna to the pi user group with:
sudo usermod -a -G pi minidlna
- Now we will create the directories which will be used for storing the minidlna database and the log files:
sudo mkdir /var/{cache,log}/minidlna
sudo chown minidlna:minidlna /var/{cache,log}/minidlna
- The next step is to make some changes to the minidlna configuration file. Open the file for editing with:
sudo vi /etc/minidlna.conf
…and make the following changes (changing the IP address to match your Raspberry Pi. If you’re not sure of the IP address, use the ifconfig command):
media_dir=A,/home/pi/media/music
media_dir=P,/home/pi/media/pictures
media_dir=V,/home/pi/media/videos
db_dir=/var/cache/minidlna
log_dir=/var/log/minidlna
listening_ip=192.168.XXX.XXX
inotify=yes
notify_interval=300
- Open the sysctl.conf file for editing with:
sudo vi /etc/sysctl.conf
…and add the following to the bottom of the file:
# minidlna server tweaks
fs.inotify.max_user_watches = 100000
# end of minidlna server tweaks
- Rebuild the database and restart minidlna with:
sudo service minidlna stop
sudo service minidlna force-reload
sudo service minidlna start
You can now add music, pictures and videos to the respective directories under /home/pi/media.