LiveNVR安防流媒体服务,支持RTSP稳定拉流接入,支持Onvif协议接入,支持RTMP/HLS/HTTP-FLV分发,将传统安防监控设备互联化,无插件直播等。
LiveNVR相关二次开发-API接口
概述
API采用Restful风格的Http协议,全部请求都使用Get方式,字符不区分大小写。基本结构如下:
http://<IP>:<Port>/api/<Version>/<Action>?<Param1>=<value>&<Param2>=<Value>&.....
参数
<table>
<tr><td>参数名称</td> <td>定义</td> <td>说明</td></tr>
<tr><td>IP</td> <td>Platform Address</td> <td>IP地址</td></tr>
<tr><td>Port</td> <td>Platform Port</td> <td>通讯端口</td></tr>
<tr><td>Version</td> <td>API Version</td> <td>API版本</td></tr>
<tr><td>Action</td> <td>Action</td> <td>执行的操作</td></tr>
<tr><td>Param</td> <td>Action Parameter</td> <td>操作所使用的参数,可以有多个参数,每个参数对应一个Value。</td></tr>
<tr><td>Value</td> <td>Parameter Value</td> <td>参数值,如果Value的字符串中出现&等特殊字符,则必须用””包住Value。</td></tr>
</table>
返回值
调用API会返回Json字符串,代表操作返回的结果
{
"LiveQing" : {
"Body" : {
……
},
"Header" : {
"CSeq" : "1",
"ErrorNum" : "200",
"ErrorString" : "Success OK",
"MessageType" : "MSG_SC_API_ACK",
"Version" : "1.0"
}
}
}
接口列表
1. 登录LiveNVR
- 接口: /api/v1/login?username=xxx&password=xxx
- 参数
<table>
<tr><td>名称</td><td>解释</td><td>含义</td></tr>
<tr><td>Username</td><td>登陆用户名</td><td>-</td></tr>
<tr><td>Password</td><td>登陆密码</td><td>经过MD5加密的32位字符</td></tr>
</table>
-
返回: 200 OK or 401 Unauthorized
{ "LiveQing" : { "Body" : { "Token" : "a19cb5f6e7d2449d8d24c8a0fc554ca7" }, "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_LOGIN_ACK", "Version" : "1.0" } } }
-
操作: 登录,登陆后会返回token,以后调用接口需要在cookie中携带token信息“token=a19cb5f6e7d2449d8d24c8a0fc554ca7”
2. 注销登陆
-
接口: /api/v1/logout
-
返回: 200 OK 401 Unauthorized
{ "LiveQing" : { "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_LOGOUT_ACK", "Version" : "1.0" } } }
-
操作: 再次请求接口需要重新登陆
3. 修改密码
-
接口: /api/v1/modifypassword?oldpassword=xxx&newpassword=xxx
-
参数
<table>
<tr><td>名称</td><td>含义</td><td>备注</td></tr>
<tr><td>Oldpassword</td><td>旧密码</td><td>经过MD5加密的字符</td></tr>
<tr><td>Newpassword</td><td>新密码</td><td>经过MD5加密的字符</td></tr>
</table>
-
返回: 200 OK or 401
{ "LiveQing" : { "Body" : { "Token" : "8b65982a99664d19bcccc35ff8d2acaf" }, "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_MODIFY_PASSWORD_ACK", "Version" : "1.0" } } }
-
操作: 修改密码成功会返回新的token
4. 获取LiveNVR服务信息
- 接口:/api/v1/getserverinfo
- 返回
<table>
<tr><td>名称</td><td>含义</td><td>备注</td></tr>
<tr><td>Server</td><td>服务器软件版本信息</td><td>-</td></tr>
<tr><td>RunningTime</td><td>服务器累计运行时长信息</td><td>-</td></tr>
<tr><td>Hardware</td><td>服务器硬件版本信息</td><td>-</td></tr>
<tr><td>InterfaceVersion</td><td>接口服务版本信息</td><td>-</td></tr>
</table>
-
报文
{ "LiveQing" : { "Body" : { "Hardware" : "x86", "InterfaceVersion" : "v1", "RunningTime" : "30 Days 0 Hours 1 Mins 40 Secs", "Server" : "LiveNVR/1.1 (Build/16.1020; Platform/Win32; State/Development; )" }, "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_INFO_ACK", "Version" : "1.0" } } }
-
操作: 显示
5. 【视频广场】显示所有在线通道预览
- 接口:/api/v1/getchannels[?channel=1]
- 参数
<table>
<tr><td>名称</td><td>含义</td><td>备注</td></tr>
<tr><td>channel</td><td>查询指定通道号的信息</td><td>可选参数。不带channel参数或者channel小于0查看全部通道信息</td></tr>
</table>
-
返回:
- 所有设备列表信息,在线&不在线 通道(包含快照信息)
- 通道名称、通道号、通道快照、通道是否在线
<table>
<tr><td>名称</td><td>含义</td><td>备注</td></tr>
<tr><td>Channel</td><td>通道号</td><td>通道号</td></tr>
<tr><td>Name</td><td>通道名称</td><td>通道名称</td></tr>
<tr><td>Online</td><td>是否在线</td><td>1在线/0离线</td></tr>
<tr><td>SnapURL</td><td>快照地址</td><td>返回为快照的相对网络地址</td></tr>
</table>
-
报文
{ "LiveQing" : { "Body" : { "ChannelCount" : "2", "Channels" : [ { "Channel" : 1, "Name" : "channel1", "Online" : 1, "SnapURL" : "/snap/1/2016-10-24/20161024125212.jpg" }, { "Channel" : 2, "Name" : "channel2", "Online" : 0, "SnapURL" : "" } ] }, "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_GET_CHANNELS_ACK", "Version" : "1.0" } } }
-
操作: H5列表显示
6. 播放单个通道直播
- 接口:/api/v1/getchannelstream?channel=1&protocol=RTMP
- 参数
<table>
<tr><td>名称</td><td>含义</td><td>备注</td></tr>
<tr><td>Channel</td><td>通道号</td><td>-</td></tr>
<tr><td>Protocol</td><td>获取直播的协议</td><td>RTMP/HLS</td></tr>
</table>
- 返回: 直播流地址URL
{
"LiveQing" : {
"Body" : {
"ChannelName" : "通道名"
"URL" : "rtmp://{host}:10035/hls/stream_1"
},
"Header" : {
"CSeq" : "1",
"ErrorNum" : "200",
"ErrorString" : "Success OK",
"MessageType" : "MSG_SC_SERVER_GET_CHANNEL_STREAM_ACK",
"Version" : "1.0"
}
}
}
注:返回的URL中带有{host}占位符,{host}即为api接口请求中的IP字段,如果返回的URL为hls地址,那么直接为/hls/stream_1.m3u8地址,需要前端自动拼接成LiveNVR HTTP播放地址,比如LiveNVR的web访问地址为:http://192.168.66.189:10800/,那么返回的hls应该拼接为http://192.168.66.189:10800/hls/stream_1.m3u8,rtmp地址应该拼接为:rtmp://192.168.66.189:10035/hls/stream_1;
- 操作:调用播放器进行播放
7. 视频播放心跳
-
接口: /api/v1/touchchannelstream?channel=1&line=local&protocol=rtmp
-
参数: 同接口6
-
返回: 直播流地址
{ "LiveQing" : { "Body" : { "ChannelName" : "通道名" "URL" : "rtmp://{host}:10035/hls/stream_1" }, "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_TOUCH_CHANNEL_STREAM_ACK", "Version" : "1.0" } } }
-
操作:播放视频心跳,60秒内发送一次,否则自动停止推流
8. 获取LiveNVR基本配置信息
- 接口: /api/v1/getbaseconfig
- 返回: 基础配置信息表
<table>
<tr><td>名称</td><td>解释</td><td>备注</td></tr>
<tr><td>ServiceLanPort</td><td>LiveNVR服务监听端口</td><td>ReadOnly</td></tr>
<tr><td>ServiceLanIP</td><td>LiveNVR服务本地地址</td><td>ReadOnly</td></tr>
<tr><td>ServiceWanIP</td><td>LiveNVR服务公网端口</td><td>暂时不启作用</td></tr>
<tr><td>ServiceWanPort</td><td>LiveNVR服务公网地址</td><td>暂时不启作用</td></tr>
<tr><td>ChannelSnapInterval</td><td>通道快照间隔</td><td>单位为分钟</td></tr>
<tr><td>NginxRTMPPort</td><td>LiveNVR配套的rtmp服务器端口</td><td>默认10035</td></tr>
</table>
-
报文
{ "LiveQing" : { "Body" : { "ChannelSnapInterval" : "120", "NginxRTMPPort" : "10035", "ServiceLanIP" : "192.168.66.222; 127.0.0.1; ", "ServiceLanPort" : "10010", "ServiceWanIP" : "none-config", "ServiceWanPort" : "10010" }, "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_BASE_CONFIG_ACK", "Version" : "v1" } } }
-
操作:显示
9. 设置LiveNVR基本配置信息
-
接口: /api/v1/setbaseconfig?ChannelSnapInterval=120&NginxRTMPPort=10035&ServiceLanPort=10010&ServiceWanIP="none-config"&ServiceWanPort=10010
-
参数:
<table>
</table> -
返回: 200 OK
{ "LiveQing" : { "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_SET_BASE_CONFIG_ACK", "Version" : "1.0" } } }
-
操作:显示配置成功,重启后生效
10. 发现Onvif设备
-
接口: /api/v1/discoverdevices
-
返回: 200 OK
{ "LiveQing" : { "Body" : { "ChannelCount" : "1", "Channels" : [ { "IP" : "192.168.66.222", "Onvif" : "/onvif/devices", "Port" : 8080 } ] }, "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_DISCOVER_DEVICES_ACK", "Version" : "1.0" } } }
11. 探测设备信息
-
接口: /api/v1/probedevice?ip=192.168.66.222&username=admin&password=admin
-
参数:
<table>
<tr><td>名称</td><td>含义</td><td>备注</td></tr>
<tr><td>Username</td><td>登陆用户名</td><td>设备用户名</td></tr>
<tr><td>Password</td><td>登陆密码</td><td>设备密码(明文)</td></tr>
</table> -
返回:200 OK
{
"LiveQing" : {
"Body" : {
"IP" : "192.168.66.222",
"Onvif" : "/onvif/devices",
"Password" : "admin",
"Port" : "8080",
"Rtsp" : "rtsp://192.168.66.222:554/11",
"UserName" : "admin"
},
"Header" : {
"CSeq" : "1",
"ErrorNum" : "200",
"ErrorString" : "Success OK",
"MessageType" : "MSG_SC_SERVER_PROBE_DEVICE_ACK",
"Version" : "1.0"
}
}
}
12. Onvif云台控制
- 接口:/api/v1/ptzcontrol?channel=1&actiontype=continuous&command=down&speed=5&protocol=onvif
- 参数:
<table>
<tr><td>名称</td><td>含义</td><td>备注</td></tr>
<tr><td>channel</td><td>通道ID</td><td>例:1
</td></tr>
<tr><td>actiontype</td><td>动作类型</td><td>continuous或者single</td></tr>
<tr><td>command</td><td>动作命令</td><td>stop停止、up向上移动、down向下移动、left向左移动、right向右移动、zoomin、zoomout、focusin、focusout、aperturein、apertureout</td></tr>
<tr><td>speed</td><td>动作速度</td><td>例如:5</td></tr>
<tr><td>protocol</td><td>摄像机接入的协议</td><td>暂时仅支持ONVIF接入的摄像机</td></tr>
<tr><td>reserve</td><td>保留</td><td>暂未使用</td></tr>
</table>
只有Onvif类型接入的设备才能支持云台控制功能,同时,设备必须有云台,他才会转动;
13. 单个通道配置
-
接口: /api/v1/setchannelconfig?Cdn=&Channel=2&Enable=0&IP=192.168.66.22&Name=channel2&Onvif=”/device/service”&Password=admin&Port=8080&Protocol=RTSP&Rtsp=”rtsp//192.168.66.22/22”&UserName=admin&OnDemand=1&Audio=1&Reserve2=0
-
参数
<table>
<tr><td>名称 </td><td>含义</td><td>备注</td></tr>
<tr><td>Channel</td><td>设置的通道号</td><td>例如:1</td></tr>
<tr><td>Enable</td><td>通道是否启用</td><td>1启用、0禁用</td></tr>
<tr><td>IP</td><td>摄像机IP地址</td><td>例如:192.168.66.222</td></tr>
<tr><td>Name</td><td>摄像机名称</td><td>例如:测试通道</td></tr>
<tr><td>Port</td><td>摄像端口</td><td>例如:554、8080</td></tr>
<tr><td>Protocol</td><td>摄像机接入的协议</td><td>ONVIF、RTSP</td></tr>
<tr><td>Username</td><td>摄像机登陆用户名</td><td>例如:admin</td></tr>
<tr><td>Password</td><td>摄像机登陆密码</td><td>例如:admin</td></tr>
<tr><td>RTSP</td><td>摄像机的RTSP地址</td><td>例如:rtsp://192.168.66.222/11</td></tr>
<tr><td>ONVIF</td><td>摄像机的Onvif地址 </td><td>/onvif/devices</td></tr>
<tr><td>TransProtocol</td><td>传输协议 </td><td>选项:TCP、UDP</td></tr>
<tr><td>Cdn</td><td>推送的CDN地址</td><td>rtmp://rtmp.aliyun.com/live/209?sign=faefabe&tm=20161005190329</td></tr>
<tr><td>OnDemand</td><td>是否按需直播</td><td>1启用、0不启用</td></tr>
<tr><td>Audio</td><td>是否启用音频输入</td><td>1启用、0不启用</td></tr>
<tr><td>Reserve2</td><td>保留参数2</td><td>1启用、0不启用</td></tr>
</table>
-
返回: 200 OK
{ "LiveQing" : { "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_SET_CHANNEL_CONFIG_ACK", "Version" : "1.0" } } }
-
操作:显示配置成功,即时生效!
14. 获取LiveNVR所有通道信息
-
接口: /api/v1/getchannelsconfig
-
返回: 通道列表数组信息
{ "LiveQing" : { "Body" : { "ChannelCount" : "16", "Channels" : [ { "Cdn" : "", "Channel" : 1, "Enable" : 1, "IP" : "192.168.66.222", "Name" : "channel1", "OnDemand" : 1, "Online" : 1, "Onvif" : "/onvif/devices", "Password" : "admin", "Port" : 8080, "Protocol" : "RTSP", "Rtsp" : "rtsp://192.168.66.222/11", "UserName" : "admin", "Audio" : 0 "Reserve2" : 0 }, { "Cdn" : "", "Channel" : 2, "Enable" : 0, "IP" : "192.168.66.22", "Name" : "channel2", "OnDemand" : 1, "Online" : 0, "Onvif" : "/onvif/devices", "Password" : "admin", "Port" : 8080, "Protocol" : "RTSP", "Rtsp" : "rtsp://192.168.66.22/22", "UserName" : "admin", "Audio" : 1 }, …… ] }, "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_GET_CHANNELS_CONFIG_ACK", "Version" : "1.0" } } }
-
操作:显示,单个通道可禁用/启用/修改配置
15. 抓取图片
-
接口:/api/v1/getsnap?channel=1
-
参数:
<table>
<tr><td>名称</td><td>含义</td><td>备注</td></tr>
<tr><td>channel</td><td>通道号</td><td>-</td></tr>
</table> -
返回:image/jpeg格式,http body为图片数据
16. 开始录像
-
接口:/api/v1/startrecord?channel=1&duration=3600
-
参数:
<table>
<tr><td>名称</td><td>含义</td><td>备注</td></tr>
<tr><td>channel</td><td>通道号</td><td>-</td></tr>
<tr><td>duration</td><td>录像时长,单位秒</td><td>缺省或者为0时,一直录像,直到执行stoprecord接口</td></tr>
</table> -
返回:200 OK
{ "LiveQing" : { "Header" : { "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_START_RECORD_ACK", "Version" : "1.0" } } }
17. 停止录像
-
接口:/api/v1/stoprecord?channel=1
-
参数:
<table>
<tr><td>名称</td><td>含义</td><td>备注</td></tr>
<tr><td>channel</td><td>通道号</td><td>-</td></tr>
</table> -
返回:200 OK
{ "LiveQing" : { "Header" : { "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_STOP_RECORD_ACK", "Version" : "1.0" } } }
18. 获取第三方平台配置
-
接口:/api/v1/getthirdplatformconfig
-
返回:
-
第三方平台类型枚举,例如:LiveQing云端流媒体(LiveQing),QQ互联云平台(QQConnect),海康萤石云平台(EZVIZ)
-
平台地址和端口
-
平台验证信息,例如:用户名、密码、AppKey、SecretKey
{ "LiveQing" : { "Body" : { "ThridPlatform" : "LiveQing", "ThridPlatformAliveInterval" : "90", "ThridPlatformCustomize" : "dev", "ThridPlatformIP" : "www.liveqing.com", "ThridPlatformPort" : "10000", "ThridPlatformToken" : "123456", "ThridPlatformUID" : "NVR00000002" }, "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_GET_THRID_PART_PLATFORM_ACK", "Version" : "1.0" } } }
-
-
操作:显示
19. 设置第三方平台配置
- 接口: /api/v1/setthirdplatformconfig?ThridPlatform=LiveQing&ThridPlatformIP=www.liveqing.com&ThridPlatformPort=10000&ThridPlatformUID=NVR00000002&ThridPlatformAliveInterval=90&ThridPlatformCustomize=dev
-
返回: 200 OK
{ "LiveQing" : { "Header" : { "CSeq" : "1", "ErrorNum" : "200", "ErrorString" : "Success OK", "MessageType" : "MSG_SC_SERVER_SET_THRID_PART_PLATFORM_ACK", "Version" : "1.0" } } }
-
操作:显示配置成功,重启后生效!
20. 重启接口
- 接口: /api/v1/restart
- 返回: 200 OK
- 操作: 显示成功
获取更多信息
安防流媒体互联直播-QQ交流群:615081503
国标GB28181无插件LiveGBS-QQ交流群:947137753
WEB:www.liveqing.com
Tel:189-5515-0114 (同微信)
Copyright © LiveQing.com 2016-2019
网友评论