obs直播配置

直播模块中除了obs直播外,同时支持浏览器+摄像头的直播方式. 客户端需要一个元素.能够绑定推流地址,并且能够推流 客户端需要一个播放元素,能够绑定一个hls播放地址,能够播放视频 服务器端需要一个视口,能够正确接收并处理客户端推流内容,并且转为hls格式

一丶 修改nginx配置

1.增加配置文件目录

mkdir /usr/local/nginx/conf/servers

2.添加rtmp.conf配置文件到/usr/local/nginx/conf/servers目录下,注意实际配置过程中请将www.test.com修改为真实地址

内容编辑 :

rtmp {
    server {
        listen 1935;
        ping 30s;
        notify_method get;
        on_connect http://www.test.com/livevideo/rest/on_connect.json;

        application wrtmp {
          live on;

          # sample play/publish handlers
          # hls访问模式,以下两个事件无效
          # on_play http://www.test.com/livevideo/rest/on_play.json;
          # on_play_done http://www.test.com/livevideo/rest/on_play_done.json;
          # 使用$host会报错
          on_publish http://www.test.com/livevideo/rest/on_publish.json;
          on_done http://www.test.com/livevideo/rest/on_done.json;
          on_publish_done http://www.test.com/livevideo/rest/on_publish_done.json;
          on_record_done http://www.test.com/livevideo/rest/on_record_done.json;
          on_update http://www.test.com/livevideo/rest/on_update.json;
          

          # 直播流的录制配置
          recorder rec1 {
            # 录制的磁盘路径是与域名相关 $host 同样会报错
            record_path /home/httpd/data/db/test.com/rec;
            record_interval 5s;
            record video keyframes;
          }

          # sample HLS
          hls on;
          hls_nested on;
          hls_base_url /livevideo/ts?i=;
          hls_path /home/httpd/data/db/test.com/_shadow/;
          hls_fragment 3s;
        }
    }
} 

3./usr/local/nginx/conf/nginx.conf配置文件最后一行增加

include servers/*;

4.修改完配置文件后,重启服务

bash /home/httpd/wware/tools/restartserver.sh

5.防火墙开启1935/tcp端口

firewall-cmd --add-port=1935/tcp --permanent
firewall-cmd --reload

注意事项

目前nginx中的rtmp模块只支持请求HTTP地址,如果网站开启了HTTPS,那么OBS直播将会出现推流失败的问题,access.log中没有任何日志

解决办法:

1.将301强制跳转去掉。(如果对HTTPS访问要求不高的可以使用此解决方法)

2.使用nginx配置中的location和proxy_pass。(推荐使用此方法,保留了301强制跳转,不影响任何HTTPS的访问)示例:

示例一:
server {

    listen 80;
    server_name *.wware.org;

    location ~ /livevideo/rest/on_.*\.json {
        proxy_http_version 1.1;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;
        proxy_pass https://127.0.0.1:443;
    }

    location / {
        return 301 https://$http_host$request_uri;
    }

}


示例二:
server {

    listen 80;
    server_name *.wware.org;

    location ~ (/livevideo/rest/on_connect.json|/livevideo/rest/on_publish.json|/livevideo/rest/on_done.json|/livevideo/rest/on_publish_done.json|/livevideo/rest/on_record_done.json|/livevideo/rest/on_update.json) {
        proxy_http_version 1.1;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;
        proxy_pass https://127.0.0.1:443;
    }

    location / {
        return 301 https://$http_host$request_uri;
    }

}