BlueXIII's Blog

热爱技术,持续学习

0%

nginx-rtmp配置

Windows预编译版下载地址

http://nginx-win.ecsds.eu/download/
http://nginx-win.ecsds.eu/download/nginx%201.7.11.3%20Gryphon.zip

直接安装即可,不做赘述

yamdi

简介

yamdi用于为rtmp点播文件添加索引

下载

http://yamdi.sourceforge.net/
https://github.com/ioppermann/yamdi/releases

编译

1
2
gcc yamdi.c -o yamdi -O2 -Wall
cp yamdi /usr/local/bin

nginx-rtmp

编译安装

1
2
3
./configure --prefix=/opt/nginx-rtmp --with-openssl=../openssl-1.1.1g --add-module=../nginx-rtmp-module-1.2.1 --with-debug
make
make install

配置

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
worker_processes  1;

error_log logs/error.log debug;

events {
worker_connections 1024;
}

rtmp {
server {
listen 1935;

application hls {
live on; #启用rtmp直播
#地址为rtmp://[server]:[rtmp_port]/[app]/[stream]
hls on; #启用hls直播
#地址为http://[server]:[http_port]/[app]/[stream].m3u8
#需要配合下面http段设置使用
hls_path nginx-rtmp-module/tmp/app/;
hls_fragment 5s;
recorder rec { #启用录制
record all manual; #手动控制录制启停
record_suffix _rec.flv;
record_path nginx-rtmp-module/tmp/rec/; #录制保存地址
record_unique on;
}
}
application vod2{ #rtmp点播
play nginx-rtmp-module/tmp/rec/;
}
}
}

http {
server {
listen 18080;

location /stat { #服务器状态
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}

location /stat.xsl {
root nginx-rtmp-module/;
}

location /control { #控制器
rtmp_control all;
}

location /hls/ { #hls直播地址
#server hls fragments
types{
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias nginx-rtmp-module/tmp/app/;
expires -1;
}

location /vod/{ #hls点播地址
alias nginx-rtmp-module/tmp/rec/;
}

location / {
root nginx-rtmp-module/test/www/;
}
}
}

注意拷贝stat.xsl到相应目录下

测试

rtmp监控

http://localhost:18080/stat

rtmp推流

地址:
rtmp://10.30.22.242:1935/hls/mystream

rtmp直播

rtmp://127.0.0.1:1935/hls/mystream

hls直播

http://127.0.0.1:18080/hls/mystream.m3u8

录制视频

http://127.0.0.1:18080/control/record/start?app=hls&name=mystream&rec=rec
http://127.0.0.1:18080/control/record/stop?app=hls&name=mystream&rec=rec

为rtmp点播文件添加索引

1
2
cd /tmp/rec
yamdi -i mystream-1597303714_rec.flv -o mystream-1597303714_rec_idx.flv

rtmp点播

rtmp://127.0.0.1:1935/vod2/mystream-1597303714_rec_idx.flv

制作hls点播分片文件

1
2
3
4
5
cd nginx-rtmp/nginx-rtmp-module/tmp/rec

ffmpeg -i mystream-1597303714_rec.flv -acodec copy -bsf:a h264_mp4toannexb -g 105 -vcodec libx264 -vprofile baseline -bf 0 -bufsize 850k -bsf:v dump_extra -map 0 -f segment -segment_format mpegts -segment_list "mystream-1597303714_rec.m3u8" -segment_time 10 mystream-1597303714_rec-%d.ts

ffmpeg -i mystream-1597303714_rec.flv -acodec copy -bsf:a aac_adtstoasc -g 105 -vcodec libx264 -vprofile baseline -bf 0 -bufsize 850k -bsf:v dump_extra -map 0 -f segment -segment_format mpegts -segment_list "mystream-1597303714_rec.m3u8" -segment_time 10 mystream-1597303714_rec-%d.ts

hls点播

http://127.0.0.1:18080/vod/mystream-1597303714_rec.m3u8