Skip to content

Instantly share code, notes, and snippets.

@peerasan
Created November 19, 2019 08:07
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 peerasan/e79a878244fad775352253d090e1dfc7 to your computer and use it in GitHub Desktop.
Save peerasan/e79a878244fad775352253d090e1dfc7 to your computer and use it in GitHub Desktop.
nginx-rtmp
# /etc/nginx/sites-available
# Patrickz
# Default server configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
add_header 'Cache-Control' 'no-cache';
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Expose-Headers' 'Content-Length';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Access-Control-Allow-Headers' 'Origin,Range,Accept-Encoding,Referer,Cache-Control';
add_header 'Access-Control-Expose-Headers' 'Server,Content-Length,Content-Range,Date';
add_header 'Access-Control-Allow-Methods' 'GET, HEAD, POST, OPTIONS, PUT, DELETE';
location /hls {
#root /raid/live_hls;
alias /raid/live_hls;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/share/nginx/html;
}
}
# /etc/nginx/ngixn.conf
# Patrickz
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
rtmp {
server {
listen 1935;
ping 30s;
notify_method get;
chunk_size 4096;
buflen 5s;
application vod {
play /raid/live;
}
application transcode {
live on;
record all;
record_path /raid/transcode;
record_unique on;
exec_push ffmpeg -i rtmp://localhost:1935/transcode/myLive -max_muxing_queue_size 1024 -threads 8
-c:v libx264 -preset faster -profile:v baseline -vf scale=1920:1080 -b:v 6000k -c:a aac -b:a 128k -f flv rtmp://localhost:1935/live/myLive_1080p
-c:v libx264 -preset faster -profile:v baseline -vf scale=1280:720 -b:v 4000k -c:a aac -b:a 128k -f flv rtmp://localhost:1935/live/myLive_720p
-c:v libx264 -preset faster -profile:v baseline -vf scale=640:360 -b:v 1000k -c:a aac -b:a 128k -f flv rtmp://localhost:1935/live/myLive_360p
-c:v libx264 -preset faster -profile:v baseline -vf scale=426:240 -b:v 500k -c:a aac -b:a 64k -ar 22050 -ac 1 -f flv rtmp://localhost:1935/live/myLive_240p;
}
application live {
live on;
record all;
record_path /raid/live;
record_unique on;
hls on;
hls_path /raid/live_hls;
hls_nested on;
}
}
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment