user root;worker_processes 1;
error_log /var/log/rtmp.log debug;
events { worker_connections 1024;}
rtmp_auto_push on;
rtmp { server { listen 1935; on_connect http://localhost/auth;
application conf {
live on; exec_static /var/www/video/wrapper.sh stream0; exec_kill_signal term; }
application tohls { live on; hls on; hls_path /var/www/video; hls_fragment 5s; hls_playlist_length 20s; } }}http { include mime.types; default_type application/octet-stream;
server { listen 80; server_name video-server;
location / { root /var/www/video; }
location /auth { if ($arg_id = 'icanit') { return 201; } return 404; } # rtmp stat location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { # you can move stat.xsl to a different location root /var/www/video; }
# rtmp control location /control { rtmp_control all; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }} cat wrapper.sh#!/bin/bash#while [ 1 ]#doon_die (){ # kill all children pkill -KILL -P $$}
trap 'on_die' TERM
ffmpeg -i rtmp://source/live/stream -codec copy -map 0 -f segment -vbsf h264_mp4toannexb -flags -global_header -segment_format mpegts -segment_list stream.m3u8 -segment_time 30 -segment_list_size 0 -f flv rtmp://video-server/tohls/stream?id=icanit &
wait#done