Build your own mp3 broadcast station in linux

Source: Internet
Author: User
Tags builtin touch command icecast icecast server perl script reverse dns

Overview:This article describes how to create an MP3 broadcast using the Open Source Tool Icecast and ices in Linux.

Principle:

Icecast is an Internet broadcast system based on mpeg iii technology. Compared with commercial software such as ShoutCast, Icecast has the following features:

  1. Icecast is a pure OpenSource software;
  2. You do not need to run your own Directory Server;
  3. Occupy less system resources;

We can run our own streaming server -- Icecast on the server and use ICES to provide the container. The client can use the most commonly used Winamp.

Test environment:

Server Platform: RedHat 7.0

Streaming Server: Icecast

Usage: ices

MP3 encoding tool: lame

Steps:

1. Obtain related software

Stream server Icecast: http://www.icecast.org/releases/icecast-1.3.10-1.i386.rpm

Utility tool ICES: http://www.icecast.org/releases/ices-0.0.1.beta5.tar.gz

Coding tool lame: http://home.elka.pw.edu.pl /~ Dmierzej/Linux/lame/lame-3.87beta-1.i386.rpm

Lame: http://home.elka.pw.edu.pl /~ Dmierzej/Linux/lame/lame-devel-3.87beta-1.i386.rpm

Note:

A. generally, liveice, shout, and other software can be used to provide a stream (that is, serving as a stream) for the stream server. However, I found that ICES is stable during use, although it is still a beta version.

B. generally, each MP3 file cannot have the same attributes. At this time, some strange phenomena may occur during the broadcast process, such as intermittent and noisy sounds, therefore, we must use the MP3 encoding tool lame to encode it again to generate MP3 files with consistent attributes.

2. Install icecase

Run the following command to install Icecast:

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

3. Install ices

Run the following command to install ICES:

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

The ices-0.0.1.beta5 directory is generated under the current directory, and the CD command is used to enter the Directory

  # cd ices-0.0.1.beta5

Then execute:

  # ./configure  # make  # make install

The compiled files are installed in the/usr/local/Icecast directory by default.

4. Install lame

Run the following command to install the lame MP3 encoding tool. This tool is used to re-encode MP3 files to generate MP3 files with consistent attributes.

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

5. Configure icecast

The main configuration file of Icecast is/etc/Icecast. conf, which has many configuration options, but most of them only need to adopt the default configuration. Some options are described as follows:

Port: defines the port bound to the Icecast service. Only one port can be set. Port 8000 is usually used.

Encoder_password: password used to connect to the kernel. ICES must provide this password when providing a stream for Icecast. For security reasons, you can set a complicated password.

Admin_password: You can use Telnet to log on to Icecast for remote management. This password is the one you must enter when logging on to Icecast.

Oper_password: password used by Telnet to log on to Icecast to execute the restricted command.

Max_clients: Maximum number of customers allowed to connect to the streaming server within the same time.

Max_sources: Maximum number of workers that can be broadcast at the same time. The stream source and stream server can be located on different machines and multiple workers can be transmitted to the same stream server for broadcast.

Max_admins: Number of connections that can be remotely managed by logging on to Icecast at the same time.

Logfile: Set the location of the log file.

Hostname: Set the IP address bound to Icecast. It is bound to all IP addresses by default.

SERVER_NAME: Specify the host name or IP address of the Icecast Server.

Client_timeout: Set the timeout time when the server disconnects the connected customer when no timeout occurs.

Stats_log: Set the log file that records icecast statistics.

Stats_time: Set the update period of the stats_log file.

Max_clients_per_source: sets the maximum number of customers that can be connected to the same region at the same time.

Reverse_lookups: sets whether to reverse DNS resolution can be performed on connections. If the value is 0, reverse DNS resolution is disabled. If the value is 1, reverse dns resolution is enabled.

Location: Set the geographic Location of the icecast Server. setting or not is not important.

Rp_email: Set the email address of the icecast Server administrator.

Throttle: The bandwidth threshold that can be used by the icecast Server. If this threshold is reached, new customer connections will be rejected, in megabytes/s.

Logfiledebuglevel: defines the log details.

Server_url: defines the RUL of the icecast Server

The following are my configuration files for your reference only:

  #icecast.conf  location Yuxi Yunnan China  rp_email bye2000@yxtc.edu.cn  server_url http://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  accessfile access.log  usagefile usage.log  logfiledebuglevel 0  consoledebuglevel 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. Start the icecast Service

Run the following script to start the icecast service:

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

7. recode all mp3 files

Use lame to re-encode mp3 files to generate mp3 files with consistent attributes.

The following parameters of the Lame command are used:

-- Mp3input: the input file is an mp3 file.

-M s: specifies that all frames are stereo.

-B 56: Specifies the baud rate of the newly generated mp3 file, which is 56 kbps in kbps.

-- Resample 24: Specifies the sampling frequency of the newly generated mp3 file. The value is 24 KHZ, and the Unit is KHZ.

The following is an example of lame usage:

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

8. Generate a playlist

You can use the following file to generate a playlist:

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

Change play_list_file to the name of your playlist file.

The following is an example of a playlist 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

As you can see, you only need to include the complete path and file name of the mp3 file.

9. Publish stream

Ices can use xml-based configuration files or command with options. Here we use the latter. Common command options include:

-B: Specify how ices will run in the future.

-B: Specifies the baud rate.

-D: stream description

-N: Set the name of the broadcast station.

-G: the type of broadcast music.

-H: Streaming Server IP Address

-P: Listener port of the stream server

-P: the password used to connect to the streaming server.

-R: Set random playback of songs

-S: specifies the type of the playlist, usually using builtin

-U: Specifies the URL of the streaming server.

-F: Specifies the playlist file.

My example:

  /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  http://www.yxtc.edu.cn -F /etc/icecast/list

10. Receive Broadcast

Users can receive broadcasts in a way similar to the following:

Create a file with the extension m3u. For example, if my file is tom. m3u, the file contains the following content:

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

Then, create a hyperlink to the file on the homepage. Once you click the connection, mp3 players such as winamp and realplay will be started to receive broadcasts.

We recommend that you use winamp to receive broadcasts.

Well, it's done. Sit down and make a cup of coffee and enjoy your mp3 broadcast.

11. Additional instructions:

I wrote a perl script that automatically searches all mp3 files in the system, then, mp3 files with non-56 K Baud Rate and 24 KHz sampling frequency are converted into mp3 files with a 56 K Baud rate and a 24 KHz sampling frequency using lame. After the conversion, a playback list is automatically generated.

Usage:

  ./list_gen  list_file

You must use the touch command to create the list file.

This script requires your system to install the lame tool.

The script source code is as follows. You can also download it from here:

  #!/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 can't find file you specified! ";      print "You must create play list file first! ";        }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.