📜 ⬆️ ⬇️

Automatic tuning of Icecast2 and mpd to several audio streams

At the request of a friend tried to make online radio. And everything seems to be nothing, but it became necessary to broadcast and manage many streams independently of each other ...

For this, I chose the following path ...


Let's go in order.
')
As a server system I use Ubuntu Server 12.10.

The first step is to put Icecast2:
sudo apt-get install icecast2 


Next put mpd:
 sudo apt-get install mpd 


Create a radio directory in the root of the file system.
Create 3 files in this directory

And copy 2 directories from the / etc / icecast2 / directory


Next, you need to edit the settings files Icecast2 and mpd.

File icecast.xml.default:
 <icecast> <limits> <clients>50</clients> <sources>2</sources> <threadpool>5</threadpool> <queue-size>524288</queue-size> <client-timeout>30</client-timeout> <header-timeout>15</header-timeout> <source-timeout>10</source-timeout> <burst-on-connect>1</burst-on-connect> <burst-size>65535</burst-size> </limits> <authentication> <source-password>#2</source-password> <relay-password>#2_relay</relay-password> <admin-user>admin</admin-user> <admin-password>admin_#2</admin-password> </authentication> <hostname>127.0.0.1</hostname> <listen-socket> <port>#3</port> </listen-socket> <mount> <mount-name>/#1</mount-name> </mount> <paths> <basedir>#0/#1/icecast2</basedir> <logdir>#0/#1/icecast2/log</logdir> <webroot>#0/#1/icecast2/web</webroot> <adminroot>#0/#1/icecast2/admin</adminroot> <pidfile>#0/#1/icecast2/icecast.pid</pidfile> <alias source="/" dest="/status.xsl"/> </paths> <logging> <accesslog>access.log</accesslog> <errorlog>error.log</errorlog> <loglevel>4</loglevel> <logsize>10000</logsize> </logging> <security> <chroot>0</chroot> <changeowner> <user>icecast</user> <group>icecast</group> </changeowner> </security> </icecast> 

Let us understand what the parameters mean:
# 0 - path to user directory
# 1 - username
# 2 - user password
# 3 - the port on which Icecast2 will be launched

Now edit mpd.conf.default:
 music_directory "#1/#2/music" playlist_directory "#1/#2/playlists" db_file "#1/#2/lib/tag_cache" log_file "#1/#2/log/mpd.log" pid_file "#1/#2/pid" state_file "#1/#2/state" user "mpd" bind_to_address "127.0.0.1" port "#5" auto_update "yes" audio_output { type "shout" name "#2 radio" encoding "mp3" host "localhost" port "#4" mount "/#2" password "#3" bitrate "192" format "44100:16:2" } audio_output { type "alsa" name "fake out" driver "null" } volume_normalization "yes" filesystem_charset "UTF-8" id3v1_encoding "UTF-8" metadata_to_use "artist,album,title,track,name,genre,date,composer,performer,disc" 

Mpd options:
# 1 - path to user directory
# 2 - username
# 3 - user password for Icecast2
# 4 - the port on which Icecast2 is running
# 5 - port to control mpd

And the last file is the setup script:
 #!/bin/bash MAIN_DIR=/userAlias FROM=/radio if [ $# -lt 4 ]; then echo "====    ====" echo " ./script.sh 'userName' 'userPassword' 'port' 'mpdPort'" exit 1 fi echo "<===>    <===>" if [ ! -d "$MAIN_DIR" ]; then mkdir $MAIN_DIR echo "     " fi mkdir $MAIN_DIR'/'$1 echo "    " $1 echo "" echo "<===>  icecast <===>" cp $FROM/icecast.xml.default $MAIN_DIR'/'$1'/'icecast.xml replace '#0' $MAIN_DIR -- $MAIN_DIR'/'$1'/'icecast.xml replace '#1' $1 -- $MAIN_DIR'/'$1'/'icecast.xml replace '#2' $2 -- $MAIN_DIR'/'$1'/'icecast.xml replace '#3' $3 -- $MAIN_DIR'/'$1'/'icecast.xml mkdir $MAIN_DIR'/'$1'/icecast2' mkdir $MAIN_DIR'/'$1'/icecast2/log' mkdir $MAIN_DIR'/'$1'/icecast2/web' mkdir $MAIN_DIR'/'$1'/icecast2/admin' cp $FROM/icecastDirs/admin/* $MAIN_DIR'/'$1'/icecast2/admin' cp $FROM/icecastDirs/web/* $MAIN_DIR'/'$1'/icecast2/web' touch $MAIN_DIR/$1/icecast2/log/error.log touch $MAIN_DIR/$1/icecast2/log/access.log chown icecast:icecast $MAIN_DIR/$1/icecast.xml chown icecast:icecast $MAIN_DIR/$1/icecast2/log/* echo "<===>  icecast  <===>" echo "" echo "<===>  mpd <===>" cp $FROM/mpd.conf.default $MAIN_DIR'/'$1'/'mpd.conf replace '#1' $MAIN_DIR -- $MAIN_DIR'/'$1'/'mpd.conf replace '#2' $1 -- $MAIN_DIR'/'$1'/'mpd.conf replace '#3' $2 -- $MAIN_DIR'/'$1'/'mpd.conf replace '#4' $3 -- $MAIN_DIR'/'$1'/'mpd.conf replace '#5' $4 -- $MAIN_DIR'/'$1'/'mpd.conf mkdir $MAIN_DIR'/'$1'/music' mkdir $MAIN_DIR'/'$1'/playlists' mkdir $MAIN_DIR'/'$1'/lib' mkdir $MAIN_DIR'/'$1'/log' touch $MAIN_DIR/$1/lib/tag_cache chmod 777 $MAIN_DIR/$1/lib/tag_cache touch $MAIN_DIR/$1/pid chmod 777 $MAIN_DIR/$1/pid echo "<===>  mpd  <===>" echo "<===>  icecast <===>" icecast2 -b -c $MAIN_DIR'/'$1'/'icecast.xml sleep 1s echo "<===>  mpd <===>" mpd $MAIN_DIR'/'$1'/'mpd.conf 

If you do not go into details, the script does the following:


After creating 3 files you need to make the script run:
 chmod 777 script.sh 


And execute:
 ./script.sh radio1 password1 9001 19001 


After running the script, Icecast2 and mpd will be launched.
In the browser, you can try to contact:
 :9001/radio1 

... mpd ( ) .

: /userAlias/radio1/music/

- mpd:
sudo apt-get install ncmpc
mpd.
:
ncmpc -p 19001
music Ctrl + U
'3' - .
/ .
'2' - . Enter - .

, :9001/radio1 .

, .
:9001/radio1

... mpd ( ) .

: /userAlias/radio1/music/

- mpd:
sudo apt-get install ncmpc

mpd.
:
ncmpc -p 19001
music Ctrl + U
'3' - .
/ .
'2' - . Enter - .

, :9001/radio1 .

, .

Source: https://habr.com/ru/post/170235/


All Articles