Today I want to report on how I configured my home server so that it is able to stream music to my home network.
First of all, I installed the necessary software, i. e. mpd and icecast2 with aptitude install mpd icecast2.
mpd
Then, I configured mpd by editing /etc/mpd.conf as follows:
music_directory "/var/lib/mpd/music"
playlist_directory "/var/lib/mpd/playlists"
db_file "/var/lib/mpd/tag_cache"
log_file "/var/log/mpd/mpd.log"
error_file "/var/log/mpd/errors.log"
pid_file "/var/run/mpd/pid"
The first line sets the directory where mpd will look for music. I just used the default and created symlinks within that directory to my data folders containing my music collection.
state_file "/var/lib/mpd/state"
This ensures that mpd will remember its state upon restart, so that e. g. the current playlist will be restored.
bind_to_address "any"
port "6600"
These lines will allow me to control mpd over the network. Later on, mpd clients will be configured to use the address of the server and this port to control mpd.
Now, the core option for streaming the music follows. Since I do not only want to hear music being locally restricted to the room the server resides, I chose an icecast2 server as output.
audio_output {
type "shout"
name "zeus"
host "localhost"
port "8000"
mount "/mpd.ogg"
password "********"
quality "8.0"
format "44100:16:1"
}
This configures mpd to output played music in OGG vorbis format with a quality of 8.0 to a shoutcast-compatible server (i. e. icecast2 in this case) running on localhost, port 8000. The password here will also be set in icecast2, so that only we are allowed to output music to the icecast2 server.
The quality of 8.0 is quite high but for a local network bandwidth does not matter.
mixer_type "software"
With this option I told mpd to adjust volume not at hardware level but at software level since mpd does not output the music to a hardware device.
replaygain "track"
replaygain_preamp "0"
volume_normalization "yes"
These three options tell mpd to apply track replay gain so that each track shall have equal volume.
Now, we’ve configured mpd. At last, I created the necessary symlinks in /var/lib/mpd/music, e. g.
ln -s /path/to/my/music /var/lib/mpd/music/collection
Before we create the database for mpd and start the daemon, beware of one bug that’s not fixed in Ubuntu Intrepid’s version of mpd:
mpd will hang while scanning your music if there are .m4a files among them, especially if they are from Itunes. This bug is known and fixed in current mpd releases and therefore will surely be fixed in future Ubuntu versions.
I’ve solved this by setting the permissions of all .m4as in a way that does not allow mpd to read them, e. g.
find /path/to/music -iname "*.m4a" -exec chmod 600 {} \;
Since I am the owner of those files and mpd usually runs as user mpd this works quite well as a temporary fix, although those files cannot be played, of course, which might not suit everybody. So another option is re-encoding them, of course.
Then, I created mpd’s database:
/etc/init.d/mpd start-create-db
And restarted mpd, just to make sure the config is reloaded:
/etc/init.d/mpd restart
Next step is icecast2, then.
icecast2
For icecast2, I just used the default XML config file /etc/icecast2/icecast.xml and adjusted it as follows:
<clients>4</clients>
<sources>1</sources>
This restricts the number of clients to four (suits me) and the number of sources to one (the mpd).
<burst-on-connect>0</burst-on-connect>
This disables burst-on-connect which fills a the buffer of a client that plays the stream with an initial load of data. This reduces latency a bit.
<source-password>********</source-password>
Set to the same password as above.
<admin-password>********</admin-password>
Set to the password I’ll use for the web administration later on.
<hostname>hera.olymp.org</hostname>
The hostname of my home server.
At last, I set in /etc/default/icecast2:
ENABLE=true
and restarted icecast2:
/etc/init.d/icecast2 restart
Clients
As client for mpd I’m currently using sonata since I fancy it’s approach as light-weight client for mpd while still delivering very useful features like automatic cover art, artist info and lyrics as well as last.fm support.
sonata does not play the stream, though, so I still need to start, e. g. mplayer as client for the stream:
mplayer http://hera.olymp.org:8000/mpd.ogg
Sadly, I’ve found not yet a client that integrates controlling mpd and playing a stream concurrently.
Sources
I used these two howtos:
Linux, Music, Tips
home server, howto, icecast2, Linux, mpd, shoutcast, sonata, streaming