Can you stream an mp3 file with nginx?

10,165

Solution 1

You can also achieve this with mp4 module

 location /mp3/ {
    root data;
    mp4;
    mp4_buffer_size      1m;
    mp4_max_buffer_size  5m;
 }

You don't have to convert to flv to play mp3

Solution 2

Nginx has built in support for streaming FLV files through the HttpFlvStreamModule. You nave to specify the module when you compile / recompile Nginx.

# ./configure --with-http_flv_module ...SOME-OTHER-OPTS...

You can then configure your nginx.conf to stream FLV files like so:

...
http {
    ...
    server {
        ...
        location ~ \.flv$ {
            flv;
        }
        ...
    }
    ...
}

Now how does this help anything since the original question was about streaming MP3 files? Well you can use FFMPEG to convert the MP3s to FLV files like this:

ffmpeg -y -i /home/song.mp3 -f flv -acodec mp3 -ab 64 -ac 1 /home/song.flv
Share:
10,165

Related videos on Youtube

Philipp Jahoda
Author by

Philipp Jahoda

Updated on September 17, 2022

Comments

  • Philipp Jahoda
    Philipp Jahoda over 1 year

    I have a Ruby On Rails application running on Nginx which is serving out MP3s using JW player. I need to be able to set the start time and duration for playlist items. From what I can tell to do this I need be streaming the MP3 files. How can I setup Nginx to do this?

  • Philipp Jahoda
    Philipp Jahoda about 13 years
    According to the JW player you need to be using streaming vs flat file served by a web-server in order to specify the "start" parameter. Shown in their documentation
  • d-_-b
    d-_-b about 13 years
    JWplayer supports stream for video. "Support for streaming video protocols RTMP and HTTP pseudo-streaming" longtailvideo.com/support/jw-player/jw-player-for-flash-v5/… I see no mention of support for streaming audio. What is you use case and why do you want to use a streaming protocol with MP3?
  • d-_-b
    d-_-b about 13 years
    I guess that's cool if you like to use a video player to play music. I've used this before: flash-mp3-player.net There are quite a few other flash audio players as well.
  • Brad
    Brad about 7 years
    This answer is wrong. This content is served on-demand, over HTTP, and that's how it is streamed. Icecast is for live streams, and actually uses HTTP as well.
  • Brad
    Brad about 7 years
    No need to deal with FLV for this, there is no extra streaming server requirement beyond HTTP in this use case. Also, if you're going to convert from MP3 to FLV, you should use -acodec copy... otherwise you're transcoding and reducing quality.