学海荡舟手机网
导航

主页 > 电子设备技术 > 电器电路基础 > > 详细内容

怎么用Linux建立自己的Mp3广播站

 概述:本文将介绍用linux下的开放源码工具ecast和ices创建广播的方法。  

  原理:

  icecast是一个基于Mpeg III技术的Internet广播系统,同shoutcast等商业软件相比具有以下特点:

  1.Icecast是一个纯粹的OpenSource软件;  

  2. 不需要运行自己的目录服务器;

  3.占用更少的系统资源;

  我们可以在服务器上运行自己的流服务器——icecast,使用ices提供流源,客户端则可

  以使用最常用的winamp。  

  试验环境:

  服务器平台:RedHat 7.0

  流服务器:icecast

  流源:ices

  mp3工具:lame

  步骤:

  1.获得相关软件

  流服务器icecast://www.icecast.org/releases/icecast-1.3.10-1.i386.rpm

  流源工具ices://www.icecast.org/releases/ices-0.0.1.beta5.tar.gz

  编码工具lame://home.elka.pw.edu.pl/~dmierzej/linux/lame/lame-3.87beta-1.i386.rpm

  lame库://home.elka.pw.edu.pl/~dmierzej/linux/lame/lame-devel-3.87beta-1.i386.rpm

   说明:

  A.通常可以使用liveice、shout等软件为流服务器提供流(即作为流源),但是我在使

  用的过程中发现ices要稳定一些,虽然还是个beta版的。

  B.通常你的每个mp3文件不可能具有同样属性,此时广播过程就会出现一些怪现象,

  比如声音断断续续、有噪音等等,所以我们必须使用mp3编码工具lame重新对其进行编码,来生成属性一致的mp3文件。 

  2.安装icecase

  使用以下命令安装icecast:

  rpm –ivh icecast-1.3.10-1.i386.rpm  

  3.安装ices

  使用以下命令安装ices:

  # tar xvzf ices-0.0.1.beta5.tar.gz

  会在当前目录下生成ices-0.0.1.beta5目录,用cd命令进入该目录

  # cd ices-0.0.1.beta5

  然后执行:

  # ./configure

  # make

  # make install

  编译好的文件缺省被安装在/usr/al/icecast目录下  

  4.安装lame

  执行以下命令来安装lame mp3编码工具,该工具用来重新对mp3文件进行编码,以产生属性一致的mp3文件。

  rpm –ivh lame-3.87beta-1.i386.rpm

  rpm –ivh lame-devel-3.87beta-1.i386.rpm

  

 5.配置icecast

  icecast的主要配置文件是/etc/icecast.conf,有很多配置选项,但是其中的大多数只要采用缺省配置即可,部分选项意义说明如下:  

  Port:定义icecast服务绑定的端口,只设置一个即可,通常使用8000端口。  

  encoder_password:流源连接时的密码,使用ices为icecast提供流时ices必须提供提供这个密码,出于安全性考虑可以设置一个较为复杂的密码。  

  admin_password:可以通过telnet登录icecast进行远程管理,这个密码就是登录icecast时必须输入的密码。  

  oper_password:通过telnet登录icecast执行限制性命令时的密码。  

  max_clients:同一时间内允许连接到流服务器的最大客户数目。  

  max_sources:允许同时广播的最大流源数目,流源和流服务器可以位于不同的机器上,

  并且可以将多个流源传输到同一个流服务器进行广播。  

  max_admins:可以同时登录icecast进行远程管理的连接数目。

  Logfile:设置日志文件的位置。  

  Hostname:设置icecast绑定的ip地址,缺省绑定到所有ip地址。  

  server_name:指定icecast服务器的主机名或者是ip地址。  

  client_timeout:设置当无流源时,服务器断开已连接客户的超时时间。  

  stats_log:设置记录icecast统计数据的日志文件。  

  stats_time:设置stats_log日志文件的更新。  

  max_clients_per_source:设置可以同时连接到同一流源的最大客户数目。  

  reverse_lookups:设置是否对可以连接进行反向DNS解析,为0时禁止反向DNS解析,

  为1时启用反向dns解析。

  Location:设置icecast服务器的地理位置,设置与否并不重要。  

  rp_email:设置icecast服务器管理员的邮件地址。  

  Throttle:icecast服务器可以使用的带宽阀值,如果达到这一阀值,新的客户连接将被拒

  绝,单位是兆/秒。  

  Logfiebuglevel:定义日志的信息详细程度。  

  server_url:定义icecast服务器的RUL

  This should be set to a URL describing this icecast server.  

  以下是我的配置文件,仅供参考:

  #icecast.conf

  location Yuxi Yunnan China

  rp_email bye2000@yxtc.edu.cn

  server_url //www.yxtc.edu.cn/

  max_clients 900

  max_clients_per_source 900

  max_sources 10

  max_admins 5

  throttle 10.0

  mount_fallback 1

  encoder_password secret

  admin_password secret

  oper_password secret

  port 8000

  force_servername 0

  logfile icecast.log

  aessfile access.log

  usagefile usage.log

  logfiledebuglevel 0

  consebuglevel 0

  reverse_lookups 0

  console_mode 0

  client_timeout 30

  kick_clients 0

  staticdir /usr/share/icecast/static

  templatedir /usr/share/icecast/templates

  logdir /var/log/icecast

  stats_log stats.log

  statshtml_log stats.html

  stats_time 60

  kick_relays 10

  transparent_proxy 0

  acl_policy 1  

  6.启动icecast服务

  执行以下脚本启动icecast服务:

  # /etc/rc.d/init.d/icecast start  

  7.对所有mp3文件进行重新编码

  采用lame对mp3文件进行重新编码,从而生成属性一致的mp3文件。

  这要用到Lame命令的以下参数:

  --mp3input:输入文件为mp3文件

  -m s:指定所有帧均为

  -b 56:指定新生成mp3文件的波特率,这里指定为56 kbps,单位是kbps

  --resample 24:指定新生成mp3文件的采样,这里指定为24 K,单位是KHZ  

  下面是一个lame的使用实例:

  lame --mp3input -m s -b 56 --resample 24 old.mp3 new.mp3

  
 

 

  8生成播放列表

  可以用以下文件生成播放列表:

  # find / -name ‘*.mp3’ > play_list_file

  将其中的play_list_file改成你的播放列表文件名。

  以下是一个播放列表文件示例:

  #play_list example

  /data/mp3/PowerStation/byemylove/1.mp3

  /data/mp3/PowerStation/byemylove/10.mp3

  /data/mp3/PowerStation/byemylove/11.mp3

  /data/mp3/PowerStation/byemylove/2.mp3

  /data/mp3/PowerStation/byemylove/3.mp3

  /data/mp3/PowerStation/byemylove/4.mp3

  /data/mp3/PowerStation/byemylove/5.mp3

  /data/mp3/PowerStation/byemylove/6.mp3

  可以看出,只要包含mp3文件的完整路径和文件名即可。  

  9发布流

  ices可以使用基于xml的配置文件,也可以使用带选项的命令,这里我们使用后者,常用的命令选项有:

  -B:指定ices以后台程序方式运行

  -b:指定使用的波特率

  -d:对流的描述

  -n:设置广播站的名称

  -g:广播音乐的类型

  -h:流服务器ip地址

  -p:流服务器监听端口

  -P:连接流服务器的密码

  -r:设置随机播放歌曲

  -S:指定播放列表类型,通常使用builtin

  -U:指定流服务器的URL

  -F:指定播放列表文件  

  我的例子:

  /usr/local/icecast/bin/ices –B –b 56 –d MUSIC –n “TOM Radio” –g music –h localhost –p 8000 –P secrue –r –S builtin –U //www.yxtc.edu.cn -F /etc/icecast/list  

  10. 接收广播  

  可以用类似以下的方法让用户接收广播:

  建立一个扩展名为m3u的文件,比如我的文件是tom.m3u,该文件包含以下内容:

  //www.yxtc.edu.cn:8000/

  然后在主页上建立该文件的超链接,这样客户一旦点击该连接,就会启动winamp、realplay等mp3播放器接收广播了。

  推荐使用winamp接收广播。  

  好了,大功告成了,坐下来泡杯咖啡慢慢欣赏你的mp3广播吧。

  


 

 

 11. 补充说明:

  我写了一个perl脚本,该脚本会自动搜索系统中所有的mp3文件,然后将非56K波特率和24KHZ采样频率的mp3文件用lame转换成56K波特率和24KHZ采样频率的mp3文件,完成转换后自动生成播放列表。

  使用方法:

  ./list_gen list_file

  必须先用touch 命令建立该列表文件

  该脚本要求你的系统安装lame工具。

  该脚本源码如下,你也可以从这里下载:  

  #!/usr/bin/perl

  `rm -f /tmp/temp.mp3`;

  if ( ! $ARGV[0] ) {

   print "   

  Usage: ./list_gen list_file_name   

  ";

   print "You must create the file first!   

  ";

   exit(0);

  }

  $files = `find / -name ’*.mp3’`;

  @file = split(/   

  +/,$files);

  $num = @file;

  for ($i=0; $i<=$num-1; $i++) {

   $file_info=`file $file[$i]`;

   if ( $file_info=~/MP3/) {

   @file_type=split(/s+/,$file_info);

   if ( $file_type[2]=~/56/ ){

   }else{

   `lame --mp3input -m s -b 56 --resample 24 $file[$i] /tmp/temp.mp3`;

   `mv -f /tmp/temp.mp3 $file[$i]`;

   }

   push (@list,"$file[$i]   

  ");

   }

  }

  

  if ( -e $ARGV[0] ) {

   $num = @list;

   open(LIST,">$ARGV[0]");

   for ( $i=0; $i<=$num; $i++ ) {

  print LIST "$list[$i]";

   }

   close(LIST);

   print "

  play list create OK, good luck!!!   

  ";

  }else{

   print "

  I ’t find file you specified!

  ";

   print "You must create play list file first!   

  ";  

  }


相关文章