Article Address: http://blog.csdn.net/zph1234/article/details/52846223
The built environment streaming media using centos 7.0 + nginx; let's start streaming wonderful journey together!
1. Download nginx-rtmp-module:
nginx-rtmp-module official github Address: https://github.com/arut/nginx-rtmp-module
Use the command:
1 |
|
The nginx-rtmp-module to download the linux.
2, install nginx:
nginx's official website: http://nginx.org/en/download.html
1 2 3 4 5 |
|
Note: Nginx here do not need to modify the path name.
The default installation directory is: / root, add-module is downloaded nginx-rtmp-module file path.
Installation time may be an error not installed openssl, you need to perform the command:
1 |
|
3, modify nginx configuration file:
1 |
|
Add the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
hls_path need read permission writable.
Http modify the server module:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Of course, root can follow according to their needs to reform. Then start nginx:
1 |
|
About rtmp more parameters can refer to: https://github.com/arut/nginx-rtmp-module/wiki
If the unit can not see the virtual machine right Nginx access page, you need to handle it as follows:
1 2 3 |
|
You can also modify the server name and port the server is listening:
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 |
|
4, the flow started to push
做好以上的配置后,就可以开始推流了,我们可以使用obs(或者访问http://www.obsapp.net/)来推流。(截图同款请到http://www.pc6.com/mac/410309.html)
在设置->串流 中填写信息:URL为 rtmp://xxx:1935/hls,xxx为你的服务器的IP地址,hls是用来存放流媒体的。
秘钥可以随便填写一个,用来播放的时候识别播放哪个流媒体的,例如填写test等。
填写完毕后,点击开始串流,就说明我们的流媒体服务器搭建成功了。
5、观看直播(拉流)
观看直播就比较简单了,可以简单的使用h5的vedio标签就可以观看了。
可以访问http://xxx:81/hls/mystream.m3u8来观看直播,其中xxx为你的服务器IP地址,或者使用
1 2 3 4 |
|
同上, xxx写的是你服务器IP地址。
然后使用手机访问这个网站就能够观看直播了。延迟大概在20S左右。
(在IOS的safari浏览器中可以正常观看)
写在最后
为什么延迟 那么高呢?这是因为服务器将视频流切断成一个个小的以.ts结尾的文件。
(hls文件夹内容。即推流到该文件夹了)
而我们访问的是.m3u8文件,这个文件内容是将一个个ts文件串联起来的,这就达到了一个播放的效果,所以看起来会有很大的延迟。
(m3u8文件内容)
如果降低延迟也不是没有方法,可以设置切片生成的大小以及访问的速度,但是这样大大增加了服务器的压力。
当然,我们也可以用rtmp拉流工具(VLC等)来看该直播,延迟大概在2-5S左右,拉流地址与推流地址一致。
纸上得来终觉浅,绝知此事要躬行。