搭建直播流服务器
技术
- Nginx
- nginx-rtmp-module-1.1.11 (nginx 插件)
步骤
- 下载nginx 和 nginx-rtmp-module 源文件
- 解压 nginx 和 nginx-rtmp-module
- ./configure --add-module=/home/shichangcheng/live/nginx-rtmp-module-1.1.11(将nginx第三方模块加入nginx)
- make ; make install;
- 配置nginx.conf
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# hls living
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/local/nginx/html/nginx-rtmp-module/;
}
location /control {
rtmp_control all;
}
location /hls {
types{
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /home/shichangcheng/live/my-app;
}
}
}
rtmp {
server {
listen 1935;
application hls {
live on;
hls on;
hls_path /home/shichangcheng/live/my-app/hls;
hls_fragment 5s;
}
application live{
live on;
max_connections 1024;
allow play all;
record_path /home/shichangcheng/live/my-app/live;
recorder audio
{
record audio;
record_suffix -%d-%b-%y-%T.flv;
}
recorder chunked
{
record all;
#record_max_size 5120K;
record_interval 15s;
record_path /home/shichangcheng/live/my-app/live/chunked;
}
}
}
}
遇到的问题
- liunx 的权限
- nginx user 修改为root
- rtmp 中 record_path 保存客户端采集视频信息推动到服务器的地址,需要注意该文件的读写权限。
- 防火墙 iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 1935 -j ACCEPT
推流地址
rtmp://123.206.231.130/hls/(movie)
(movie)为表示生成流文件的名字
播放地址
rtmp地址:rtmp://123.206.231.130/hls/(movie)
hvl 地址:http://123.206.231.138/hls/movie.m3u8
直播协议
- rtmp :rtmp 延时较低,需要使用flash,或者解码器才能播放。
- hlv :hlv 延时较高,自己测未进过cdn一般优化,延时5。移动端网页播放使用HLV协议。
客户端
- 直播工具可以使用金山云的DEMO
- 播放器
- H5 只能使用 hlv 地址
- 金山云提供的播放SDK
- PC客户端 VLC Media Player