Skip to content

Instantly share code, notes, and snippets.

@AysadKozanoglu
Last active November 8, 2018 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AysadKozanoglu/ddcab9b791c9838f541ae4afcd26daf2 to your computer and use it in GitHub Desktop.
Save AysadKozanoglu/ddcab9b791c9838f541ae4afcd26daf2 to your computer and use it in GitHub Desktop.
nginx rtmp live stream install & config
apt-get -y install build-essential libpcre3 libpcre3-dev libssl-dev unzip
wget http://nginx.org/download/nginx-1.14.1.tar.gz
wget https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/archive/dev.zip
unzip dev.zip
tar zxvf nginx-1*
cd nginx-1*
./configure --sbin-path=/usr/local/sbin --user=www-data --group=www-data --with-stream --with-threads --with-file-aio --add-module=../nginx-rtmp-module-dev
worker_processes auto;
worker_rlimit_nofile 100000;
events {
# determines how much clients will be served per worker
# max clients = worker_connections * worker_processes
# max clients is also limited by the number of socket connections available on the system (~64k)
worker_connections 4000;
# optmized to serve many clients with each thread, essential for linux
use epoll;
# accept as many connections as possible, may flood worker connections if set too low
multi_accept on;
accept_mutex on;
accept_mutex_delay 500ms;
}
thread_pool default threads=16 max_queue=65536;
rtmp_auto_push on;
rtmp {
server {
listen 1935;
chunk_size 4000;
# TV mode: one publisher, many subscribers
application mytv {
# enable live streaming
live on;
# record first 1K of stream
record all;
record_path /tmp/av;
record_max_size 1K;
# append current timestamp to each flv
record_unique on;
# publish only from localhost
allow publish 127.0.0.1;
deny publish all;
#allow play all;
}
# HLS
# For HLS to work please create a directory in tmpfs (/tmp/hls here)
# for the fragments. The directory contents is served via HTTP (see
# http{} section in config)
#
# Incoming stream must be in H264/AAC. For iPhones use baseline H264
# profile (see ffmpeg example).
# This example creates RTMP stream from movie ready for HLS:
#
# ffmpeg -loglevel verbose -re -i movie.avi -vcodec libx264
# -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
# -f flv rtmp://localhost:1935/hls/movie
#
# If you need to transcode live stream use 'exec' feature.
#
application hls {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 3;
hls_playlist_length 10;
# disable consuming the stream from nginx as rtmp
deny play all;
}
# MPEG-DASH is similar to HLS
application dash {
live on;
dash on;
dash_path /tmp/dash;
}
}
}
# HTTP can be used for accessing RTMP stats
http {
#aio on;
aio threads=default;
directio 4m;
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;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment