1,安裝nginx-rtmp-module模塊
配置文件 open /usr/local/etc/nginx 下的nginx.conf
#配置nginx支持rtmp sudo vim /usr/local/nginx/conf/nginx.conf rtmp { server{ listen 1066; #錄制配置 record all; record_unique on; record_path /home/weeds/weeds/rtmp/record; record_suffix -%Y-%m-%d-%H_%M_%S.flv; #record_max_size 300m; #直播權限配置 publish_notify on; #notify_method get; on_publish http://dev.ft.com/new_api/huazhen_rtmp/pushCallBack; #on_publish_done http://127.0.0.1/publishDoneCallBack.php; #on_play http://127.0.0.1/playCallBack.php; #on_play_done http://127.0.0.1/playDoneCallBack.php; #直播流配置 application rtmplive{ live on; #為rtmp設置最大鏈接數。默認為off max_connections 1024; } application hls{ live on; #hls on; #hls_path /home/weeds/weeds/rtmp/hls; #hls_fragment 5s; } hls on; hls_path /home/weeds/weeds/rtmp/hls; hls_fragment 5s;#沒有生效 hls_playlist_length 30s; hls_nested on; #默認是off。打開后的作用是每條流自己有一個文件夾 hls_cleanup off;#不清理ts } } #nginx配置支持hls http節點的server下增加 #加入hls支持 location /hls { types { application/vnd.apple.mpegurl m3u8; #或 application/x-mpegURL video/mp2t ts; } alias /home/weeds/weeds/rtmp/hls; #視頻流文件目錄(自己創建) expires -1; add_header Cache-Control no-cache; } #end... #重啟nginx sudo /usr/local/nginx/sbin/nginx -s reload #推流 ffmpeg -re -i /home/weeds/weeds/audio/4.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost:1066/hls/room http://localhost/hls/room/index.m3u8
參考文檔
https://github.com/arut/nginx-rtmp-module/wiki/Directives