A simple guide to start rtmp streaming with nginx 1


I was once using nginx, nginx-rtmp-module and EasyRTMP(http://rg4.net/easyrtmp) to streaming live video with rtmp mode.

It was just for fun, and I didn’t find a chance to utilize it in work. I suggested it to my boss year ago, but it was turned down, comparing to the works on schedule it was always a minor factor to the products. So one day when I found my disk out of usage, I re-installed my OS without backup any data of the previous working environment.

Days ago, a formal colleague asked me some questions about rtmp streaming by using nginx. Happened to have the time, so I tryied to redo the work, and here are the detail steps to start streaming video by rtmp with nginx and nginx rtmp module.

BTW: I’m using /opt/softwares folder as my software download directory, if you are using another directory as your base directory, you should change your configuration for your script or configuration files.

Here we go:

1. Download nginx
The latest release of nginx is 1.5.13, we’ll use it as a example.

2. Extract the downloaded nginx source code

3. Download nginx-rtmp-module source code
This is only a test, so we’ll use the latest source to run the test. In formal version, we should choose a stable release instead.

4. configure nginx with rtmp suppported, and compile it.

If you don’t need HLS support, you can remove the option string: –add-module=/opt/softwares/nginx-rtmp-module/hls

5. nginx and rtmp module configurations

use /home/jacky/rtmp as the root directory of nginx.

6.re-config the nginx.conf

Open the nginx.conf file and modify the path setting to the right path of your environment, you need to modify at least the following 3 settings:

An example of my configuration. Here is the working directory for me:

7. startup the nginx

8. publish stream to nginx
The easiest way to publish live video stream is using ffmpeg.
So as an example, we use ffmpeg to feed the rtmp stream to nginx:

If you dont have a proper video file, you can also publish your webcam to nginx by following command:

Something you may need to know:
RTMP supports only a limited number of codecs. The most popular RTMP codecs pair is H264 + AAC, traditional FLV format, Sorenson-H263 (aka flv) + MP3 or Nellymoser, is also supported.
So if you are publishing streams by yourself, you must be confirmed that your audio/video codec is the ones RTMP supports. Otherwise you need to do the transcode yourself before feed to nginx.

9. Play the video
Open a browser, and navigate to http://live.rg4.net

Getting started with nginx rtmp

10. Get your nginx ready for HLS

If you want your nginx ready for HLS support, you should first make sure you’ve compiled the nginx with HLS module, and modify the default nginx.conf to have HLS enabled, then push your streams to the server with URL like:

rtmp://your-server-ip-address/hls/<stream_name>

Once done with these, you can have both RTMP and HLS supported for your single push of stream. nginx will do the rest job of conversion and segmenting of RTMP to HLS.

But as you may know, HLS supports less formats than RTMP, if you want archive that, support RTMP and HLS both with a single push, you need specify the audio/video encoding type to AAC/H.264 for your stream.

When everything is ready, you can watch the video by:

  • RTMP: rtmp://your-server-ip-address/hls/<stream_name>
  • HLS: http://your-server-ip-address/hls/<stream_name>.m3u8

Here is a sample configuration which worked for me:


Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “A simple guide to start rtmp streaming with nginx

  • jacky

    There is one more step to follow before you start the nginx, that is modify the nginx.conf and change all the “/path/to” content to the real path for your system.