Icecast and Musicpd

From FreeBSDwiki
Jump to: navigation, search



As my laptop's music collection was getting larger and I was wanting more elbow room, I decided it was finally time to offload most of it to a remote machine and figure out some way to access it easily via the internet.

Setting up Icecast2

The first step was to install Icecast2. I did this from audio/icecast2 in ports, but it can probably be done via pkg_add instead. Once installed, it should be configured. It seems that /usr/local/share/icecast/doc/ has some config examples. In the configuration file, the <source-password>, <admin-password>, and <bind-address> are the main fields that I changed. As I want to be the only one listening to this (which is to say didn't want the stream shared via the internet), I set <bind-address> to . I also changed <user> and <group> to be nobody as I had been starting the server as root.

Setting up MusicPD (ports method)

  • MusicPD can now (as of musicpd 0.13.0_2) be setup with shoutcast plugin support for icecast from within the ports subsystem. This means that configuration and install is very simple. I recommend setting up id3tag support (which for some reason currently defaults to off in the port). "make config" will allow you to change the options for the port on rebuilds. (optional)
cd /usr/ports/audio/musicpd
make config
make install

In order to run the MPD server, you need to create an mpd.conf file. Start with the defaults example by copying the defaults file to /usr/local/etc/mpd.conf. You will need to change a few values to get shoutcast working (uncomment the shout example, set passwords, etc.)

 cp /usr/local/share/doc/mpd/mpdconf.example /usr/local/etc/mpd.conf

and add the following line to /etc/rc.conf:


Then start the server with:

 /usr/local/etc/rc.d/musicpd start 

or reboot.

Setting up MusicPD (manual method)

The second thing I did was set up musicpd. As the version in ports (as of this writing) doesn't yet support streaming to the icecast server, I had to grab the version from their svn (this requires having subversion installed). Go to a directory of you choosing and try this:

svn co musicpd
 cd mpd

Now, as (probably a way to make it do the right thing) didn't actually do everything quite right for me I had to export LD_FLAGS=-lc_r and then the following:

./configure --with-libFLAC=/usr/local/ --with-ogg=/usr/local/ \
 --with-vorbis=/usr/local/ --disable-tremor --enable-shout \
 --enable-ogg --disable-ipv6

Each of these arguments is for a reason. FLAC, ogg, and vorbis install in /usr/local/wherever on freebsd and I guess that the script assumes them to be elsewhere. --disable-tremor is required because tremor and shout are mutually exclusive for mpd. --enable-shout enables shout protocol streaming (which icecast2 uses) and --disable-ipv6 was necessary to overcome a bug with musicpd on freebsd. After that:

gmake && gmake install

With musicpd installed, there's the task of configuring it. From the musicpd port, I copied and filled in this startup script:


# PROVIDE: musicpd
# KEYWORD: FreeBSD shutdown

# Add the following line to /etc/rc.conf to enable mpd:

. /etc/rc.subr



musicpd_flags="$musicpd_flags $config"

[ -z "$musicpd_enable" ] && musicpd_enable="NO"
[ -z "$musicpd_flags" ]  && musicpd_flags=

load_rc_config $name

run_rc_command "$1"

In /usr/local/etc/mpd.conf I modified the example configuration file (from the doc subdirectory of the svn repository that we checked out earlier) to have the following lines:

music_directory         "/mnt/storageDrive/media/music"
playlist_directory      "/mnt/storageDrive/media/music"
db_file                 "/var/mpd/mpd.db"
log_file                "/var/mpd/mpd.log"
error_file              "/var/mpd/mpd.error"
pid_file                "/var/mpd/"
audio_output {
 type            "shout"
 name            "my cool stream"
 host            ""
 port            "8000"
 mount           "/mpd.ogg"
 password        "sourcepasswordfromicecastconfigfile"
 bitrate         "128"
 format          "44100:16:1"
 user            "source"
bind_to_address         ""

Again, the address as I don't want this control available to everyone on the internet. Make sure that the password in this file and <source-password> in icecast's configuration file match. Set the bitrate to be whatever format you would like. MusicPD will reencode all of your music to that bitrate and ogg format as you listen. Now icecast and musicpd should be installed and configured. To get them to start automagically at boot, Try adding the following to /etc/rc.conf :

#for musicpd
#for icecast

Getting the music to the client

Once icecast and musicpd are running, it's very easy to get music to the client. I use ssh port-forwarding to do it.

ssh -N -L6600: username@server &
ssh -N -L8000: username@server &

And now to enjoy the tunes and control the server, you can install your favourite ogg-player (I'm currently using xmms-kde) and mpd client (kmp here).

Audioscrobbler support

For audioscrobbler support, I am using mpdscribbler downloaded from . To install it, I exported LDFLAGS=-lc_r and then did this:

tar -xf mpdscribble-0.2.7.tar.gz
cd mpdscribble-0.2.7
make install

After this, the usual setup procedure is to run Unfortunately the script is a bit linuxified so I simply made a config in the following format:

username = username
password = md5ofmypassword
cache = /usr/home/username/.mpdscribble/mpdscribble.cache
log = /usr/home/username/.mpdscribble/mpdscribble.log
verbose = 2

Just running mpdscribble after this works for me without trouble. To get the md5 of a password, the following works:

md5 -s 'My super cool password'

External links

Icecast homepage

MusicPD homepage

mpdscribble homepage

Personal tools