pavement

Icecast and Musicpd

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
(Setting up MusicPD: automatically is not a word)
(Setting up MusicPD)
 
(One intermediate revision by one user not shown)
Line 3: Line 3:
 
== Setting up Icecast2 ==
 
== 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 127.0.0.1 .  I also changed <user> and <group> to be nobody as I had been starting the server as root.
 
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 127.0.0.1 .  I also changed <user> and <group> to be nobody as I had been starting the server as root.
== Setting up MusicPD ==
+
== Setting up MusicPD (ports method) ==
The second thing I did was set up musicpd.  '''As the version in ports 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:
+
*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:
 +
  musicpd_enable="YES"
 +
 
 +
Then start the server with:
 +
  /usr/local/etc/rc.d/musicpd start
 +
or reboot.
 +
 
 +
*Warning, ensure that the directories specified in mpd.conf both '''exist''' and have the correct permissions.  mpd will fail miserably {with little error messaging} if this is not setup properly. See http://mpd.wikia.com/wiki/Music_Player_Daemon_HOWTO_Troubleshoot for more information.
 +
== 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:
 
  <nowiki>svn co https://svn.musicpd.org/mpd/trunk musicpd
 
  <nowiki>svn co https://svn.musicpd.org/mpd/trunk musicpd
 
  cd mpd
 
  cd mpd
Line 64: Line 82:
 
  bind_to_address        "127.0.0.1"
 
  bind_to_address        "127.0.0.1"
 
Again, the 127.0.0.1 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.
 
Again, the 127.0.0.1 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 automatically at boot, Try adding the following to /etc/rc.conf :
+
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 musicpd
 
  musicpd_enable="YES"
 
  musicpd_enable="YES"

Latest revision as of 11:48, 2 July 2008

Contents

[edit] Introduction

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.

[edit] 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 127.0.0.1 . I also changed <user> and <group> to be nobody as I had been starting the server as root.

[edit] 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:

 musicpd_enable="YES"

Then start the server with:

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

or reboot.

[edit] 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 https://svn.musicpd.org/mpd/trunk musicpd
 cd mpd
 ./autogen.sh

Now, as autogen.sh (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:

#!/bin/sh
#

# PROVIDE: musicpd
# REQUIRE:
# BEFORE:
# KEYWORD: FreeBSD shutdown

# Add the following line to /etc/rc.conf to enable mpd:
#
#musicpd_enable="YES"

. /etc/rc.subr

name=musicpd
rcvar=`set_rcvar`

config=/usr/local/etc/mpd.conf
command=/usr/local/bin/mpd
required_files=$config

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/mpd.pid"
audio_output {
 type            "shout"
 name            "my cool stream"
 host            "127.0.0.1"
 port            "8000"
 mount           "/mpd.ogg"
 password        "sourcepasswordfromicecastconfigfile"
 bitrate         "128"
 format          "44100:16:1"
 user            "source"
}
bind_to_address         "127.0.0.1"

Again, the 127.0.0.1 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
musicpd_enable="YES"
#for icecast
icecast_enable="YES"

[edit] 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:127.0.0.1:6600 username@server &
ssh -N -L8000:127.0.0.1:8000 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).

[edit] Audioscrobbler support

For audioscrobbler support, I am using mpdscribbler downloaded from http://www.frob.nl/projects/scribble/mpdscribble-0.2.7.tar.gz . 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
./configure
make
make install

After this, the usual setup procedure is to run setup.sh. Unfortunately the setup.sh 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'

[edit] External links

Icecast homepage

MusicPD homepage

mpdscribble homepage

Personal tools