流媒体服务器允许您通过基于 TCP 的网络传输 MP3 文件。这可以是互联网本身,也可以是您的本地网络/内联网。
连接原理与 Web 服务器非常相似,当客户端(MP3 播放器)连接到服务器时,文件会被流式传输。
下载并解压后,最好仔细查看一下 doc/ 目录,HTML 手册非常有用且全面。
如果您已下载源代码,请按照与您的系统相关的编译说明进行操作。
除非您在配置文件 icecast.conf 中正确设置了 servername,否则 Icecast 将无法正常工作,该文件位于 etc 目录中。它必须与解析到您的 IP 地址的名称完全匹配。
如果您在 Icecast 启动时看到以下行,则说明存在问题
-> [05/Jan/2000:17:21:04] WARNING: Resolving the server name [your.server.name] does not work!
编辑位于 etc 目录中的 icecast.conf,找到包含 “server_name” 条目的行,并输入您的服务器名称。如果您不确定,可以使用 hostname 命令或使用 cat 命令查看 /etc/hosts 文件来查找。
完成必要的更改后,您需要将 conf 文件复制到 bin 目录,或者使用 -c 选项启动 icecast 并指定位置,如下所示
[dj@megajukebox bin]$ ./icecast -c ../etc/icecast.conf
如果一切配置正确,您应该会看到类似于以下内容
[dj@megajukebox bin]$ ./icecast -c ../etc/icecast.conf -d /home/dj/mp3/icecast/ Icecast Version 1.3.0 Starting... Icecast comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of Icecast under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING. [05/Jan/2000:18:36:30] Icecast Version 1.3.0 Starting.. [05/Jan/2000:18:36:30] Using stdin as icecast operator console [05/Jan/2000:18:36:30] Tailing file to icecast operator console [05/Jan/2000:18:36:30] Server started... [05/Jan/2000:18:36:30] Listening on port 8000... [05/Jan/2000:18:36:30] Using [megajukebox] as servername... [05/Jan/2000:18:36:30] Max values: 1000 clients, 1000 clients per source, 10 sources, 5 admins -> [05/Jan/2000:18:36:30] [Bandwidth: 0.000000MB/s] [Sources: 0] [Clients: 0] [Admins: 1] [Uptime: 0 seconds]
-d 选项设置日志文件和模板的目录。
以下是命令行选项列表
-c [filename] Parse as a configuration file. Please note that any command line parameters you supply after this override whatever is in file. Also note that icecast.conf in the current directory is already parsed when you specify this file, so anything in icecast.conf not overridden by the new configuration file will be used by the server. -P [port] This is the port used for all client, source, and admin connections. It's set to 8000 by default. -m [max clients] Allow this number of client connections. When this number is reached, all client connections will be refused with 'HTTP/1.0 504 Server Full' -p [encoder password] This sets the password that the encoder must use to be allowed to stream to the server. Note that if you have compiled the server with crypt() support, this argument must be an encrypted string. -b This will send the icecast server into the background (i.e daemon process). To use the admin commands now, you have to connect to the server as an admin, using some sort of telnet client. -d [directory] Make all log files created by icecast, and all templates that icecast looks for be relative to this directory.
好了,服务器已经启动了,但是您现在需要将 MP3 源连接到服务器。
您可以从两个应用程序中选择将 MP3 数据传递到服务器,Shout 和 LiveIce。
Shout 为 Icecast 提供要流式传输的 MP3 的静态播放列表,并包含在 Icecast 中。
如果要流式传输 MP3 文件,可以使用以下命令创建播放列表
find [MP3 directory] -name '*.mp3' -print > playlist
在最基本的层面上,要启动 shout 服务,请发出以下命令
[dj@megajukebox bin]# ./shout megajukebox -P hackme -p playlist
-P 选项指定向 Icecast 添加挂载点所需的密码,它被恰当地设置为 hackme...... 我强烈建议您更改它,否则可能会有人这样做 :) -p 选项指定播放列表文件的位置。以下是所有命令行选项的列表
[dj@megajukebox bin]# ./shout Usage: shout <host> [options] [[-b <bitrate] file.mp3]... Options: -B <directory> - Use directory for all shout's files. -C <file> - Use file as configuration file -D <dj_file> - Run this before every song (system()) -P <password> - Use specified password -S - Display all settings and exit -V - Use verbose output -X <desc> - Use specified description. -a - Turn on automatic bitrate (transfer) correction -b <bitrate> - Start using specified bitrate -d - Activate the dj. -e <port> - Connect to port on server. -f - Skip files that don't match the specified bitrate -g <genre> - Use specified genre -h - Show this text -i - Use old icy headers -k - Don't truncate the internal playlist (continue) -l - Go on forever (loop) -m <mount> - Use specified mount point -n <name> - Use specified name -o - Turn of the bitrate autodetection. -p <playlist> - Use specified file as a playlist -r - Shuffle playlist (random play) -s - (Secret) Don't send meta data to the directory server -u <url> - Use specified url -v - Show version -x - Don't update the cue file (saves cpu) -z - Go into the background (Daemon mode) -t - Enable title streaming
LiveIce 可以以 2 种模式工作,它可以将播放列表传递给 Icecast,也可以从声卡传递实时音频。
解压并阅读关于构建软件包的 README 后,请确保您已安装并可以使用 mpg123,因为 LiveIce 需要它。
有两种配置 LiveIce 的方法:使用 vi/emacs 或其他编辑器编辑配置文件,或者使用基于 TK 的配置工具,这是一种更美观的编辑方式 :)
描述 liveice.cfg 内部结构的最佳位置可以在 LiveIce 的主页上找到,Scott 在那里介绍了所有选项。
这是我的配置文件副本,其中 LiveIce 设置为混音器模式(从 MP3 列表流式传输)
注意:我在文件中添加了注释,因此如果您复制粘贴,请确保注释没有换行,否则 LiveIce 将无法工作 :)
# liveice configuration file # Automatically generated SERVER megajukebox # Your server name * MUST BE THE NAME THE SERVER RESOLVES TO * PORT 8000 # The port Icecast is running on NAME Megajukebox # Information regarding the name of your server which is sent to MP3 players, and # to directory servers. # Examples 'Sarah FM' or 'ThisTown: Loud and Heavy Jazz - Internet Radio 24/7' GENRE Live # Information regarding the genre. Examples 'Talk' or 'Dance' DESCRIPTION # Information regarding the station. Example 'The best for reggae in the North' URL http://megajukebox:8000 # The URL and port of the server. PUBLIC 0 # Set this to 1 if you want Icecast to announce your station and list it's details # on a directory server, otherwise leave 0 XAUDIOCAST_LOGIN # can be either ICY_LOGIN or X_AUDIOCAST_LOGIN. X_AUDIOCAST is better. MOUNTPOINT /techno # Sets the mountpoint name of the stream for Icecast. Only used if X_AUDIOCAST is used # otherwise defaults to icy_0 PASSWORD hackme # Icecast's admin password SAMPLE_RATE 44100 # The sample rate of the stream STEREO # Can be MONO or STEREO NO_SOUNDCARD # See below HALF_DUPLEX # Sets the soundcard duplex mode. Can be HALF_DUPLEX or FULL_DUPLEX USE_GOGO # Sets the encoder to use. Check the README for the list BITRATE 128000 # Sets the bit rate of the stream (see below) VBR_QUALITY 1 # Sets the variable bit rate quality. MIXER # See below PLAYLIST /megajukebox/playlist # Location of the playlist (see details on the find command later in this chapter) TRACK_LOGFILE track.log # Filename and location to dump list of MP3's streamed
[dj@megajukebox liveice]$ ./liveice /megajukebox/playlist 1 opening connection to megajukebox 8000 Attempting to Contact Server connection successful: forking process opening pipe!... writing password Setting up Interface Soundcard Reopened For Encoding Input Format: 16Bit 44100Hz Stereo Output Format: 256000 Bps Mpeg Audio IceCast Server: megajukebox:8000 Mountpoint: /techno Name: megajukebox - this and that radio - broadcasting 24/7 Genre: Techno Url: http://megajukebox.com Description: a load of digital noise -> but i know you like it :) Press '+' to Finish adding /megajukebox/demotunes/track_1.mp3 adding /megajukebox/demotunes/track_2.mp3 adding /megajukebox/demotunes/track_3.mp3 adding /megajukebox/demotunes/track_4.mp3 /megajukebox/demotunes/track_4.mp3 Adding New Channel 1 Adding New Channel 2 Channel 1 selecting /megajukebox/demotunes/track_1.mp3 Channel 2 selecting /megajukebox/demotunes/track_1.mp3 Playing track_1.mp3 searching for Id3v2 searching for Id3v1 copying the data fixing the nulls adding the url closing input file Using log track.log
最后一行是峰值表。
这些是混音器模式的键盘控制
Action Channel 1 Key Channel 2 Key ~~~~~~ ~~~~~~~~~~~~~ ~~~~~~~~~~~~~ Select next track on channel 1 a Select prev track on channel q z Start/Stop channel 2 s Reset channel w x Increase volume on channel 3 d Decrease volume on channel e c Increase speed on channel 4 f Decrease speed on channel r v Sticky mode On/Random/Off 5 g Preview channel t b Random Track u m
上面的 liveice.cfg 适用于混音器模式。要在音频模式下使用 LiveIce,请将与 MIXER 相关的行更改为 NOMIXER,并将 NO_SOUNDCARD 设置为 SOUNDCARD,然后重新启动 LiveIce。
忘记设置正确的选项会导致一些有趣的警告 ;)
946:Error: Line In mode *and* no soundcard??????? Eeejit!
一旦您正确设置了所有内容并插入了外部源,您应该就可以进行流式传输了 =:)
[dj@megajukebox liveice]$ ./liveice /megajukebox/playlist 0 Initialising Soundcard 16Bit 22050Hz Stereo Full Duplex opening connection to megajukebox 8000 Attempting to Contact Server connection successful: forking process opening pipe!... writing password Setting up Interface Soundcard Reopened For Encoding Input Format: 16Bit 22050Hz Stereo Output Format: 32000 Bps Mpeg Audio IceCast Server: megajukebox:8000 Mountpoint: /daves_band_live_at_the_club Name: megajukebox - Dave and the Dynamite - Live at the Roxy Genre: Live/Rock Url: http://megajukebox Description: megajukebox::Louder than a frog in a trashcan..... and almost as musical Press '+' to Finish Lvl: L: 8704 R: 11776
最后一行是信号电平表,如果输入信号太高,您将收到 *clip* 警告。 如果是这样,请调低输入源的增益。
眼尖的人可能已经注意到,在 liveice.cfg 中,第一行注释指出该文件是自动生成的。如果您正在使用基于 TK 的 GUI liveiceconfigure.tk 并且您进行了手动更改,则在保存时将会丢失这些更改。 要么使用 GUI,要么学习 vi/emacs :)
解压捆绑包后,cd 到目录,然后阅读 README :)
Fluid 有三种基本的操作模式:transmit(传输)、relay(中继)和 forward(转发)。 我将只关注 transmit 模式。
与 transmit 关联的配置文件位于 config/MP3TX.cfg 中。 要测试服务器,请运行以下命令,此时默认配置设置应该可以正常工作
java Fluid TX
自然而然地,您首先需要安装某种形式的 Java。 您可以使用从 http://www.blackdown.org 获取的 Blackdown 端口的 JDK,或者如果您使用的是 Redhat,则可以使用 Kaffe。
Fluid 附带了一些示例 MP3 文件,因此如果一切正常,您应该会看到类似于以下内容(在此示例中,我使用 Kaffe 启动了服务器,您可能必须使用 java 启动它)
[dj@megajukebox Fluid-Beta2J]$ kaffe Fluid tx ------- Fluid Streaming Server Beta 2 ------- This program is ShareWare(tm) and it will not be crippled in any way because of it. However if you do like the program and will use it commercial purposes, we ask of you to contact us at the address below for pricing info: Eldean AB E-mail: Sjoangsvagen 7 fluid@subside.com S-192 72 Sollentuna SWEDEN Fluid is Copyright Subside (C) 1998 written by Lars Samuelsson http://www.subside.com --------------------------------------------- * Transmission mode * Reading config from: config/MP3TX.cfg Reading playlist: playlist.m3u Server started on port: 2711 Accepting administrator login on port: 2710 P| Dr. Nick - Hello Everybody
您需要编译要流式传输的 MP3 的播放列表。 这将是一个静态列表,用户将无法更改此列表或提出请求。 此播放列表名为 playlist.m3u,默认情况下位于根目录中。
要编译特定目录(或磁盘)中所有 MP3 的播放列表,请使用以下命令
find [MP3 directory] -name "*.mp3" -print > playlist.m3u
可以通过 telnet 到服务器的管理端口来远程管理服务器,默认情况下端口为 2710,如下所示
[dj@megajukebox Fluid-Beta2J]$ telnet localhost 2710 Trying 127.0.0.1..megajukebox Connected to localhost.localdomain. Escape character is '^]'. jaguar You are connected to the -Fluid- Streaming Server Type "help" for a command reference help The following commands are available: help conn curr exit curr Information about the currently broadcasted song: Title: Beer Talk Artist: Homer Simpson Album: The Simpsons Year: 1996 Comment: Borrowed this as an example Genre: Comedy
[dj@megajukebox config]$ cat MP3TX.cfg 2711 2710 5 4096 32 1000 jaguar playlist.m3u current.txt # --- The lines are --- # 1. PORT number (the server will use) # 2. PORT number (for maintaining the server remotely) # 3. Maximum number of connections (the server will accept) # 4 Packetsize when reading/sending (in bytes) # 5. Bitrate of the mp3s in kbit/s (all mp3s must have same bitrate) # 6. Delay between songs (in milliseconds) # 7. Password for remote administration # 8. Playlist name (list in .m3u format) # 9. Name of the file to write song info to (from ID3-tag)
Fluid 已更新,并以 GPL 许可证发布(做得好,Lars!)
以下是主要区别
Litestream 在操作上与 Icecast 类似。 该系统由 streamer(流媒体服务器)和 source(源)组成。
要启动 streamer,您需要发出以下格式的命令
[dj@megajukebox]$ litestream <source port> <stream host> <stream port> <max listeners> <log ident> [<yp host> <yp port>]
选项如下
source port 是您连接 “音频” 源的端口。
stream host 这是您的服务器的 IP 或 FQDN(使用 hostname 命令查找域名,或使用 cat /etc/hosts 查找 IP 地址)。
stream port 这是客户端连接到的端口号。
max listeners 这是可以连接到您服务器的客户端数量。
log ident 日志消息被写入 /var/log/messages。 <log ident> 是一个用于标识 Litestream 服务器的 ident 字符串,例如。
如果您使用 ident 字符串 “Litestream”,则 /var/log/messages 中的服务器启动消息将类似于
Sep 18 19:32:20 linux Litestream[1901]: stream.c:555: main: 'server started'
<yp host & yp port> 这 2 个选项指定 yp 服务器的主机和端口,用于向 mp3 目录服务器公告您的服务器。
这是一个例子
[dj@megajukebox]$ litestream 5000 megajukebox 5555 1000 LitestreamServer
好了,这就是服务器系统。 启动后,它会在那里等待输入连接,这可以通过 source 命令完成。
格式如下
source <ip or hostname> <port> <name> <genre> <url> <irc> <icq> <aim> <public? (0, 1)> <reported bitrate (16, 18, 56, 128, etc.)> <playlist.txt> <log ident>
以下是 source 的选项列表。
ip or hostname 是运行 Litestream Server 的计算机的主机名或 IP 地址。
port 是 Litestream Server 等待流式传输源的端口。
name 是您的流的名称。
genre 是您的流的类型。
url 是您的流的网页 URL。
irc 是您的流的 IRC 频道。
icq 是您的 ICQ ID。
aim 是您的 AIM ID。
public 为 0 或 1。 0 表示私有,1 表示公共。
reported bitrate 是将报告给 YP 服务器的流比特率。 这不一定反映您流的实际比特率。
playlist.txt 是包含您的播放列表的文件的名称。
log ident 是 syslog 标识符,它将添加到 Litestream Streaming Source 生成的每条日志消息的前面。
这是一个与之前的 Litestream 命令匹配的示例
[dj@megajukebox]$ source megakukebox 5000 'Megajukebox The best jukebox ever' Various http://www.megajukebox.com \#megajukebox 0 N/A 1 128 /jukebox/playlist LitestreamSource
Apache::MP3 模块允许 Apache WebServer 流式传输 MP3。 它不提供与 Fluid、Litestream 和 Icecast 相同级别的功能。
该模块依赖于 MP3::Info 和 mod_perl,这两者都可以在 CPAN 上找到。
下载所需文件后,阅读 README 将有所帮助!
首先制作模块,然后对 Apache 的配置文件进行配置更改(您的更改可以在 httpd.conf 或 srm.conf 中进行)。
您还需要为图标创建目录,并为 MP3 创建目录层次结构。
README 的第 6 节详细介绍了 Perl 配置文件的编辑(或创建)。
这是为了预加载 MP3::Info 模块,如果没有它,可能会导致 Apache 崩溃。
在 httpd.conf 中创建如下条目
Perlrequire /etc/httpd/conf/startup.perl
更改 /etc/httpd/conf 引用以指向您的系统上 Apache 配置文件的位置。
现在在上面指定的位置创建文件 startup.perl。 最低限度,您应该具有以下内容(再次调整 perl 的路径以适合您的系统)。
[dj@megajukebox conf]$ cat /etc/httpd/conf/startup.perl #!/usr/bin/perl use MP3::Info();
然后重新启动 Apache 并将 Web 浏览器指向您的一个新 MP3 目录 :)
Apache::MP3 上有更多文档可用,从命令行运行以下命令
[dj@megajukebox conf]$ perldoc Apache::MP3
许多公司和机构现在使用防火墙来阻止用户连接到远程服务器上的某些端口。
绕过此问题的一种方法是使用端口 80 运行您的 MP3 服务器。 您将无法在同一 URL 或 IP 地址上运行 Web 服务器。
在 “绕过防火墙” 模式下运行 Icecast 时,您需要使用将端口设置为端口 80 的选项启动 shout,如下所示
[dj@megajukebox bin]$ ./shout megajukebox -e 80 -P hackme -p ../playlist
如果 MP3 服务器的比特率设置得太高,流式传输音频可能会消耗大量带宽。
考虑以下场景。 T1 链路的容量约为 1.55 Mb/秒。 如果您以 128K/Bps 立体声流式传输 MP3,则每个连接的播放器将使用 256K/Bps,因此在任何时候只有 6 个用户可以连接到您的 MP3 服务器而不会出现问题。 并且在 256K/Bps 的速率下,您将无法获得太多调制解调器用户连接!
因此,您必须决定将流速率设置为多少,不仅要考虑服务器的互联网连接额定值,还要考虑用户的连接速率。 24K/Bps 立体声将提供合理的质量信号,56K 调制解调器用户将能够连接到该信号,并且对于同一 T1 线路,将允许大约 32 个同时连接。
如果您的服务器在 Intranet 上运行,则仍然必须考虑带宽问题,特别是当您的网络运行速度为 10M/秒时。
但是请告知您的 ISP 或系统管理员您将要进行流式传输,否则您可能会感到震惊。 一些 ISP 会向您收取超过一定限制的带宽费用,而系统管理员想知道为什么他们的网络现在运行缓慢 :)
我认为可以合理地假设唱片公司不会喜欢您在未经他们许可或支付某种费用的情况下流式传输材料! 那么您可以流式传输什么?
这是一个您需要注意法律后果的领域,因为承担责任的将是您。
以下是两个链接,一个是指电子前沿基金会,他们是倡导解除围绕该技术的限制的组织。 另一个链接是指美国唱片业协会,该协会旨在保护艺术家免受盗版侵害的权利。
我强烈建议访问这两个网站,以及任何其他与您实际所在地相关的网站。
http://www.riaa.com/weblic/weblic.htm