微信小商店ObS推流服务器,宝塔Nginx配置rtmp直播服务器OBS推流 VLC拉流

一,环境准备

1.下载nginx-rtmp-module:

cd /www/server/

git clone https://github.com/arut/nginx-rtmp-module.git

2.Nginx安装:

软件商店 > 应用搜索:nginx > 安装 > 编译安装 > 添加自定义模块

模块名称:nginx_rtmp_module

描述: nginx rtmp

参数:--add-module=/www/server/nginx-rtmp-module

3. 编辑conf配置:

新建目录:/www/server/nginx/conf/rtmp, 在目录下新建两个文件:nginx-rtmp.conf 和 nginx-rtmp-play.conf

新建目录: /www/tmp/hls用于存放hls视频文件

# nginx-rtmp.conf

rtmp {

server {

listen 1935;

ping 30s;

chunk_size 4000;

notify_method get;

application live { # 推流地址rtmp://ip:1935/live/密钥,同拉流播放地址

live on;

record off; # 是否开启记录 off, all,用于录制直播视频以便回放重播

#record_unique on; # 记录值唯一

#record_max_size 200M; # 记录文件大小

#record_path "/www/tmp/video"; # 记录文件位置

#record_suffix -%Y-%m-%d-%H_%M_%S.flv; # 记录文件命名

#on_publish http://127.0.0.1:8686/auth; # 开始推流的回调地址

#on_done 'http://when live stop call this url'; # 结束推流的回调地址

#on_play http://127.0.0.1:8686/auth; # 开始播放的回调地址

}

application hls { # 推流地址rtmp://ip:1935/hls/密钥,开启HLS协议进行m3u8直播

live on;

hls on; # 开启hls, hls的推流会产生一个m3u8的ts视频文件索引,同时保存一个个视频片段缓存,可以拿到再次播放。

hls_path /www/tmp/hls; # 视频切片ts文件存放的位置

hls_sync 100ms;

hls_fragment 5s; # 视频切片的大小,ts文件大小

hls_cleanup on; #对多余的切片进行删除

hls_playlist_length 60s; #保存m3u8列表长度时间,默认是30秒

}

#application vod { # 用于视频点播flv/mp4

# play /www/tmp/videos; # 本地视频MP4文件存放地址,作为流播放视频: rtmp://ip:1935/vod/视频名称.mp4

#}

#application vod_http { # 播放远程http链接的视频,rtmp://ip:1935/vod_http/视频名称.mp4

# play http://localhost:8080/vod/;

#}

}

}

# nginx-rtmp-play.conf

server {

listen 1000;

location /stat { # http://ip:1000/stat, 监控流的地址

rtmp_stat all;

rtmp_stat_stylesheet stat.xsl;

}

location /stat.xsl {

root /www/server/nginx-rtmp-module/;

}

location /hls { # http拉流的地址,http://ip:1000/hls/密钥.m3u8

# Serve HLS fragments

types {

application/vnd.apple.mpegurl m3u8;

video/mp2t ts;

}

root /www/tmp;

expires -1;

add_header Cache-Control no-cache;

add_header Access-Control-Allow-Origin *;

}

}

编辑nginx.conf引入配置: include /www/server/nginx/conf/rtmp/nginx-rtmp.conf;

a9b03112d21d

引入配置:include /www/server/nginx/conf/rtmp/nginx-rtmp-play.conf;

a9b03112d21d

4. 重启Nginx:

a9b03112d21d

注意放行端口:1935和1000:

a9b03112d21d

5. 使用OBS推流:

live推流:

a9b03112d21d

a9b03112d21d

浏览器访问:http://ip:1000/stat可以看到推流的情况:

a9b03112d21d

使用VLC拉流播放:

a9b03112d21d

a9b03112d21d

HLS推流:

a9b03112d21d

使用VLC拉流播放:

a9b03112d21d

6. 扩展:浏览器拉流播放:

html播放器代码index.html(使用video.js):

HTML5 直播

因为本例的html需要在服务中打开,本例采用node, 所以在同一目录下建立server.js:

(提示:不使用node启动服务可以在IDEA中直接将index.html以服务run运行)

var http = require('http');

// 导入文件读写的js

var fs = require('fs');

var server = http.createServer(function (request, response) {

console.log('someone has visited my first node server !');

//根据访问的路径来选择响应的文件

let filePath;

if (request.url === '/') {

filePath='index.html';

} else {

filePath='notfound.html';

}

//读取文件并写入响应内容中去

fs.readFile(filePath,function(err,data ){

response.write(''+data);

//不能直接写data 是16进制的数,需要转成字符串

//我写data.toString() 会报错

response.end();

})

})

server.listen(8000, function () {

console.log('server started at http://localhost:8000/ ......')

});

启动服务:node ./server.js 浏览器访问http://localhost:8000/打开播放index.html页面

效果:

a9b03112d21d

提示:

使用Chrome播放rtmp流的时候需要允许Flash执行,而使用hls播放m3u8则不用:

a9b03112d21d

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值