Nginx: Konfigurasi RTMP dengan HLS dan Dash
Revision as of 17:11, 1 November 2014 by Onnowpurbo (talk | contribs)
Untuk mendukung HLS & Dash, kita perlu mengubah sedikit konfigurasi nginx.conf
vi /usr/local/nginx/conf/nginx.conf
ubah agar
http { server { listen 80; 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 live { live on; record off; } 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; } } }
Contoh lain untuk hls
location /hls/ { hls; # Use the HLS handler to manage requests # serve content from the following location alias /var/www/video; # HLS parameters hls_fragment 8s; hls_buffers 10 10m; hls_mp4_buffer_size 1m; hls_mp4_max_buffer_size 5m; }
Contoh sederhana untuk men-stream sebuah video .avi menggunakan ffmpeg:
# ffmpeg -loglevel verbose -re -i movie.avi -vcodec libx264 # -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1 # -f flv rtmp://localhost:1935/hls/movie
# avconv -loglevel verbose -re -i movie.avi -vcodec libx264 # -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1 # -f flv rtmp://localhost:1935/hls/movie
Default playlist address pada setup ini adalah:
http://server.ip/hls/StreamKey.m3u8
StreamKey pada contoh ffmpeg commandline di atas adalah “movie”. Ingat, address rtmp address selalu rtmp://ip/ApplicationName/StreamKey.