Skip to content

Instantly share code, notes, and snippets.

@mfuzailzubari
Created June 27, 2018 12:31
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save mfuzailzubari/8bef96c8bc19584a09d41b4b208a9d00 to your computer and use it in GitHub Desktop.
Save mfuzailzubari/8bef96c8bc19584a09d41b4b208a9d00 to your computer and use it in GitHub Desktop.
NGINX RTMP Configurations
worker_processes auto;
events {
# Allows up to 1024 connections, can be adjusted
worker_connections 1024;
}
# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
# This application is to accept incoming stream
application live {
live on; # Allows live input
# Once receive stream, transcode for adaptive streaming
# This single ffmpeg command takes the input and transforms
# the source into 4 different streams with different bitrate
# and quality. P.S. The scaling done here respects the aspect
# ratio of the input.
exec ffmpeg -i rtmp://192.168.1.68/live/$name -async 1 -vsync -1
-c:v libx264 -c:a libfdk_aac -b:v 256k -b:a 32k -vf "scale=480:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://192.168.1.68/show/$name_low
-c:v libx264 -c:a libfdk_aac -b:v 768k -b:a 96k -vf "scale=720:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://192.168.1.68/show/$name_mid
# -c:v libx264 -c:a libfdk_aac -b:v 1024k -b:a 128k -vf "scale=960:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://192.168.1.68/show/$name_high
-c:v libx264 -c:a libfdk_aac -b:v 1920k -b:a 128k -vf "scale=1280:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://192.168.1.68/show/$name_hd720
-c copy -f flv rtmp://192.168.1.68/show/stream;
}
# This application is for splitting the stream into HLS fragments
application show {
live on; # Allows live input from above
hls on; # Enable HTTP Live Streaming
# hls_fragment 5s;
# Pointing this to an SSD is better as this involves lots of IO
hls_path /tmp/hls/;
# Instruct clients to adjust resolution according to bandwidth
hls_variant _low BANDWIDTH=288000; # Low bitrate, sub-SD resolution
hls_variant _mid BANDWIDTH=448000; # Medium bitrate, SD resolution
# hls_variant _high BANDWIDTH=1152000; # High bitrate, higher-than-SD resolution
hls_variant _hd720 BANDWIDTH=2048000; # High bitrate, HD 720p resolution
# hls_variant _src BANDWIDTH=4096000; # Source bitrate, source resolution
}
}
}
http {
# See http://licson.net/post/optimizing-nginx-for-large-file-delivery/ for more detail
# This optimizes the server for HLS fragment delivery
sendfile off;
tcp_nopush on;
directio 512;
# HTTP server required to serve the player and HLS fragments
server {
listen 80;
error_log /home/user/build/logs/rtmp.log debug;
error_log /home/user/build/logs/rtmp-error.log;
# error_log /home/user/build/logs/rtmp-info.log info;
# error_log /home/user/build/logs/rtmp-notice.log notice;
location / {
root html;
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
}
root /tmp/;
add_header Cache-Control no-cache; # Prevent caching of HLS fragments
add_header Access-Control-Allow-Origin *; # Allow web player to access our playlist
}
}
}
@Alex00Sam
Copy link

Alex00Sam commented Jan 24, 2023

Can you provide links for an OBS input video output receiving?

@btarg
Copy link

btarg commented Sep 4, 2023

I would love to see an example with an HTML video player to play the output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment