Difference between revisions of "Nginx: Konfigurasi RTMP dengan HLS dan Dash"

From OnnoWiki
Jump to navigation Jump to search
(New page: We already looked at using our nginx-rtmp server to transcode our streams or to deliver them to more than one location. But another very nice feature, especially for mobile devices is the ...)
 
Line 1: Line 1:
We already looked at using our nginx-rtmp server to transcode our streams or to deliver them to more than one location. But another very nice feature, especially for mobile devices is the option to offer streams using HLS or Mpeg-Dash.
+
Untuk mendukung HLS & Dash, kita perlu mengubah sedikit konfigurasi nginx.conf
 
 
Dash explanation
 
HLS explanation
 
 
 
In nginx-rtmp, both features are actually quite easy to use, but they depend on a few factors:
 
 
 
    both HLS and DASH need their own temp folder which we define in our settings soon
 
    your input stream should use the baseline H264 profile for Iphones etc.
 
 
 
In the nginx config we have to change our http section as well as our application, both in the nginx.conf:
 
  
 
  http {
 
  http {
Line 35: Line 25:
 
  }
 
  }
  
So we need a folder tmp/dash and tmp/hls in our root folder for nginx. And in the rtmp section:
+
 
 +
Kita butuh menambahkan folder tmp/dash and tmp/hls di root folder untuk nginx.
 +
 
 +
mkdir /tmp/hls
 +
mkdir /tmp/dash
 +
chmod -Rf 777 /tmp/hls
 +
chmod -Rf 777 /tmp/dash
 +
 
 +
Juga di bagian rtmp:
  
 
  rtmp {
 
  rtmp {

Revision as of 10:42, 1 November 2014

Untuk mendukung HLS & Dash, kita perlu mengubah sedikit konfigurasi nginx.conf

http {

    server {

        listen      8080;

        location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /tmp;
            add_header Cache-Control no-cache;
        }

        location /dash {
            # Serve DASH fragments
            root /tmp;
            add_header Cache-Control no-cache;
        }
    }
}


Kita butuh menambahkan folder tmp/dash and tmp/hls di root folder untuk nginx.

mkdir /tmp/hls
mkdir /tmp/dash
chmod -Rf 777 /tmp/hls
chmod -Rf 777 /tmp/dash

Juga di bagian rtmp:

rtmp {

    server {

        listen 1935;
        chunk_size 4000;

        application hls {
            live on;
            hls on;
            hls_path /tmp/hls;
        }

        # MPEG-DASH is similar to HLS

        application dash {
            live on;
            dash on;
            dash_path /tmp/dash;
        }
    }
}

That is pretty much all we need. In his example configuration arut also shows us a simple ffmpeg configuration to stream a movie to either of the applications:

# ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264
#    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
#    -f flv rtmp://localhost:1935/hls/movie

Now you are ready to go and test the stream on your mobile. There are different ways to playback the stream so you will probably want to google the best solution for your system (Android/iOS/WP).

Default playlist address in this setup is:

http://server.ip/hls/StreamKey.m3u8 

The StreamKey in our example ffmpeg commandline was “movie”. Remember, the rtmp address is always rtmp://ip/ApplicationName/StreamKey. If you have questions, as always, post them below!




Referensi