php rtmp服务器搭建,rtmp直播服务器的搭建(小白踩坑)

好的我懒。。

开始编译   centos7

./configure --disable-all --with-ssl --with-hls --with-nginx --with-http-server  &&  make

文档会告诉你

./obj/srs -c conf/https.hls/conf

其实就坑!!!!

etc/init.d/srs  就能打开

并且调用的是srs.conf

然后用xsolist就可以推流了(obs推流失败,有知道如何解决的大神求指导)

再说,推流验证,

编译的时候加上  --with-http-callback

在srs.conf中加上  http_hooks{

enabled         on;

# when client connect to vhost/app, call the hook,

# the request in the POST data string is a object encode by json:

#       {

#           "action": "on_connect",

#           "client_id": 1985,

#           "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",

#           "tcUrl": "rtmp://video.test.com/live?key=d2fa801d08e3f90ed1e1670e6e52651a",

#           "pageUrl": "http://www.test.com/live.html"

#       }

# if valid, the hook must return HTTP code 200(Stauts OK) and response

# an int value specifies the error code(0 corresponding to success):

#       0

# support multiple api hooks, format:

#       on_connect http://xxx/api0 http://xxx/api1 http://xxx/apiN

on_connect      http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;

# when client close/disconnect to vhost/app/stream, call the hook,

# the request in the POST data string is a object encode by json:

#       {

#           "action": "on_close",

#           "client_id": 1985,

#           "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live"

#       }

# if valid, the hook must return HTTP code 200(Stauts OK) and response

# an int value specifies the error code(0 corresponding to success):

#       0

# support multiple api hooks, format:

#       on_close http://xxx/api0 http://xxx/api1 http://xxx/apiN

on_close        http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;

# when client(encoder) publish to vhost/app/stream, call the hook,

# the request in the POST data string is a object encode by json:

#       {

#           "action": "on_publish",

#           "client_id": 1985,

#           "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",

#           "stream": "livestream"

#       }

# if valid, the hook must return HTTP code 200(Stauts OK) and response

# an int value specifies the error code(0 corresponding to success):

#       0

# support multiple api hooks, format:

#       on_publish http://xxx/api0 http://xxx/api1 http://xxx/apiN

on_publish      http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;

# when client(encoder) stop publish to vhost/app/stream, call the hook,

# the request in the POST data string is a object encode by json:

#       {

#           "action": "on_unpublish",

#           "client_id": 1985,

#           "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",

#           "stream": "livestream"

#       }

# if valid, the hook must return HTTP code 200(Stauts OK) and response

# an int value specifies the error code(0 corresponding to success):

#       0

# support multiple api hooks, format:

#       on_unpublish http://xxx/api0 http://xxx/api1 http://xxx/apiN

on_unpublish    http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;

# when client start to play vhost/app/stream, call the hook,

# the request in the POST data string is a object encode by json:

#       {

#           "action": "on_play",

#           "client_id": 1985,

#           "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",

#           "stream": "livestream",

#           "pageUrl": "http://www.test.com/live.html"

#       }

# if valid, the hook must return HTTP code 200(Stauts OK) and response

# an int value specifies the error code(0 corresponding to success):

#       0

# support multiple api hooks, format:

#       on_play http://xxx/api0 http://xxx/api1 http://xxx/apiN

on_play         http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;

# when client stop to play vhost/app/stream, call the hook,

# the request in the POST data string is a object encode by json:

#       {

#           "action": "on_stop",

#           "client_id": 1985,

#           "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",

#           "stream": "livestream"

#       }

# if valid, the hook must return HTTP code 200(Stauts OK) and response

# an int value specifies the error code(0 corresponding to success):

#       0

# support multiple api hooks, format:

#       on_stop http://xxx/api0 http://xxx/api1 http://xxx/apiN

on_stop         http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;

# when srs reap a dvr file, call the hook,

# the request in the POST data string is a object encode by json:

#       {

#           "action": "on_dvr",

#           "client_id": 1985,

#           "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",

#           "stream": "livestream",

#           "cwd": "/usr/local/srs",

#           "file": "./objs/nginx/html/live/livestream.1420254068776.flv"

#       }

# if valid, the hook must return HTTP code 200(Stauts OK) and response

# an int value specifies the error code(0 corresponding to success):

#       0

on_dvr          http://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs;

}

说一句,其实里面全是废话

可以精简成这样

http_hooks{

enabled         on;

on_connect      http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;

on_close        http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;

on_publish      http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;

on_unpublish    http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;

on_play         http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;

on_stop         http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;

on_dvr          http://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs;

}

文档一直再说要开api。其实也是不用的

里面的连接可以随便换的

on_publish      对应的就是推流验证了

{

"action": "on_publish",

"client_id": 1985,

"ip": "192.168.1.10",

"vhost": "video.test.com",

"app": "live",

"tcUrl": "rtmp://x/x?key=xxx",

"stream": "livestream"

}

srs会给你的链接post一个json

只要验证一下tcUrl": "rtmp://x/x?key=xxx",

返回0就是验证通过

返回1不通过

表示一个写php代码丑到没朋友,

中间碰到了 json_decode()的坑

只要json_decode(变量,trun)就可以了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值