Created
January 3, 2017 17:51
-
-
Save maksadbek/d2a8ac2409c1fe074f7390ab42e46b7d to your computer and use it in GitHub Desktop.
nginx configuration for HLS live video streaming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worker_processes 1; | |
error_log logs/error.log debug; | |
events { | |
worker_connections 1024; | |
} | |
rtmp { | |
server { | |
listen 1935; | |
allow play all; | |
#creates our "live" full-resolution HLS videostream from our incoming encoder stream and tells where to put the HLS video manifest and video fragments | |
application live { | |
allow play all; | |
live on; | |
record all; | |
record_path /video_recordings; | |
record_unique on; | |
hls on; | |
hls_nested on; | |
hls_path /HLS/live; | |
hls_fragment 10s; | |
#creates the downsampled or "trans-rated" mobile video stream as a 400kbps, 480x360 sized video | |
exec ffmpeg -i rtmp://192.168.254.178:1935/$app/$name -acodec copy -c:v libx264 -preset veryfast -profile:v baseline -vsync cfr -s 480x360 -b:v 400k maxrate 400k -bufsize 400k -threads 0 -r 30 -f flv rtmp://192.168.254.178:1935/mobile/$; | |
} | |
#creates our "mobile" lower-resolution HLS videostream from the ffmpeg-created stream and tells where to put the HLS video manifest and video fragments | |
application mobile { | |
allow play all; | |
live on; | |
hls on; | |
hls_nested on; | |
hls_path /HLS/mobile; | |
hls_fragment 10s; | |
} | |
#allows you to play your recordings of your live streams using a URL like "rtmp://my-ip:1935/vod/filename.flv" | |
application vod { | |
play /video_recordings; | |
} | |
} | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
server { | |
listen 80; | |
server_name 192.168.254.178; | |
#creates the http-location for our full-resolution (desktop) HLS stream - "http://my-ip/live/my-stream-key/index.m3u8" | |
location /live { | |
types { | |
application/vnd.apple.mpegurl m3u8; | |
} | |
alias /HLS/live; | |
add_header Cache-Control no-cache; | |
} | |
#creates the http-location for our mobile-device HLS stream - "http://my-ip/mobile/my-stream-key/index.m3u8" | |
location /mobile { | |
types { | |
application/vnd.apple.mpegurl m3u8; | |
} | |
alias /HLS/mobile; | |
add_header Cache-Control no-cache; | |
} | |
#allows us to see how stats on viewers on our Nginx site using a URL like: "http://my-ip/stats" | |
location /stats { | |
stub_status; | |
} | |
#allows us to host some webpages which can show our videos: "http://my-ip/my-page.html" | |
location / { | |
root html; | |
index index.html index.htm; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment