Icecast
Icecast 是一个用于在网络上流式传输媒体(如音频和视频)的程序。不同类型的客户端连接到 IceCast 服务器,以提供“挂载点”、控制服务器或收听正在播放的音频。
Icecast 支持同时流式传输多个音频流 - 每个流都有一个“挂载点”,客户端可以使用网络 URI(例如 https://127.0.0.1:8000/example.ogg.m3u
)访问(这指的是名为“example”的挂载点)。
安装
或者,您可以构建并安装 icecast-khAUR 软件包。Icecast-kh (Karl Heyes) 在官方版本的基础上进行了扩展,增加了一些功能,这些功能可能会(如果发现运行良好)合并到下一个官方版本中。
配置
所有配置都在 /etc/icecast.xml
中完成。
icecast
之前,请务必更改 <authentication>
部分中的默认密码!默认情况下,icecast 监听端口 8000
。它可以监听多个端口 - 可以通过修改一个或多个 <listen-socket>
部分来更改此行为。
默认情况下,Icecast 绑定到所有接口(即 0.0.0.0
)。要更改此行为,请修改各自 <listen-socket>
部分下的 <bind-address>
部分。
要为所有未指定其类型的挂载点(例如 <mount type="normal">
)设置默认值,可以修改 <mount type="default">
部分
/etc/icecast.xml
<mount type="default"> <public>0</public> <intro>/stream.m3u</intro> <max-listener-duration>3600</max-listener-duration> <authentication type="url"> <option name="mount_add" value="http://auth.example.org/stream_start.php"/> </authentication> <http-headers> <header name="foo" value="bar" /> </http-headers> </mount>
icecast.service
以 icecast 用户身份运行。不需要也不建议在 <security>
下的 <changeowner>
部分中设置要更改的用户和组。运行
要验证 icecast 是否正在运行,请访问 https://127.0.0.1:8000/ 或检查 icecast.service
的 状态。
流媒体
一些程序能够基于 配置的 <authentication>
部分中设置的 <source-password>
流式传输到 icecast。
icecast.service
必须在流式传输到它之前启动。MPD
配置 MPD(作为 系统 或 用户 服务)作为 icecast 源
mpd.conf
audio_output { type "shout" encoding "ogg" name "my cool stream" host "localhost" port "8000" mount "/example.ogg" user "source" password "<source-password>" # Set either quality or bit rate # quality "5.0" bitrate "64" format "44100:16:1" # Optional Parameters # description "here is my long description" # genre "jazz" } # Need this so that mpd still works if icecast is not running audio_output { type "null" name "fake out" }
启动 mpd.service
。
icecast Web 界面现在应该列出这个新流,并且播放列表应该可以作为 https://127.0.0.1:8000/example.ogg.m3u 访问
ezstream
ezstreamAUR 是 icecast 的原生源客户端。它像 icecast 一样使用 XML 文件进行配置
在 /usr/share/examples/ezstream/ 中可以找到几个示例。它支持 mp3、Ogg Vorbis、Ogg Theora,对于流式传输视频,可以使用 ffmpeg2theora 重新编码为 Ogg Theora。
配置完成后,可以通过以下方式启动流:
$ ezstream -c /path/to/file.xml
可以通过创建 m3u 播放列表并在配置文件中的 <intakes>
下定义它来流式传输多个媒体
<intakes> <intake> <type>playlist</type> <filename>playlist.m3u</filename> </intake> </intakes>
XMMS2
xmms2 是一个极简音乐播放器,可以通过多个客户端进行控制,与 MPD 相比,设置起来相当简单,并且可以像 ezstream 那样即时添加媒体进行流式传输。
可以使用以下命令显示 Icecast 配置:
$ xmms2 server config | grep ices
ices.encodingmaxbr = -1 ices.encodingminbr = -1 ices.encodingnombr = 96000 ices.host = localhost ices.mount = /stream.ogg ices.password = hackme ices.port = 8000 ices.public = ices.streamdescription = ices.streamgenre = ices.streamname = ices.streamurl = ices.user = source
可以按如下方式更改这些配置:
$ xmms2 server config ices.password my_password $ xmms2 server config ices.port 5080 $ xmms2 server config ices.public 1
将输出更改为 ices,以便 XMMS2 可以将流挂载到 icecast 服务器上。
$ xmms2 server config output.plugin ices
启动后,流应正常工作,并且可以使用“add”命令添加文件。
或者,可以使用 lxmusic 控制 XMMS2,它提供了一个简单的 GUI。
VLC
vlc 是一个功能齐全的媒体播放器和转码器,内置支持 Icecast 流媒体。它可以通过 GUI 或命令行控制,并且可以充当媒体文件或从 JACK 输出端口和其他来源捕获的实时音频的 Icecast 源。例如,以下命令将 VLC 连接到它找到的第一个 JACK 音频输出端口,将音频编码为 Ogg Vorbis,并将其流式传输到 https://127.0.0.1:8000/stream.ogg
的 Icecast 挂载点
$ cvlc 'jack://channels=2:ports=.*' ':sout=#transcode{vcodec=none,acodec=vorb,ab=192,channels=2,samplerate=44100,scodec=none}:std{access=shout,mux=ogg,dst=//source:hackme@localhost:8000/stream.ogg}' :no-sout-all :sout-keep
或者,VLC 提供了一个引导式 GUI 来流式传输到 Icecast 服务器。打开任何媒体源时,选择流,然后添加 Icecast 作为目标。系统将提示您输入网络地址、端口、挂载点和登录名:密码。对于后者,请使用 source:<password>
格式。在下一个屏幕上选择所需的转码选项,即可开始。
播放
当访问 https://127.0.0.1:8000 时,可以通过 Web 浏览器 收听流。
此外,还有一些客户端可以直接使用提供的播放列表文件(例如 https://127.0.0.1:8000/example.ogg.m3u)
MPD
Icecast 流可以使用 MPD 播放。
使用 MPD 客户端(例如 mpc)将 icecast 播放列表文件的 URL 添加到(本地)MPD 实例的播放列表中
$ mpc add https://127.0.0.1:8000/example.ogg.m3u
添加的项目的行为类似于 MPD 播放列表中的任何其他曲目。
MPlayer
启动程序并为其提供 icecast 播放列表
$ mplayer -playlist https://127.0.0.1:8000/example.ogg.m3u
Mpv
启动程序并将它指向 icecast 播放列表
$ mpv https://127.0.0.1:8000/example.ogg.m3u
Sonata
- 安装 sonata-gitAUR 软件包。
- 启动它,您应该会看到 Sonata 的首选项设置。
- 将“名称”设置为您的服务器的名称。
- 将“主机”设置为您的服务器的 IP 地址。
- 将“端口”设置为“6600”。
- 单击“+”并重复之前的步骤,但这次是关于您的本地计算机(即其名称和 IP)。
- 右键单击->“连接”,然后选择您的服务器。然后单击“库”选项卡,如果一切顺利,您应该会看到服务器上的所有音乐选择。找到一个文件夹,右键单击并单击“添加”。单击“当前”选项卡将显示您当前的播放列表,其中应包含您刚从库中选择的任何文件夹的内容。双击一首歌曲。您应该会看到文本变为粗体,并且进度条出现,就像正在播放一样,但您不会听到任何声音。不要害怕。
- 右键单击->“连接”,然后选择您的本地计算机。然后单击“流”选项卡。右键单击并单击“新建”。将“流名称”设置为服务器 /etc/mpd.conf 文件的 audio_output { } 部分中的名称,并将 URL 设置为 IP.of.server:8000/example.ogg.m3u。双击此流。
- 单击“当前”选项卡,您将看到流的 URL 作为您的唯一项目。双击它,延迟片刻后,您应该会听到您在服务器上选择的歌曲。
VLC
除了充当 Icecast 源之外,vlc 还可以播放来自 Icecast 和其他网络音频源的流。选择打开网络流...并在出现提示时提供 URL。
技巧与窍门
在 chroot 环境中运行 Icecast
更改 /etc/icecast.xml
中的以下设置
<chroot>1</chroot>
编辑 icecast.service
的 [Service]
部分
WorkingDirectory=/usr/share/icecast
现在更改 /etc/icecast.xml
中的这些条目
<logdir>./log</logdir> <webroot>./web</webroot> <adminroot>./admin</adminroot> <pidfile>./icecast.pid</pidfile>
在 /usr/share/icecast
下创建一个日志目录并设置权限
# cd /usr/share/icecast # mkdir log # cd log # touch access.log playlist.log error.log # cd .. # chown -R icecast:icecast log/
本地用户
请注意,如果您在本地用户(即不使用 /etc/icecast.xml 的用户)下运行 icecast,那么您需要从 /usr/share 复制 icecast Web XML 文件,否则您将收到关于 XSLT 的错误,并且 Web 界面将无法工作。
$ cp -R /usr/share/icecast/web ~/icecast/
另外,请确保注释掉 icecast 配置文件中的 <changeowner>
部分,因为更改进程的所有者需要 root 权限。
参见
- 官方网站 - Icecast 官方网站
- 客户端列表 - 与 Icecast 兼容的上游客户端列表
- MPD Wiki:配置 - MPD Wiki 中的配置页面
- ffmpeg2theora 实时流媒体指南 - 关于使用 icecast、oggfwd 和 ffmpeg2theora 进行实时流媒体的指南
- Ezstream - Ezstream 网站