搭建直播平台
1、下载nginx-rtmp-module:
1)nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module
2)使用git下载nginx-rtmp-module
克隆: git clone https://github.com/arut/nginx-rtmp-module.git
将nginx-rtmp-module下载设定的linux路径中一般情况下我是放在了(cd usr/local/src/)。
2、安装nginx:
1)首先查看你是否安装了nginx 如果没有安装请进行安装nginx 推荐安装路径
2)如果已经安装了配置以下内容
进入安装的版本nginx下 (我的是1.8.1如果版本不一样请修改)
cd nginx-1.8.1
在nginx-1.8.1执行下面两个命令关联已下载的nginx-rtmp-module
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module
make && make install
本次默认安装目录为:/root, add-module为下载的nginx-rtmp-module文件路径。
3) 如果安装的时候报错没有安装openssl,需要执行命令:
yum -y install openssl openssl-devel
3、修改nginx配置文件:
进入nginx.conf配置文件内:vi /usr/local/nginx/conf/nginx.conf
修改或加入以下内容:
[php]
- rtmp {
- server {
- listen 1935; #监听的端口
- chunk_size 4000;
- application hls { #rtmp推流请求路径
- live on;
- hls on;
- hls_path /usr/local/nginx/html/hls; #自己的推送路径也就是访问的路径
- hls_fragment 5s;
- }
- }
- }
同配置内
hls_path需要可读可写的权限。
修改http中的server模块:
[php]
- server {
- listen 81;
- server_name localhost;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- root /usr/local/nginx/html; #自己配置路径
- index index.html index.htm;
- }
- #error_page 404 /404.html;
- # redirect server error pages to the static page /50x.html
- #
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
然后启动nginx:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
rtmp的参数可参考:https://github.com/arut/nginx-rtmp-module/wiki
4,完成后安装obs
1)可安装在我们的电脑上
安装会出现bug 自己调试 (安装上就行)
2)安装好后我们开始配置obs
第一步 如上图点击进入
第二步 修改编码可修改也可不修改
第三步 广播设定
第四步 后面的你们自定义配置吧!不配置也可以
5,前面的完成后我们再场景配置
选择一个即可配置可视频(视屏捕捉设备)也可桌面的
6,完成后我们开始串流
会出现如下形式(此处我的场景配置是显示器获取)
7、好了接下来我们可以观看直播(拉流)
观看直播就比较简单了,
在linux上创建hls文件也可是其他的文件夹
书写一个index.php文件
内容可如下:
[php]
- <video>
- <source src="http://xxx:81/hls/test.m3u8"/>
- <p class="warning">Your browser does not support HTML5 video.</p>
- </video>
然后就可以简单的使用h5的vedio标签就可以观看了。
可以访问http://xxx:81/hls/mystream.m3u8来观看直播,其中xxx为你的服务器IP地址,
1,下载nginx-rtmp-module:
nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module
1)进到一个路径下存储(一般我存到 cd /usr/local/src/ ),使用git下载nginx-rtmp-module
2) 命令执行:git clone https://github.com/arut/nginx-rtmp-module.git