Google

mod_mp3 - FAQ for the Apache mod_mp3 streaming module



NAME

mod_mp3 - FAQ for the Apache mod_mp3 streaming module


So what is mod_mp3?

This turns apache into your basic RIAA hating, but every college student loving mp3 streaming server. It can do a number of things. It can play from a list of files, either straight through or randomly. It can be used as a handler if you just have mp3s or ogg files on your server and you want to stream them with the corret headers. It can also be used to cache mp3's into memory and have the server operate entirely from memory. Enjoy, groove, mp3s not included.


Where do I get it from?

You can get it from either http://software.tangent.org/download/ via the web or ftp://www.tangent.org/pub/apache/ via ftp.


What sort of license does it have?

You are pretty much free to use it as you please. Check out the License file with the distribution for more details. (Its very BSD like)


How can I make suggestions for it?

Send email to brian@tangent.org


How can I report a bug?

You are better off going to http://media.tangent.org/submit.pl. Just submit a bug. This works best right now.


How do I install it?

 Read the INSTALL file that comes along with the module.


How do I use it?

        Listen 8000
        <VirtualHost www.example.com:8000>
                ServerName www.exampe.com
                MP3Engine On
                MP3CastName "Brian's Tunes"
                MP3Genre "Much, nutty"
                MP3 /export/mp3
                MP3 /tmp/madonna.mp3
                MP3 /tmp/cows.mp3
                MP3Random On
                #Increase this if your connections are timing out
                Timeout 1200
                ErrorLog /usr/local/apache/logs/music_error_log
        </VirtualHost&gt

Make sure you also enable Listen for port 80 if you are also running a regular webserver. Also, keep in mind that while I set mine up with VirtualHosts, you could just as easily use Directory, or Location directives. You could run as many streams out of a single host as you want.


So what are the directives?

MP3
Either a filename or directory filled with mp3s (it recurses into subdirectories)

MP3Engine
Turn on the streaming mp3 server.

MP3CastName
Name of your server

MP3Genre
Genre that will be sent to the client

MP3Random
Tells mod_mp3 to randomly dish out music

MP3Stream
I am not useable yet.

MP3Loop
Causes requests to loop thrugh the music requested indefinetly.

MP3LimitPlayConnections
Limit the number of play requests possible.

MP3Log

Logs transaction ID of the player, md5sum of mp3 file, and song title, example: MP3Log /usr/local/apache/logs/mp3stream_log
MP3ReloadRequest
When enabled this causes mod_mp3 to reload all of playlists/files/directories for each request.

MP3Playlist
This takes a file filled with mp3 filenames and loads the filename into mod_cgi list (most MP3 player's playlists are in this format)

MP3Cache
Tells mod_mp3 to cache all of the files to memory instead of getting them at request time from disk. This can take up a lot of memory but is quite a bit faster if you are expecting a large load. This directive must come first if used.

MP3DefaultOperation
You can use this to send a different default output than just straight MP3. The different options are: rss, m3u, m3u2, pls, pls2, list, select. It will also take a second option with can be a regular expression to match browsers with.

MP3Allow
When turned on, only files that are matched with a regular expression given with this directive will load. So ``MP3Allow *.mp3'' would only load file that ended with .mp3.

MP3Deny
Same as MP3Allow but it denies files by filenames.

MP3DispatchAgent
Tells ModMP3 to use a specific dispatch agent (internal, mysql, playlist, pgsql)

MP3MySQLConnectInfo
If you are using the mysql Dispatch agent. specify the hostname,username,password #for the database to connect to. (MP3MySQLConnectInfo ``localhost'' ``USERNAME'' ``PASSWORD'').

MP3MySQLInfo
Database and Table info (MP3MySQLInfo ``DATABASENAME'' ``TABLENAME'')

MP3MySQLTokenTable
Table to use to find tokens.

MP3PgConnectInfo
If you are using the mysql Dispatch agent. specify the hostname,username,password #for the database to connect to. (MP3PgConnectInfo ``localhost'' ``USERNAME'' ``PASSWORD'').

MP3PgInfo
Database and Table info (MP3PgInfo ``DATABASENAME'' ``TABLENAME'')

MP3PgTokenTable
Table to use to find tokens.


XMMS is just sitting here doing nothing.

Look at the example, you probably don't have your virtualhost defined correctly.


What protocols are being supported?

Whatever I can get my hands on. Right now that means just Icecast and Shoutcast. Shout is full supported and ice is coming along nicely. We can also do the headers for Ogg files.


Can I write an interface for it?

Yes. The idea is to let other people write the interface for mod_mp3. To enable this a couple of hooks have been added. You can find a list of the contents to a server by doing a http://example.com:8000/?op=rss. If you want, you can this grab songs based on the ID of the song (which is the filename MD5'ed). An examle is: http://avenger.tangent.org:8080/?op=play&song=475c47c405940fde1737e8bc85f65760&song=7777e58678fcc5fcc96d449b4951ebd1

This was just a start, there is a mailing list for the interface, as I get an idea about what people want, more will be added


What are the different flags I can give op ?

?op=select
lets you search, but also lists ALL the songs, on the bottom of the list, you can selct individual songs, and play them.. (make your own playlist, search for songs, etc).

?op=rdf
listing in RDF format Version 1.0

?op=rss
listing in RSS format Version 0.91

?op=m3u
Makes a playlist in m3u format, and sends it to you, if you have the proper settings with mime-types this would/could load up winamp for you with the entire collectionas a playlist.

?op=m3u2
different format of the playlist.

?op=pls
Winamp playlist

?op=pls2
Another playlist format

?op=list
List in RSS version 0.91

?op=play
Plays songs randomly.

?op=reload
Tells the server to reload all of its playlists.

?op=mbm
Displays the songs in Musicbrainz DTD

?op=index
Shows the index page, if you have one set in your document root for this host. (NOTE, index can be replaced by anything that is not mentioned above, i.e it could be ?op=blowupafghasnistan).


Will this work with Apple's OSX?

Several people have written in and said that it will. If I get a binary I will put it up for people to download and use. Which has been happening. Keep in mind though that until someone sends me a copy of OSX (I own a Mac) I won't be actively testing it.


So what is up with Apple's Itunes?

In theory it supports the shout protocol, but in reality it seems to ignore file names found in the stream.


So what are streams?

A cute idea. Look through the mail archives for the mailing lists for more info. This is not completly supported yet.


Will this work with SSL?

According to people on the mailing list, it will work just fine. Trick is you need a player that can do SSL. You can either do this by tunneling or I am told by using IE with some native player.


My build is dieing with apxs=255?

You are not going to like the answer to this. Basically at some point you have either installed multiple copies of Apache or somehow munged your current copy. Do this: ``apxs -g -n example; cd example; make''. Did that work? If it didn't your copy of Apache is munged.


So what about Vorbis support?

Go look at http://media.tangent.org/article.pl?sid=01/05/04/1547242


I am getting a sync error from the client, what does that mean?

Check that you are not accidently loading any files that may not be mp3's. That is the normal culprit. You can make sure you are only loading mp3 files by using the MP3Allow directive (MP3Allow *.mp3).


Apache is loading very slowly.

You have some crazy sized music collection I take it? And you are just point Apache at the directory and waiting for it to start right? Well, it will, but it is going to take a while. I would suggest using a playlist instead. You can generate one with ``find /export/mp3 | grep -i ''\.mp3`` > /tmp/playlist''


What is this RSS thing, and where can I find a perl/php class to handle it?

You can find out information on RSS at <A HREF=``''>. There is a perl class on CPAN called XML::RSS that will parse RSS. For PHP look at this http://nwow.org/rssparse-0.4.tar.gz


What does all the info in the logs mean ?

Example:

[16/Jul/2001:22:36:19 -0400] fc62362bf4cd1a8602bbf170409b8d04 7652fcbd1077f4ffa58ba36d10c8d9d4

Explanation:

[16/Jul/2001:22:36:19 -0400]
the stuff in the [] is pretty self explanatory.

fc62362bf4cd1a8602bbf170409b8d04
The second string is the transaction id of the player

  • fcbd1077f4ffa58ba36d10c8d9d4
    The third string is the MD5 of the file being streamed for that player

    Pharoahs
    The fourth string is the ID3 Name or filename if there is no id3 tag for that file.


  • Do I have to use a virtual host for this?

    No, not at all. You can put directives in the root of your httpd.conf or even put them in a directory (you could also technically put them in a .htaccess file, but that would be pretty horrible for performance).


    What is a dispatch?

    A dispatch is an internal handler. It is what gets the data to Apache to send. The default handler is a simple load the data into memory and use it sort of thing. There is also currently a MySQL dispatch, Postgres dispatch, and a playlist dispatch. If you are going to do large scale broadcasting the MySQL dispatch is probably what you want. Also, if you want to reload without restarting Apache, then any dispatch other then the internal dispatch is what you want. If you lack a database, the playlist dispatch is probably the way to grow. It lack token support like the MySQL and Postgres dispatch though.


    How do I use the MySQL dispatch?

    First, you need to have MySQL installed. Second you need to tell configure to use mysql (./configure --with-mysql). Third you need to create a database to hold the table. There is a sample schema in the support directory. mod_mp3 will load the files for you if you want, it does this with the MP3 directive (also with playlists), or you can choose to load them by hand. As long as you use similair names for the columns you will be ok. You will need to call MP3DispatchAgent and MP3MySQLConnectInfo to feed the right information to Apache so that it can connect to you DB.


    How do I use the Postgres dispatch?

    First, you need to have Postgres installed. Second you need to tell configure to use mysql (./configure --with-postgres). Third you need to create a database to hold the table. There is a sample schema in the support directory. mod_mp3 will load the files for you if you want, it does this with the MP3 directive (also with playlists), or you can choose to load them by hand. As long as you use similair names for the columns you will be ok. You will need to call MP3DispatchAgent and MP3PostgresConnectInfo to feed the right information to Apache so that it can connect to you DB. You should realize that this is quite alpha at this point and misses many of the features of the MySQL dispatch. Patches to fix this of course are encouraged.


    How do I use the Playlist dispatch?

    This has to be one of the easiest methods to use mod_mp3. Use the playlist directive to specify a playlist to use and you are in business. Updating it will update the available files (and may cause clients to reconnect at the next song). No token support is currently provided by this dispatch.


    I am trying to use the MySQL dispatch, but Apache won't load

    This is a symptom of having PHP with MySQL support and ModMP3 with MySQL support built-in. The fix for this is to recompile PHP. The PHP configure script warns you about this. The exact message is:

            +--------------------------------------------------------------------+
            |                        *** WARNING ***                             |
            |                                                                    |
            | You chose to compile PHP with the built-in MySQL support.  If you  |
            | are compiling a server module, and intend to use other server      |
            | modules that also use MySQL (e.g, mod_auth_mysql, PHP 3.0,         |
            | mod_perl) you must NOT rely on PHP's built-in MySQL support, and   |
            | instead build it with your local MySQL support files, by adding    |
            | --with-mysql=/path/to/mysql to your configure line.                |
    
    
    If you installed PHP as an RPM, please let us know what you did to fix this problem.


    I just want to have Apache stream files while mixing them with other files, can I do this?

    Yep! Just do a AddHandler mp3-file *.mp3 or AddHandler ogg-handler *.ogg to your httpd.conf and you are good to go.


    What are tokens?

    Tokens are like cookies that are specified in the URL. For example:

    http://example.com:8000/?op=play&token=rock

    The above would play any file that is associated with the ``rock'' token. For more information on this you should send email to the developers list.


    I am using the MySQL dispatch but no data is being loaded, what is up?

    You probably have called MP3 or MP3Playlist before you specified the MySQL information. Don't do that, it will not work :) See the sample MySQL file in the support directory.


    So you say you are having bandwidth problems?

    Since you have bandwidth issues, it is time to turn on compression. Actually, it is time to use LAME to compress your mp3 files even more than they are now, before transit across your broadband network.

    Look at it this way: You have 100 kilo bits per second of upload capability. You have to consider the protocol overhead or minus 10% or 15%. You have a 128 Kbit quality MP3 you want to stream. The calculation looks something like this:

    ((100,000 - 10%) / 128000) = 0.703125

    This means you get 0.7 of your connection dedicated for music (aka 70% music, 30% pops & static).

    To fix this you have to lower the bitrate of your mp3 stream, and try the calculation above again until you get a whole number. This means you need to use the mod_mp3 MP3Encoder directive to lower your mp3 bitrate while they are on their way out the door:

    MP3Encoder ``/usr/local/bin/lame -q 2 -b 48 --silent % -''

    This solution imposes a penalty on your system resources as long as your streaming music with LAME. This is not something you want to use on a multi-user setup like Ampache, or Mummi. As long as your doing this for your own personal, and don't have to share the system, it shouldn't be a problem. =)


    Will this work on any flavor of windows? How portable is it?

    There is no reason why this should not compile under windows. Currently no one has ever provided the instructions on how to do this though. In fact any system that can compile Apache and has SYSV shared memory should be able to compile this software.


    Where can I find a directory server that is mod_mp3 aware?

    Vidyut Luther has made a directory server which works with Icecast servers and mod_mp3. You can find out more information on it here : <A HREF=``http://yp.modmp3.net/''>yp.modmp3.net</A>


    So what is the future?

    World domination? Complete online server that would make any radio station drool. Support for more than just mp3. You name it, I am open to ideas. The big thing for me is that I want to give people a voice. Just like apache opened up the web for anyone to publish thoughts and ideas that they have, I want this module to extend that same philosphy to the online airwaves. The FCC is never going to make community radio a reality, hopefully this will give people an alternative. Ok, now that that soap box bit is over, the idea is to create a server which can be controlled by other applications. Let people write good interfaces and not worry about the actual protocols and methods of delivery.


    Appendix A. MP3 httpd.conf Examples

    Simple

    Listen 8000
    <VirtualHost avenger.tangent.org:8000>
    ServerName avenger.tangent.org
    MP3Engine On
    MP3CastName ``Brian's Tunes''
    MP3Genre ``Much, nutty''
    MP3 /export/mp3
    MP3DefaultOperation select
    Timeout 1200
    ErrorLog /usr/local/apache/logs/music_error_log
    </VirtualHost>

    Ogg

            Listen 8001
            <VirtualHost avenger.tangent.org:8001>
                    ServerName avenger.tangent.org
                    MP3Engine On
                    MP3CastName "Brian's Tunes"
                    MP3Genre "Much, nutty"
                    MP3 /export/ogg
                    MP3MimeType audio/x-ogg
                    ErrorLog /usr/local/apache/logs/music_error_log
                    Timeout 1200
            </VirtualHost>

    Advanced

            # The mod_mp3 virtual host.
            # Do not just make-up any name here for the ServerName directive.
            # Use real, valid, host names from the DNS.
            # Increase the timeout if you have large length mpeg files.
            # Timeout of zero means no timeout.
            <VirtualHost 123.456.789.101>
                    ServerName music.example.com
                    ServerAdmin webmaster@example.com
                    ErrorLog /var/log/httpd-error.log
                    SetEnvIfNoCase User-Agent mozilla is_a_browser
                    # Toggle the MP3 module On/Off.
                    MP3Engine On
                    # Control the number of connections to mod_mp3.
                    # Upload speed divided by bitrate is the rule of thumb.
                    # example with DSL 768/768 line, and mp3 w/128 bitrate:
                    # floor((768000 - 10%) / 128000) = 5
                    # Remember that about 5% to 15% of your bandwidth is consumed by overhead.
                    # and since 90% of a stream is not so good, we round-down, and get five.
                    # Your mileage may vary.
                    MP3LimitPlayConnections 2
                    # Name this radio station.
                    MP3CastName "mod_mp3 radio"
                    # Give your Station a format type (aka Classical, Electronic, rock'n'roll, etc.).
                    MP3Genre "various"
                    # Multiple MP3 directives are allowed.
                    # Rule of thumb dictates you not use the MP3 direcctive when using a MP3Playlist.
                    MP3 "/data/mp3z"
                    # This can increase the performance on large collections, but not dramatically.
                    # It is a good idea to avoid using this with the MP3 directive,
                    # unless you know what your doing.
                    #MP3Playlist /data/playlist.m3u
                    # Toggle the stream mode On/Off
                    # This doens't work at the moment.
                    # When enabled, you  should comment-out any MP3, or MP3Playlist directives.
                    #MP3Stream On
                    # Randomize (aka shuffle) the mod_mp3 internal playlist for playback.
                    #MP3Random On
            </VirtualHost>

    MySQL Support

            <VirtualHost 123.123.78.90> 
                    ServerName mp3s.yourdomain.com
                    ServerAdmin webmaster@yourdomain.com
                    CustomLog /www/modmp3/logs/access_log combined
                    #Turn the ModMp3 engine ON.
                    MP3Engine On
                    #The name of your broadcast.
                    MP3CastName "Linuxpowered Radio"
                    #What dispatch agent you want to use 
                    MP3DispatchAgent mysql
                    #If the Agent is Mysql, specify the hostname,username,password
                    #for the database to connect to. 
                    MP3MySQLConnectInfo "localhost" "USERNAME" "PASSWORD"
                    #Now specify the database and tablename where the songs are stored.
                    MP3MySQLInfo "DATABASENAME" "TABLENAME"
                    # Specify the table for tokens
                    MP3MySQLTokenTable "tokens"
                    #Specify where the MP3's are.  This must come after the MySQL directives
                    MP3 "/www/modmp3/songs" 
                    MP3Genre "various"
                    MP3Random On
                    MP3Log /www/modmp3/logs/mp3_log
                    MP3Allow *.mp3
            </VirtualHost>