使用Nginx搭建RTMP服务器配置
1、下载Nginx
下载地址:http://nginx-win.ecsds.eu/download/ nginx 1.7.11.3 Gryphon.zip(http://nginx-win.ecsds.eu/download/nginx 1.7.11.3 Gryphon.zip)
2、下载Nginx的RTMP扩展包
下载地址:https://github.com/arut/nginx-rtmp-module
下载完成后解压,将解压后的文件夹放入 nginx 目录下

3、修改配置文件
在conf目录下,新建一个文件“nginx.conf”,内容如下
worker_processes  1;
 
events {
    worker_connections  1024;
}
 
#RTMP服务
rtmp {
	server { 
		listen		1935;	#监听端口
		chunk_size	4096;	#数据传输块大小
		ping 5s;
		ping_timeout 5s;
		timeout 5s;
		application live{	#创建名为"live"的应用
		   live on;
		   hls on;    #开启hls
		   hls_path ./html/hls;  #hls的ts切片存放路径
		   hls_fragment 1s;         #本地切片长度
		   hls_playlist_length 2s;  #HLS播放列表长度
		}
    }
}
 
#HTTP服务,可以通过浏览器访问http://localhost/stat 或者 http://localhost:80/stat 查看服务器状态
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile      on;
    keepalive_timeout  65;
	
    server {
        listen       81;
        server_name  localhost;
		
		location /stat {
			rtmp_stat all;
			rtmp_stat_stylesheet stat.xsl;
		}
 
		location /stat.xsl { 
			root ./nginx-rtmp-module-master/;	#rtmp拓展包目录
		}
		location /live {
			types {
				application/vnd.apple.mpegurl m3u8;
				video/mp2t ts;
			}
			alias ./html/hls/;
			add_header Cache-Control no-cache;
		}
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
 
}   
4、启动服务器
在nginx目录下打开命令行界面,输入 *nginx.exe -c conf\nginx.conf*
启动后,可以在任务管理器中看到nginx进程
5、查看服务器状态
在浏览器地址栏输入 localhost/stat ,可以看到服务器状态信息

6、其它ngnix命令
nginx -s stop    //快速终止服务器,可能不保存相关信息
nginx -s quit    //完整有序停止服务器,保存相关信息
nginx -s reload  //重新载入Nginx,当配置信息修改,需要重新载入这些配置时使用此命令
start nginx //启动命令
7、测试推流和拉流
视频文件推流命令:
//RTMP 协议流
ffmpeg -re -i /Users/gao/Desktop/video/test.mp4 -vcodec libx264 -acodec aac -f flv rtmp://192.168.89.220:1935/live/home
//HLS 协议流
ffmpeg -re -i /Users/gao/Desktop/video/test.mp4 -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -q 10 rtmp://192.168.89.220:1935/hls/home
相关命令解释🤔:
/Users/gao/Desktop/video/test.mp4 ------ 是你的视频文件地址
rtmp://192.168.89.220:1935/live(hls)/home -------是推流拉流地址,中间是你的ip
/live/xx和/hls/xx中的live对应配置文件的live和hls名称,当然也可以取其他的名字, 而后面的 xx (这里是home),你自己命名的哦,对于rtmp流, 这个home就是生成的文件名,如home-xxx.flv,对于hls流,对应的是文件夹名,然后这个文件下存放ts和m3u8文件。
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号