Skip to content

Instantly share code, notes, and snippets.

@iflamed
Last active July 7, 2023 08:02
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 iflamed/406f73d7aae01ca2cec2b6cca4f4384d to your computer and use it in GitHub Desktop.
Save iflamed/406f73d7aae01ca2cec2b6cca4f4384d to your computer and use it in GitHub Desktop.
How to use nginx as RTMP server?
# create rtmp stream from video
ffmpeg -stream_loop -1 -i test02.mp4 -c:a copy -c:v libx264 -f flv rtmp://www.example.com/mytv/test02
ffmpeg -stream_loop -1 -i test02.mp4 -f flv rtmp://www.example.com/mytv/test02
location /hls {
# Serve HLS fragments
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
load_module modules/ngx_rtmp_module.so;
rtmp {
access_log /var/log/nginx/rtmp_access.log;
server {
listen 1935;
chunk_size 4000;
# TV mode: one publisher, many subscribers
application mytv {
# enable live streaming
live on;
hls on;
hls_path /tmp/hls;
# publish only from localhost
allow publish all;
allow play all;
# publish directly by nginx
exec_static ffmpeg -stream_loop -1 -i /var/www/test_hls_rtmp.mp4 -c:a copy -c:v libx264 -f flv rtmp://localhost:1935/mytv/test02;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment