直播服务器搭建
Nginx 安装流媒体
yum install gcc-c++ -y
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
wget https://nginx.org/download/nginx-1.22.1.tar.gz
tar -zxvf nginx-1.22.1.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
unzip master.zip
Master.zip和 nginx-1.22.1.tar.gz同一个目录里面
cd nginx-1.22.1
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module-master
make
make install
cp stat.xsl /usr/local/nginx/html/
vim /usr/local/nginx/conf/nginx.conf
Server里面添加
location /stat{
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl{
root html;
}
最后添加
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
publish_notify on;
on_publish http://127.0.0.1:8080/sys/auth;
record off;
}
}
}
cd /usr/local/nginx/sbin
./nginx
鉴权接口
http://127.0.0.1:8080/sys/auth?passWord=123456
Java代码
@RequestMapping("/sys/auth")
public String auth(HttpServletRequest request, HttpServletResponse response, String passWord) {
try {
if (passWord.equals("123456")){
return "success";
}else{
response.setHeader("liveAuth","authCode error");
response.setStatus(500);
}
} catch (Exception e) {
response.setHeader("error","sys error");
response.setStatus(500);
}
return "success";
}
录屏推流测试:
ffmpeg -f gdigrab -i desktop -r 15 -rtsp_transport tcp -vcodec h264 -f flv rtmp://101.34.82.141/live/1668?passWord=123456
播放测试(vlc):
rtmp://101.34.82.141/live/1668