Skip navigation.

無語録むごろく

ムゴロク

Media Streaming -- Icecast 2 and MPD-SVN

註:寫這篇文章可能有點長,不過中間有很多地方日後可能會修改,所以這個是未完成的哦~!要是當成參考也是可以的,請給多一點耐心看一下。

某天忽發奇想,要是帶這麼多歌回公司,不如自已建一台 media streaming server ,那只要上網就可以聽到自已想聽的歌曲了。
(雖然好像非常浪費電力......我家那台舊機器辛苦了)

好,返回正題,我們先從 streaming server 入手,我選擇了 icecast2 ,原因無他,因為在 Linux 下選擇好像不多。

首先,想辨法安裝好 icecast 2 ,這個取決於你們用什麼 distro ,我這裏是 Gentoo ,其他看倌們自已想辦法好了。

之後就來到 Configuration 的階段︰

<icecast>
    <limits>
        <clients>100</clients>
        <sources>2</sources>
        <threadpool>5</threadpool>
        <queue-size>102400</queue-size>
        <client-timeout>30</client-timeout>
        <header-timeout>15</header-timeout>
        <source-timeout>10</source-timeout>
        <!-- If enabled, this will provide a burst of data when a client 
             first connects, thereby significantly reducing the startup 
             time for listeners that do substantial buffering. However,
             it also significantly increases latency between the source
             client and listening client.  For low-latency setups, you
             might want to disable this. -->
        <burst-on-connect>1</burst-on-connect>
        <!-- same as burst-on-connect, but this allows for being more
             specific on how much to burst. Most people won't need to
             change from the default 64k. Applies to all mountpoints  -->
        <burst-size>65535</burst-size>
    </limits>

    <authentication>
        <!-- Sources log in with username 'source' -->
        <source-password>hackme</source-password>
        <!-- Relays log in username 'relay' -->
        <relay-password>hackme</relay-password>

        <!-- Admin logs in with the username given below -->
        <admin-user>admin</admin-user>
        <admin-password>hackme</admin-password>
    </authentication>

    <!-- Uncomment this if you want directory listings -->
    <!--
    <directory>
        <yp-url-timeout>15</yp-url-timeout>
        <yp-url>http://dir.xiph.org/cgi-bin/yp-cgi</yp-url>
    </directory>
    <directory>
        <yp-url-timeout>15</yp-url-timeout>
        <yp-url>http://www.oddsock.org/cgi-bin/yp-cgi</yp-url>
    </directory>
     -->

    <!-- This is the hostname other people will use to connect to your server.
    It affects mainly the urls generated by Icecast for playlists and yp
    listings. -->
    <hostname>127.0.0.1</hostname>

    <!-- You can use these two if you only want a single listener -->
    <!--<port>8000</port> -->
    <!--<bind-address>127.0.0.1</bind-address>-->

    <!-- You may have multiple <listener> elements -->
    <listen-socket>
        <port>8000</port>
        <!-- <bind-address>127.0.0.1</bind-address> -->
<bind-address>127.0.0.1</bind-address>
    </listen-socket>
    <listen-socket>
    <port>8001</port>
<bind-address>192.168.11.8</bind-address>
    </listen-socket>
    <!--
    <listen-socket>
        <port>8001</port>
    </listen-socket>
    -->

    <!--<master-server>127.0.0.1</master-server>-->
    <!--<master-server-port>8001</master-server-port>-->
    <!--<master-update-interval>120</master-update-interval>-->
    <!--<master-password>hackme</master-password>-->
    <!--
    <relay>
        <server>127.0.0.1</server>
        <port>8001</port>
        <mount>/example.ogg</mount>
        <local-mount>/different.ogg</local-mount>

        <relay-shoutcast-metadata>0</relay-shoutcast-metadata>
    </relay>
    -->

    <!-- Only define a <mount> section if you want to use advanced options,
         like alternative usernames or passwords
    <mount>
        <mount-name>/example-complex.ogg</mount-name>

        <username>othersource</username>
        <password>hackmemore</password>

        <max-listeners>1</max-listeners>
        <dump-file>/tmp/dump-example1.ogg</dump-file>
        <burst-size>65536</burst-size>
        <fallback-mount>/example2.ogg</fallback-mount>
        <authentication type="htpasswd">
                <option name="filename" value="myauth"/>
                <option name="allow_duplicate_users" value="0"/>
        </authentication>
    </mount>
    -->

    <fileserve>1</fileserve>

    <paths>
<!-- basedir is only used if chroot is enabled -->
        <basedir>/usr/share/icecast</basedir>

        <!-- Note that if <chroot> is turned on below, these paths must both
             be relative to the new root, not the original root -->
        <logdir>/var/log/icecast</logdir>
        <webroot>/usr/share/icecast/web</webroot>
        <adminroot>/usr/share/icecast/admin</adminroot>
        <!-- <pidfile>/usr/share/icecast/icecast.pid</pidfile> -->

        <!-- Aliases: treat requests for 'source' path as being for 'dest' path
             May be made specific to a port or bound address using the "port"
             and "bind-address" attributes.
          -->
        <!--
        <alias source="/foo" dest="/bar"/>
          -->
        <!-- Aliases: can also be used for simple redirections as well,
             this example will redirect all requests for http://server:port/ to
             the status page
          -->
        <alias source="/" dest="/status.xsl"/>
    </paths>

    <logging>
        <accesslog>access.log</accesslog>
        <errorlog>error.log</errorlog>
      <loglevel>4</loglevel> <!-- 4 Debug, 3 Info, 2 Warn, 1 Error -->
    </logging>

    <security>
        <chroot>0</chroot>
        <!--
        <changeowner>
            <user>nobody</user>
            <group>nogroup</group>
        </changeowner>
        -->
    </security>
</icecast>

以上是我個人的 Setting ,當然每個人的設定都不盡相同,我這裏是作參考的,有什麼問題可以自已到 icecast 的網頁自已慢慢研究,網址如下︰

Icecast Official Site

相搞好了 media streaming server ,那我們可以想一想用什麼來做 source client 。
當然,我們可以把曲目放到 icecast 的 base dir 中 ,寫好 playlist 就可以播。但我不喜歡把所有的曲歌曲都轉為 Ogg 格式,所以把可試的都試過後,選擇了 MPD。

MPD 是什麼可以看一下以下網址︰

MPD Official Site

當然我們要先安裝好,之後又是 Configuration ︰

# MPD CONFIG FILE
# For a full description of all config parameters,
# Check the mpd man page, "man mpd".

##################### REQUIRED ###########################
port "6600"
#music_directory "/var/lib/mpd/music"
music_directory "/home/steven/.xchat2/downloads/Songs/Singular_Songs"
playlist_directory "/var/lib/mpd/playlists"
#playlist_directory "/home/steven/.xchat2/downloads/Songs/playlists"
log_file "/var/log/mpd.log"
error_file "/var/log/mpd.error.log"
pid_file "/var/log/mpd.pid"
##########################################################

##########################################################
# EVERYTHING ELSE IS OPTIONAL
##########################################################

################# FILESYSTEM SETTINGS ####################
#
# If the names of files or directories are 
# not correctly displayed then set the 
# following to the filesystem coding. 
#
#Usually this is either:
#ISO-8859-1 or UTF-8
#
# After changing the filesystem_charset
# you will need to recreate the db:
#mpd --create-db
#
filesystem_charset "UTF-8"
#
##########################################################

#################### OPTIONAL FILES ######################
#
# Location of DB file 
#
db_file"~/.mpd/mpd.db"
#
# The state file (if set) will be a file
# for storing all current information 
# (playlist, playing/paused, etc...) from
# the last MPD session. This will be used
# to recreate your last MPD session after
# restart.
#
state_file "/var/lib/mpd/state"
#
##########################################################


################### VOLUME MIXER #########################
#
# Examples:
# ALSA Mixer 
mixer_type"alsa"
mixer_device"default"
mixer_control"PCM"
#
# OSS Mixer
#mixer_type"oss"
#mixer_device "/dev/mixer"
#mixer_control"PCM"
#
# Software Mixer
#mixer_type"software"
#
##########################################################


################## AUDIO OUTPUT ##########################
#
# OSS Audio Output
#ao_driver "oss"
#ao_driver_options "dsp=/dev/dsp"
#
# ALSA Audio Output
#ao_driver"alsa09"
#ao_driver_options"dev=hw:0,0"
#
# Set this if you have problems 
# playing audio files.
# This will resample your music so
# that it comes out at the set rate. 
#
audio_output_format"44100:16:2"
#
# You should not need mess with 
# this value unless you know 
# what you're doing.
#
#audio_write_size"1024"
#
##########################################################

################# REPLAYGAIN #############################
#
# Use Replay Gain (album or title)
#http://www.replaygain.org
#
#replaygain"album"
#
# Sets the pre-amp used for files that have replaygain
# info.  Valid values are between -15 to 15 (in dB).
#
#replaygain_preamp"0"
#
##########################################################


################ OUTPUT BUFFER SETTINGS ##################
#
# You should not need to mess with this
# unless you know what you're doing.
#
#audio_buffer_size"2048"
#
# This means exactly what it says, it will
# buffer your file up to the percentage of
# the buffer before it begins playing.
#
buffer_before_play "25%"
#
##########################################################


################### HTTP PROXY ###########################
#
# http_proxy_host"proxy.isp.com"
# http_proxy_port"8080"
# http_proxy_user"user"
# http_proxy_password"password"
#
##########################################################


################# SECURITY SETTINGS ######################
#
# It is encouraged to run MPD as 
# non-superuser.  If you start mpd as root
# (for example, in an init script), set
# this value, then  mpd will drop root priveleges
# and runs as the user specified.
#
#user "mpd"
user "steven"
#
# Set this value if you only have one 
# address you want to allow connection to. 
#
#bind_to_address "192.168.11.8"
bind_to_address "127.0.0.1"
#
# If you want to setup MPD to use 
# passwords set them here
#
#password "password1@read,add,control,admin"
#password "password2@read"
#
# Specify permissions used by default when no password is 
# given by for a connection/client.
#
#default_permissions"read,add,control,admin"
#
##########################################


################ MISCELLANEOUS OPTIONS ###################
#
# This setting exists as precaution against attacks.
#
#max_playlist_length "16384"
#
# Valid options are "default", "secure" or "verbose".
#log_level"default"
#
#connection_timeout "60"
#
# This should be fine for 2-3 people using clients 
# at the same time.
#
#max_connections "5"
#
# No need to change these unless you know better.
#
#max_command_list_size "2048"
#max_output_buffer_size "2048"
#
# This will make playlists compatible with normal music
# players.
#
#save_absolute_paths_in_playlists "no"
#
##########################################################

################# SHOUT STREAMING ########################
#
# Set this to allow mpd to stream its output to icecast2
# (i.e. mpd is a icecast2 source)
#
audio_output {
        type              "shout"
name              "mpd-svn stream"
host              "192.168.11.8"
port              "8001"
mount             "/live.ogg"
password          "hackme"
quality           "5.0"   
#       bitrate           "64"
format            "44100:16:1"

# Optional Paramters
user              "source"
#       description     "here's my long description"
#       genre           "jazz"
} # end of audio_output
###########################################################

當設定好後,便可以用 init script 把這個 service 啓動︰

/etc/init.d/mpd start

之後就是 MPD 的 front-end ,我選用了 MPC 因為可以在 shell 中控制,不用 GUI ,對我來說就可以 remote control 了。

安裝好 MPD 後,

請啓動以下 commands ︰

mpc update
mpc ls | mpc add
mpc play

好了,到了這個地步,所有的東西都準備好,只要用可以聽 stream 的 players ,就可以在任何一台可以上網的電腦上收聽了。

看起來很簡單吧,看倌們可以自已一試~!

選擇Nvidia Display problems

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

November 2009
S M T W T F S
October 2009December 2009
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30