nginx rtmp 直播


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM