SRS搭建流媒体服务器
流媒体服务器搭建
目录
流媒体服务器搭建
1、安装
2、常用设置
HTTPCallback
Config SRS
HTTP callback events(回调事件)
3、回调测试
SRS HTTP Callback Server
Publish and Play
1、安装
下载地址:https://github.com/ossrs/srs/
解压后,cd /srs/trunk下执行命令:
1、Build
./configure && make
2、Run
./objs/srs -c conf/srs.conf
3、配置文件修改
修改SRS配置:vi /srs/trunk/objs/conf/srs.conf
2、常用设置
HTTPCallback
Config SRS
http hooks的配置如下:
vhost your_vhost {http_hooks {# whether the http hooks enable.# default off.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(Status 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# @remark For SRS4, the HTTPS url is supported, for example:# on_connect https://xxx/api0 https://xxx/api1 https://xxx/apiNon_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",# "send_bytes": 10240, "recv_bytes": 10240# }# if valid, the hook must return HTTP code 200(Status 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# @remark For SRS4, the HTTPS url is supported, for example:# on_close https://xxx/api0 https://xxx/api1 https://xxx/apiNon_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", "param":"?token=xxx&salt=yyy"# }# if valid, the hook must return HTTP code 200(Status 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# @remark For SRS4, the HTTPS url is supported, for example:# on_publish https://xxx/api0 https://xxx/api1 https://xxx/apiNon_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", "param":"?token=xxx&salt=yyy"# }# if valid, the hook must return HTTP code 200(Status 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# @remark For SRS4, the HTTPS url is supported, for example:# on_unpublish https://xxx/api0 https://xxx/api1 https://xxx/apiNon_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", "param":"?token=xxx&salt=yyy",# "pageUrl": "http://www.test.com/live.html"# }# if valid, the hook must return HTTP code 200(Status 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# @remark For SRS4, the HTTPS url is supported, for example:# on_play https://xxx/api0 https://xxx/api1 https://xxx/apiNon_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", "param":"?token=xxx&salt=yyy"# }# if valid, the hook must return HTTP code 200(Status 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# @remark For SRS4, the HTTPS url is supported, for example:# on_stop https://xxx/api0 https://xxx/api1 https://xxx/apiNon_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", "param":"?token=xxx&salt=yyy",# "cwd": "/usr/local/srs",# "file": "./objs/nginx/html/live/livestream.1420254068776.flv"# }# if valid, the hook must return HTTP code 200(Status OK) and response# an int value specifies the error code(0 corresponding to success):# 0on_dvr http://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs;# when srs reap a ts file of hls, call the hook,# the request in the POST data string is a object encode by json:# {# "action": "on_hls",# "client_id": 1985,# "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",# "stream": "livestream", "param":"?token=xxx&salt=yyy",# "duration": 9.36, // in seconds# "cwd": "/usr/local/srs",# "file": "./objs/nginx/html/live/livestream/2015-04-23/01/476584165.ts",# "url": "live/livestream/2015-04-23/01/476584165.ts",# "m3u8": "./objs/nginx/html/live/livestream/live.m3u8",# "m3u8_url": "live/livestream/live.m3u8",# "seq_no": 100# }# if valid, the hook must return HTTP code 200(Status OK) and response# an int value specifies the error code(0 corresponding to success):# 0on_hls http://127.0.0.1:8085/api/v1/hls http://localhost:8085/api/v1/hls;# when srs reap a ts file of hls, call this hook,# used to push file to cdn network, by get the ts file from cdn network.# so we use HTTP GET and use the variable following:# [app], replace with the app.# [stream], replace with the stream.# [param], replace with the param.# [ts_url], replace with the ts url.# ignore any return data of server.# @remark random select a url to report, not report all.on_hls_notify http://127.0.0.1:8085/api/v1/hls/[app]/[stream]/[ts_url][param];}
}
HTTP callback events(回调事件)
SRS的回调事件包括:
事件 | 数据 | 说明 |
---|---|---|
on_connect |
{ "action": "on_connect", "client_id": 1985, "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", "tcUrl": "rtmp://x/x?key=xxx", "pageUrl": "http://x/x.html" } |
当客户端连接到指定的vhost和app时 |
on_close |
{ "action": "on_close", "client_id": 1985, "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", "send_bytes": 10240, "recv_bytes": 10240 } |
当客户端关闭连接,或者SRS主动关闭连接时 |
on_publish |
{ "action": "on_publish", "client_id": 1985, "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", "stream": "livestream" } |
当客户端发布流时,譬如flash/FMLE方式推流到服务器 |
on_unpublish |
{ "action": "on_unpublish", "client_id": 1985, "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", "stream": "livestream" } |
当客户端停止发布流时 |
on_play |
{ "action": "on_play", "client_id": 1985, "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", "stream": "livestream", "pageUrl": "http://a.com/i.html", "param":"?k=v" } |
当客户端开始播放流时 |
on_stop |
{ "action": "on_stop", "client_id": 1985, "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", "stream": "livestream" } |
当客户端停止播放时。备注:停止播放可能不会关闭连接,还能再继续播放。 |
on_dvr |
{ "action": "on_dvr", "client_id": 1985, "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", "stream": "livestream", "cwd": "/opt", "file": "./l.xxx.flv" } |
当DVR录制关闭一个flv文件时 |
其中,
- 事件:发生该事件时,即回调指定的HTTP地址。
- HTTP地址:可以支持多个,以空格分隔,SRS会依次回调这些接口。
- 数据:SRS将数据POST到HTTP接口。
- 返回值:SRS要求HTTP服务器返回HTTP200并且response内容为整数错误码(0表示成功),其他错误码会断开客户端连接。
我们可以根据以上的回调事件处理自己的业务代码。
3、回调测试
SRS HTTP Callback Server
SRS自带了一个默认的处理HTTP Callback的服务器,启动时需要指定端口,譬如8085端口。
启动方法:python research/api-server/server.py 8085
启动日志如下:
[winlin@dev6 srs]$ python research/api-server/server.py 8085
[2014-02-27 09:42:25][trace] api server listen at port: 8085, static_dir: /home/winlin/git/srs/trunk/research/api-server/static-dir
[2014-02-27 09:42:25][trace] start cherrypy server
[27/Feb/2014:09:42:25] ENGINE Listening for SIGHUP.
[27/Feb/2014:09:42:25] ENGINE Listening for SIGTERM.
[27/Feb/2014:09:42:25] ENGINE Listening for SIGUSR1.
[27/Feb/2014:09:42:25] ENGINE Bus STARTING
[27/Feb/2014:09:42:25] ENGINE Started monitor thread '_TimeoutMonitor'.
[27/Feb/2014:09:42:25] ENGINE Started monitor thread 'Autoreloader'.
[27/Feb/2014:09:42:25] ENGINE Serving on 0.0.0.0:8085
[27/Feb/2014:09:42:25] ENGINE Bus STARTED
Publish and Play
推流到SRS时,会调用HTTP接口:
[2014-02-27 09:41:33][trace] post to clients, req={"action":"on_connect","client_id":4,"ip":"192.168.1.179","vhost":"__defaultVhost__","app":"live","pageUrl":""}
[2014-02-27 09:41:33][trace] srs on_connect: client id=4, ip=192.168.1.179, vhost=__defaultVhost__, app=live, pageUrl=
127.0.0.1 - - [27/Feb/2014:09:41:33] "POST /api/v1/clients HTTP/1.1" 200 1 "" "srs(simple rtmp server)0.9.2"
播放SRS的流时,也会调用HTTP接口:
[2014-02-27 09:41:50][trace] post to clients, req={"action":"on_connect","client_id":5,"ip":"192.168.1.179","vhost":"__defaultVhost__","app":"live","pageUrl":"http://dev.chnvideo.com:3080/players/rtmp/"}
[2014-02-27 09:41:50][trace] srs on_connect: client id=5, ip=192.168.1.179, vhost=__defaultVhost__, app=live, pageUrl=http://dev.chnvideo.com:3080/players/rtmp/
127.0.0.1 - - [27/Feb/2014:09:41:50] "POST /api/v1/clients HTTP/1.1" 200 1 "" "srs(simple rtmp server)0.9.2"
SRS搭建流媒体服务器相关推荐
- rtsp-simple-server + srs搭建流媒体服务器
1.下载rtsp-simple-server https://github.com/aler9/rtsp-simple-server/releases 我下载的是windows版本的.下载完后直接运行 ...
- 利用SRS搭建直播服务器
前言 初入公司,调研SRS搭建流媒体服务器,实现直播.点播功能,并搭建基于SRS的流媒体服务器集群. 我们知道,SRS定位是运营级的互联网直播服务器集群,追求更好的概念完整性和最简单实现的代码.SRS ...
- srs服务器播放文件,使用SRS+ffmpeg搭建流媒体服务器播放m3u8格式视频
1.简介 srs是一个简单的流媒体开源直播软件,ffmpeg是完整的跨平台解决方案,用于记录,转换和流传输音频和视频. 2.相关 官网下载页面:点击我到达 在线演示播放页面:点击我到达 Git页面:点 ...
- 使用EasyDarwin + ffmpeg 搭建流媒体服务器,实现多台智能电视同步播放宣传视频
近期单位用户提出需求,需要在单位内部的9台安卓智能电视(小米电视)上同步播放用户提供的宣传视频,希望能够做到所有电视音视频同步播放(电视均位于食堂内部,使用内置扬声器,各电视间音频延迟不同会导致混响) ...
- SRS(simple-rtmp-server)流媒体服务器源码分析--启动
SRS(simple-rtmp-server)流媒体服务器源码分析--系统启动 一.前言 小卒最近看SRS源码,随手写下博客,其一为了整理思路,其二也是为日后翻看方便.如果不足之处,请指教! 首先总结 ...
- ffmpeg libx264_nginx+ffmpeg搭建流媒体服务器(直播流)
这里实现了简单nginx+ffmpeg 推本地mp4视频文件的功能,以后将会继续更新 环境 系统环境:CentOS release 6.7 (Final) 需求 利用nginx和ffmpeg搭建流媒体 ...
- 音视频开发(8)---nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器
nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/redstarofsle ...
- SRS:流媒体服务器如何实现负载均衡
当我们的业务超过单台流媒体服务器的承受能力,就会遇到负载均衡问题,一般我们会在集群中提供这种能力,但实际上集群并非是唯一的实现方式.有时候负载均衡还会和服务发现等时髦词汇联系起来,而云服务的LoadB ...
- obs nginx-rtmp-module搭建流媒体服务器实现直播 ding
欢迎大家来此浏览,希望大家一块在此学习,共同交流进步. 接下来我就简单跟大家介绍一下利用nginx来搭建流媒体服务器. 我选择的是腾讯云服务器 1.下载nginx-rtmp-module: nginx ...
最新文章
- [转]java 为什么wait(),notify(),notifyAll()必须在同步方法/代码块中调用?
- 这周面了阿里,多线程都要问这么难了???
- 【CyberSecurityLearning 20】xu ni zhuan yong wang luo
- android 获取默认存储路径,Android获取外置SD卡存储路径的方法
- 开始使用Python编程
- springboot 多数据源_SpringBoot整合多数据源的巨坑一
- java+对图像进行直线检测_Java调用OpenCV进行Hough变换直线检测
- php.ini路径设置、libmysql.dll加载等
- Mangos源码分析(9):服务器公共组件实现之环形缓冲区
- Spring mvc+ Hibernate的基础dao类。
- Java之函数式接口
- 安装SQL Server 2012 RTM遇到 Microsoft NET Framework 4 0 install
- 跨越适配性能那道坎,企鹅电竞Android weex优化
- Python获取列表list中的非零数据、第一个非零元素、最后一个非零元素
- 概率论得学习和整理6:概率的分布
- [附源码]计算机毕业设计Node.js-报刊征订管理系统(程序+LW)
- NX二次开发-UFUN获取工程图详细信息UF_DRAW_ask_drawing_info
- Java基础系列(三十):局部内部类
- PHPJavaJavascript通用RSA加密
- emq查看状态“node emqx@127.0.0.1 not responding to pings”
热门文章
- 一款在线视频 App,基于 Material Design + MVP + RxJava + Retrofit + Realm + Glide
- python calu()函数_python面向对象
- 带你了解一下蛋白质化学修饰技术!(PEG-β-1,3-GAβ葡聚糖酶/ RNaseA/SAK葡激酶)
- 半导体2013风云榜 美光大跃进
- [剑指 offer]--大顶堆 ➕ 快速选择 --面试题40. 最小的k个数
- Kindle 2 和 iPad,不是零和游戏
- 重庆的大学计算机录取分数线,重庆高校录取分数线排名,4所重点一本,重邮排第5...
- “道德”,究竟是保镖还是杀手?
- Django学习笔记(下)
- 人为什么活着系列之十六:具体的人具体的环境具体分析