-
-
Save lorentedford/177a5234a30f0608866b30103dbac92c to your computer and use it in GitHub Desktop.
Install NGINX RTMP module with HLS support on Ubuntu 18.04
This file contains hidden or 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
| user nginx; | |
| worker_processes 1; | |
| error_log /var/log/nginx/error.log warn; | |
| pid /var/run/nginx.pid; | |
| load_module modules/ngx_rtmp_module.so; | |
| load_module modules/ngx_http_vod_module.so; | |
| events { | |
| worker_connections 1024; | |
| } | |
| rtmp_auto_push on; | |
| rtmp { | |
| server { | |
| listen 1935; | |
| chunk_size 4000; | |
| play_time_fix off; | |
| interleave on; | |
| publish_time_fix on; | |
| application live { | |
| live on; | |
| # Turn on HLS | |
| hls on; | |
| hls_path /tmp/hls; | |
| hls_fragment 3; | |
| hls_playlist_length 60; | |
| record off; | |
| interleave off; | |
| wait_key on; | |
| meta on; | |
| wait_video off; | |
| idle_streams off; | |
| sync 300ms; | |
| session_relay on; | |
| #allow publish 127.0.0.1; | |
| #allow publish 192.168.2.0/24; | |
| allow publish ip; | |
| #deny publish all; | |
| #deny publish all; | |
| #allow publish all; | |
| #deny publish all; | |
| allow play all; | |
| # EDIT THESE SO THE LIVESTREAM_KEY IS REPLACED BY YOUR PERSONAL KEY THAT YOU CAN LOOK UP ON THE SITE OF THE PLATFORM | |
| push rtmp://live-dfw.twitch.tv/app/key; ##Stream ID information | |
| push rtmp://ingest-01-ord1.broadcast.steamcontent.com/app/key; ##Broadcast to Steam | |
| push rtmp://rtmp-pc.facebook.com:443/rtmp/key; ##Facebook | |
| # push rtmp://live-ams.twitch.tv/app/LIVESTREAM_KEY; | |
| # push rtmp://a.rtmp.youtube.com/live2/LIVESTREAM_KEY; | |
| # push rtmp://ingest-ams.mixer.com:1935/beam/LIVESTREAM_KEY; | |
| } | |
| } | |
| } | |
| http { | |
| sendfile off; | |
| tcp_nopush on; | |
| aio on; | |
| directio 512; | |
| default_type application/octet-stream; | |
| server { | |
| listen 80; | |
| location /hls { | |
| # Disable cache | |
| add_header 'Cache-Control' 'no-cache'; | |
| # CORS setup | |
| add_header 'Access-Control-Allow-Origin' '*' always; | |
| add_header 'Access-Control-Expose-Headers' 'Content-Length'; | |
| # allow CORS preflight requests | |
| if ($request_method = 'OPTIONS') { | |
| add_header 'Access-Control-Allow-Origin' '*'; | |
| add_header 'Access-Control-Max-Age' 1728000; | |
| add_header 'Content-Type' 'text/plain charset=UTF-8'; | |
| add_header 'Content-Length' 0; | |
| return 204; | |
| } | |
| types { | |
| application/dash+xml mpd; | |
| application/vnd.apple.mpegurl m3u8; | |
| video/mp2t ts; | |
| } | |
| root /tmp/; | |
| } | |
| # vod caches | |
| vod_metadata_cache metadata_cache 256m; | |
| vod_response_cache response_cache 128m; | |
| # vod settings | |
| vod_mode local; | |
| vod_segment_duration 2000; # 2s | |
| vod_align_segments_to_key_frames on; | |
| #file handle caching / aio | |
| open_file_cache max=1000 inactive=5m; | |
| open_file_cache_valid 2m; | |
| open_file_cache_min_uses 1; | |
| open_file_cache_errors on; | |
| aio on; | |
| location /video/ { | |
| alias /path/to/Videos/; | |
| vod hls; | |
| add_header Access-Control-Allow-Headers '*'; | |
| add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range'; | |
| add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS'; | |
| add_header Access-Control-Allow-Origin '*'; | |
| expires 100d; | |
| } | |
| } | |
| } |
This file contains hidden or 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
| sudo apt install curl gnupg2 ca-certificates lsb-release | |
| echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list | |
| curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add - | |
| sudo apt update | |
| NGINX_VERSION=$(apt show nginx | grep "^Version" | cut -d " " -f 2 | cut -d "-" -f 1) | |
| # take note of the nginx version in the "stable" release. e.g. 1.14.2 | |
| echo NGINX version $NGINX_VERSION | |
| wget https://hg.nginx.org/pkg-oss/raw-file/default/build_module.sh | |
| chmod a+x build_module.sh | |
| # NGINX RTMP module (with live HLS support) | |
| ./build_module.sh -v $NGINX_VERSION https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git | |
| # create local repository | |
| sudo mkdir /opt/deb | |
| sudo cp ~/debuild/nginx-*/debian/debuild-module-rtmp/nginx-module-rtmp_*.deb /opt/deb | |
| # nginx VOD HLS | |
| ./build_module.sh -v $NGINX_VERSION https://github.com/kaltura/nginx-vod-module.git | |
| sudo cp ~/debuild/nginx-*/debian/debuild-module-vod/nginx-module-vod_*.deb /opt/deb | |
| echo "deb [trusted=yes] file:/opt deb/" | sudo tee /etc/apt/sources.list.d/local.list | |
| sudo bash -c "cd /opt && dpkg-scanpackages deb | gzip > deb/Packages.gz" | |
| sudo apt update | |
| sudo apt install nginx-module-rtmp nginx-module-vod | |
| ## for live RTMP with HLS check out | |
| # - https://gist.github.com/afriza/ca7f41ccd0a358b45cf732532f977435/b9f3d918daa9e94313710b8a6b8abbc5e8b59687 | |
| ## references: | |
| # - https://www.nginx.com/blog/creating-installable-packages-dynamic-modules/ | |
| # - http://nginx.org/en/linux_packages.html#Ubuntu | |
| # - https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/ | |
| # - https://harry.web.id/2018/11/18/ubuntu-18-04-compile-nginx-rtmp-vod-hls/ |
This file contains hidden or 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
| user nginx; | |
| worker_processes 1; | |
| error_log /var/log/nginx/error.log warn; | |
| pid /var/run/nginx.pid; | |
| load_module modules/ngx_rtmp_module.so; | |
| load_module modules/ngx_http_vod_module.so; | |
| events { | |
| worker_connections 1024; | |
| } | |
| rtmp_auto_push on; | |
| rtmp { | |
| server { | |
| listen 1935; | |
| chunk_size 4000; | |
| play_time_fix off; | |
| interleave on; | |
| publish_time_fix on; | |
| application live { | |
| live on; | |
| # Turn on HLS | |
| hls on; | |
| hls_path /tmp/hls; | |
| hls_fragment 3; | |
| hls_playlist_length 60; | |
| } | |
| } | |
| } | |
| http { | |
| sendfile off; | |
| tcp_nopush on; | |
| aio on; | |
| directio 512; | |
| default_type application/octet-stream; | |
| server { | |
| listen 80; | |
| location /hls { | |
| # Disable cache | |
| add_header 'Cache-Control' 'no-cache'; | |
| # CORS setup | |
| add_header 'Access-Control-Allow-Origin' '*' always; | |
| add_header 'Access-Control-Expose-Headers' 'Content-Length'; | |
| # allow CORS preflight requests | |
| if ($request_method = 'OPTIONS') { | |
| add_header 'Access-Control-Allow-Origin' '*'; | |
| add_header 'Access-Control-Max-Age' 1728000; | |
| add_header 'Content-Type' 'text/plain charset=UTF-8'; | |
| add_header 'Content-Length' 0; | |
| return 204; | |
| } | |
| types { | |
| application/dash+xml mpd; | |
| application/vnd.apple.mpegurl m3u8; | |
| video/mp2t ts; | |
| } | |
| root /tmp/; | |
| } | |
| # vod caches | |
| vod_metadata_cache metadata_cache 256m; | |
| vod_response_cache response_cache 128m; | |
| # vod settings | |
| vod_mode local; | |
| vod_segment_duration 2000; # 2s | |
| vod_align_segments_to_key_frames on; | |
| #file handle caching / aio | |
| open_file_cache max=1000 inactive=5m; | |
| open_file_cache_valid 2m; | |
| open_file_cache_min_uses 1; | |
| open_file_cache_errors on; | |
| aio on; | |
| location /video/ { | |
| alias /path/to/Videos/; | |
| vod hls; | |
| add_header Access-Control-Allow-Headers '*'; | |
| add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range'; | |
| add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS'; | |
| add_header Access-Control-Allow-Origin '*'; | |
| expires 100d; | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stunnel needs to be installed to stream to Facebook. https://dev.to/lax/rtmps-relay-with-stunnel-12d3
I'm installing stunnel on Debian 9 - stretch with root user. You need to switch root user or use sudo for every commands listed below.
Here is a minimal configuration of stunnel.
Stunnel basic config
Enable tunnel in /etc/default/stunnel4
ENABLE=1Now add a tunnel for Facebook Live address
systemctl restart stunnel4 && systemctl status stunnel4We can run a ffmpeg command to test pushing stream, target to local stunnel port :19350
ffmpeg -re -i /path/to/video.flv -c:v libx264 -c:a aac -f flv rtmps://127.0.0.1:19350/rtmp/<facebook-live-stream-key>