Live-streaming using Nginx and RTMP modules is straightforward. I have used the following docker image (which is an excellent solution):
alfg/nginx-rtmp
My current solution for VOD streaming:
- Create an VOD application block inside the Nginx config file:
application vod {
play /videos/;
}
- Pull this VOD stream inside the HLS block (right now, I have just focused on a single video file named input.mp4)
application show/ {
live on;
# Turn on HLS
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 10;
pull rtmp://localhost:1935/vod/input.mp4;
}
The Nginx config looks like this:
daemon off;
error_log /dev/stdout info;
events {
worker_connections 1024;
}
rtmp {
server {
listen ${RTMP_PORT};
chunk_size 4000;
application vod {
play /videos;
}
application hls {
live on;
hls on;
pull rtmp://localhost:1935/vod/input.mp4;
hls_fragment_naming system;
hls_fragment 5;
hls_playlist_length 10;
hls_path /opt/data/hls;
hls_nested on;
}
}
}
http {
root /www/static;
sendfile off;
tcp_nopush on;
server_tokens off;
access_log /dev/stdout combined;
server {
listen ${HTTP_PORT};
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /opt/data;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
location /live {
alias /opt/data/hls;
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /www/static;
}
location /crossdomain.xml {
default_type text/xml;
expires 24h;
}
}
}
Do you guys think this approach should work?
Is there anything wrong with the configuration?