0%

搭建直播流服务器

搭建直播流服务器

技术

  • Nginx
  • nginx-rtmp-module-1.1.11 (nginx 插件)

步骤

  1. 下载nginx 和 nginx-rtmp-module 源文件
  2. 解压 nginx 和 nginx-rtmp-module
  3. ./configure –add-module=/home/shichangcheng/live/nginx-rtmp-module-1.1.11(将nginx第三方模块加入nginx)
  4. make ; make install;
  5. 配置nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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;
}
}
}
}

遇到的问题

  1. liunx 的权限
  2. nginx user 修改为root
  3. rtmp 中 record_path 保存客户端采集视频信息推动到服务器的地址,需要注意该文件的读写权限。
  4. 防火墙 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

直播协议

  1. rtmp :rtmp 延时较低,需要使用flash,或者解码器才能播放。
  2. hlv :hlv 延时较高,自己测未进过cdn一般优化,延时5。移动端网页播放使用HLV协议。

客户端

  1. 直播工具可以使用金山云的DEMO
  2. 播放器
  • H5 只能使用 hlv 地址
  • 金山云提供的播放SDK
  • PC客户端 VLC Media Player