mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-06 11:38:11 +08:00
Created MediaServer支持的HTTP API (markdown)
436
MediaServer支持的HTTP-API.md
Normal file
436
MediaServer支持的HTTP-API.md
Normal file
@@ -0,0 +1,436 @@
|
||||
## ZLMediaKit支持的http api
|
||||
|
||||
ZLMediaKit目前支持以下http api接口,这些接口全部支持GET/POST方式,
|
||||
|
||||
```
|
||||
"/index/api/addFFmpegSource",
|
||||
"/index/api/addStreamProxy",
|
||||
"/index/api/close_stream",
|
||||
"/index/api/delFFmepgSource",
|
||||
"/index/api/delStreamProxy",
|
||||
"/index/api/getAllSession",
|
||||
"/index/api/getApiList",
|
||||
"/index/api/getMediaList",
|
||||
"/index/api/getServerConfig",
|
||||
"/index/api/getThreadsLoad",
|
||||
"/index/api/kick_session",
|
||||
"/index/api/restartServer",
|
||||
"/index/api/setServerConfig",
|
||||
|
||||
```
|
||||
|
||||
其中POST方式,参数既可以使用urlencoded方式也可以使用json方式。
|
||||
操作这些api一般需要提供secret参数以便鉴权,如果操作ip是127.0.0.1,那么可以无需鉴权。
|
||||
|
||||
|
||||
## API详解
|
||||
|
||||
- `/index/api/getThreadsLoad`
|
||||
|
||||
- 功能:获取各epoll(或select)线程负载以及延时
|
||||
|
||||
- 范例:[http://127.0.0.1/index/api/getThreadsLoad](http://127.0.0.1/index/api/getThreadsLoad)
|
||||
|
||||
- 参数:无
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"data" : [
|
||||
{
|
||||
"delay" : 0, #该线程延时
|
||||
"load" : 0 #该线程负载,0 ~ 100
|
||||
},
|
||||
{
|
||||
"delay" : 0,
|
||||
"load" : 0
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
- `/index/api/getServerConfig`
|
||||
|
||||
- 功能:获取服务器配置
|
||||
|
||||
- 范例:[http://127.0.0.1/index/api/getServerConfig](http://127.0.0.1/index/api/getServerConfig)
|
||||
|
||||
- 参数:
|
||||
|
||||
| 参数 | 是否必选 | 释意 |
|
||||
| :----: | :------: | :----------------------------------------------------------: |
|
||||
| secret | Y | api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数 |
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"code" : 0,
|
||||
"data" : [
|
||||
{
|
||||
"api.apiDebug" : "1",
|
||||
"api.secret" : "035c73f7-bb6b-4889-a715-d9eb2d1925cc",
|
||||
"ffmpeg.bin" : "/usr/local/bin/ffmpeg",
|
||||
"ffmpeg.cmd" : "%s -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s",
|
||||
"ffmpeg.log" : "/Users/xzl/git/ZLMediaKit/cmake-build-debug/bin/ffmpeg/ffmpeg.log",
|
||||
"general.enableVhost" : "1",
|
||||
"general.flowThreshold" : "1024",
|
||||
"general.maxStreamWaitMS" : "5000",
|
||||
"general.streamNoneReaderDelayMS" : "5000",
|
||||
"hls.fileBufSize" : "65536",
|
||||
"hls.filePath" : "/Users/xzl/git/ZLMediaKit/cmake-build-debug/bin/httpRoot",
|
||||
"hls.segDur" : "3",
|
||||
"hls.segNum" : "3",
|
||||
"hook.access_file_except_hls" : "1",
|
||||
"hook.admin_params" : "secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc",
|
||||
"hook.enable" : "1",
|
||||
"hook.on_flow_report" : "https://127.0.0.1/index/hook/on_flow_report",
|
||||
"hook.on_http_access" : "https://127.0.0.1/index/hook/on_http_access",
|
||||
"hook.on_play" : "https://127.0.0.1/index/hook/on_play",
|
||||
"hook.on_publish" : "https://127.0.0.1/index/hook/on_publish",
|
||||
"hook.on_record_mp4" : "https://127.0.0.1/index/hook/on_record_mp4",
|
||||
"hook.on_rtsp_auth" : "https://127.0.0.1/index/hook/on_rtsp_auth",
|
||||
"hook.on_rtsp_realm" : "https://127.0.0.1/index/hook/on_rtsp_realm",
|
||||
"hook.on_shell_login" : "https://127.0.0.1/index/hook/on_shell_login",
|
||||
"hook.on_stream_changed" : "https://127.0.0.1/index/hook/on_stream_changed",
|
||||
"hook.on_stream_none_reader" : "https://127.0.0.1/index/hook/on_stream_none_reader",
|
||||
"hook.on_stream_not_found" : "https://127.0.0.1/index/hook/on_stream_not_found",
|
||||
"hook.timeoutSec" : "10",
|
||||
"http.charSet" : "utf-8",
|
||||
"http.keepAliveSecond" : "100",
|
||||
"http.maxReqCount" : "100",
|
||||
"http.maxReqSize" : "4096",
|
||||
"http.notFound" : "<html><head><title>404 Not Found</title></head><body bgcolor=\"white\"><center><h1>您访问的资源不存在!</h1></center><hr><center>ZLMediaKit-4.0</center></body></html>",
|
||||
"http.port" : "80",
|
||||
"http.rootPath" : "/Users/xzl/git/ZLMediaKit/cmake-build-debug/bin/httpRoot",
|
||||
"http.sendBufSize" : "65536",
|
||||
"http.sslport" : "443",
|
||||
"multicast.addrMax" : "239.255.255.255",
|
||||
"multicast.addrMin" : "239.0.0.0",
|
||||
"multicast.udpTTL" : "64",
|
||||
"record.appName" : "record",
|
||||
"record.filePath" : "/Users/xzl/git/ZLMediaKit/cmake-build-debug/bin/httpRoot",
|
||||
"record.fileSecond" : "3600",
|
||||
"record.sampleMS" : "100",
|
||||
"rtmp.handshakeSecond" : "15",
|
||||
"rtmp.keepAliveSecond" : "15",
|
||||
"rtmp.modifyStamp" : "1",
|
||||
"rtmp.port" : "1935",
|
||||
"rtp.audioMtuSize" : "600",
|
||||
"rtp.clearCount" : "10",
|
||||
"rtp.cycleMS" : "46800000",
|
||||
"rtp.maxRtpCount" : "50",
|
||||
"rtp.videoMtuSize" : "1400",
|
||||
"rtsp.authBasic" : "0",
|
||||
"rtsp.handshakeSecond" : "15",
|
||||
"rtsp.keepAliveSecond" : "15",
|
||||
"rtsp.port" : "554",
|
||||
"rtsp.sslport" : "322",
|
||||
"shell.maxReqSize" : "1024",
|
||||
"shell.port" : "9000"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
- `/index/api/setServerConfig`
|
||||
|
||||
- 功能:设置服务器配置
|
||||
- 范例:[http://127.0.0.1/index/api/setServerConfig?api.apiDebug=0(例如关闭http api调试)](http://127.0.0.1/index/api/setServerConfig?api.apiDebug=0)
|
||||
|
||||
- 参数:
|
||||
|
||||
| 参数 | 是否必选 | 释意 |
|
||||
| :----: | :------: | :----------------------------------------------------------: |
|
||||
| secret | Y | api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数 |
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"changed" : 0, #配置项变更个数
|
||||
"code" : 0 #0代表成功
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
- `/index/api/restartServer`
|
||||
|
||||
- 功能:重启服务器,只有Daemon方式才能重启,否则是直接关闭!
|
||||
|
||||
- 范例:[http://127.0.0.1/index/api/restartServer](http://127.0.0.1/index/api/restartServer)
|
||||
|
||||
- 参数:
|
||||
|
||||
| 参数 | 是否必选 | 释意 |
|
||||
| :----: | :------: | :----------------------------------------------------------: |
|
||||
| secret | Y | api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数 |
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"code" : 0,
|
||||
"msg" : "服务器将在一秒后自动重启"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
- `/index/api/getMediaList`
|
||||
|
||||
- 功能:获取流列表,可选筛选参数
|
||||
|
||||
- 范例:[http://127.0.0.1/index/api/getMediaList](http://127.0.0.1/index/api/getMediaList)
|
||||
|
||||
- 参数:
|
||||
|
||||
| 参数 | 是否必选 | 释意 |
|
||||
| :----: | :------: | :----------------------------------------------------------: |
|
||||
| secret | Y | api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数 |
|
||||
| schema | N | 筛选协议,例如 rtsp或rtmp |
|
||||
| vhost | N | 筛选虚拟主机,例如`__defaultVost__` |
|
||||
| app | N | 筛选应用名,例如 live |
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"code" : 0,
|
||||
"data" : [
|
||||
{
|
||||
"app" : "live",
|
||||
"schema" : "rtsp",
|
||||
"stream" : "0",
|
||||
"vhost" : "__defaultVhost__"
|
||||
},
|
||||
{
|
||||
"app" : "live",
|
||||
"schema" : "rtmp",
|
||||
"stream" : "0",
|
||||
"vhost" : "__defaultVhost__"
|
||||
}
|
||||
],
|
||||
"msg" : "success"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
- `/index/api/close_stream`
|
||||
|
||||
- 功能:关闭流(目前所有类型的流都支持关闭)
|
||||
|
||||
- 范例:[http://127.0.0.1/index/api/close_stream?schema=rtmp&vhost=`__defaultVhost__`&app=live&stream=0&force=1](http://127.0.0.1/index/api/close_stream?schema=rtmp&vhost=__defaultVhost__&app=live&stream=0&force=1)
|
||||
|
||||
- 参数:
|
||||
|
||||
| 参数 | 是否必选 | 释意 |
|
||||
| :----: | :------: | :----------------------------------------------------------: |
|
||||
| secret | Y | api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数 |
|
||||
| schema | Y | 协议,例如 rtsp或rtmp |
|
||||
| vhost | Y | 虚拟主机,例如`__defaultVost__` |
|
||||
| app | Y | 应用名,例如 live |
|
||||
| stream | Y | 流id,例如 test |
|
||||
| force | N | 是否强制关闭(有人在观看是否还关闭) |
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"code" : 0,# 0:成功,-1:关闭失败,-2:该流不存在
|
||||
"msg" : "success"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
- `/index/api/getAllSession`
|
||||
|
||||
- 功能:获取所有TcpSession列表(获取所有tcp客户端相关信息)
|
||||
|
||||
- 范例:[http://127.0.0.1/index/api/getAllSession](http://127.0.0.1/index/api/getAllSession)
|
||||
|
||||
- 参数:
|
||||
|
||||
| 参数 | 是否必选 | 释意 |
|
||||
| :--------: | :------: | :----------------------------------------------------------: |
|
||||
| secret | Y | api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数 |
|
||||
| local_port | N | 筛选本机端口,例如筛选rtsp链接:554 |
|
||||
| peer_ip | N | 筛选客户端ip |
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"code" : 0,
|
||||
"data" : [
|
||||
{
|
||||
"id" : "140614477848784",
|
||||
"local_ip" : "127.0.0.1",
|
||||
"local_port" : 80,
|
||||
"peer_ip" : "127.0.0.1",
|
||||
"peer_port" : 51136,
|
||||
"typeid" : "16WebSocketSessionI11EchoSessionN8mediakit11HttpSessionEE"
|
||||
},
|
||||
{
|
||||
"id" : "140614443300192",
|
||||
"local_ip" : "127.0.0.1",
|
||||
"local_port" : 80,
|
||||
"peer_ip" : "127.0.0.1",
|
||||
"peer_port" : 51135,
|
||||
"typeid" : "16WebSocketSessionI11EchoSessionN8mediakit11HttpSessionEE"
|
||||
},
|
||||
{
|
||||
"id" : "140614440178720", # 该tcp链接唯一id
|
||||
"local_ip" : "127.0.0.1", # 本机网卡ip
|
||||
"local_port" : 1935, # 本机端口号 (这是个rtmp播放器或推流器)
|
||||
"peer_ip" : "127.0.0.1", # 客户端ip
|
||||
"peer_port" : 51130, # 客户端端口号
|
||||
"typeid" : "N8mediakit11RtmpSessionE" # 客户端TCPSession typeid
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
- `/index/api/kick_session`
|
||||
|
||||
- 功能:断开tcp连接,比如说可以断开rtsp、rtmp播放器等
|
||||
|
||||
- 范例:[http://127.0.0.1/index/api/kick_session?id=140614440178720](http://127.0.0.1/index/api/kick_session?id=140614440178720)
|
||||
|
||||
- 参数:
|
||||
|
||||
| 参数 | 是否必选 | 释意 |
|
||||
| :----: | :------: | :----------------------------------------------------------: |
|
||||
| secret | Y | api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数 |
|
||||
| Id | Y | 客户端唯一id,可以通过getAllSession接口获取 |
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"code" : 0,
|
||||
"msg" : "success"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
- `/index/api/addStreamProxy`
|
||||
|
||||
- 功能:动态添加rtsp/rtmp拉流代理(只支持H264/H265/aac负载)
|
||||
- 范例:[http://127.0.0.1/index/api/addStreamProxy?vhost=`__defaultVhost__`&app=proxy&stream=0&url=rtmp://live.hkstv.hk.lxdns.com/live/hks2](http://127.0.0.1/index/api/addStreamProxy?vhost=__defaultVhost__&app=proxy&stream=0&url=rtmp://live.hkstv.hk.lxdns.com/live/hks2)
|
||||
|
||||
- 参数:
|
||||
|
||||
| 参数 | 是否必选 | 释意 |
|
||||
| :--------: | :------: | :----------------------------------------------------------: |
|
||||
| secret | Y | api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数 |
|
||||
| vhost | Y | 添加的流的虚拟主机,例如`__defaultVhost__` |
|
||||
| app | Y | 添加的流的应用名,例如live |
|
||||
| stream | Y | 添加的流的id名,例如test |
|
||||
| url | Y | 拉流地址,例如rtmp://live.hkstv.hk.lxdns.com/live/hks2 |
|
||||
| enable_hls | N | 是否转hls |
|
||||
| enable_mp4 | N | 是否mp4录制 |
|
||||
| rtp_type | N | rtsp拉流时,拉流方式,0:tcp,1:udp,2:组播 |
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"code" : 0,
|
||||
"data" : {
|
||||
"key" : "__defaultVhost__/proxy/0" # 流的唯一标识
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
- `/index/api/delStreamProxy`
|
||||
|
||||
- 功能:关闭拉流代理
|
||||
- 范例:[http://127.0.0.1/index/api/delStreamProxy?key=`__defaultVhost__`/proxy/0](http://127.0.0.1/index/api/delStreamProxy?key=__defaultVhost__/proxy/0)
|
||||
|
||||
- 参数:
|
||||
|
||||
| 参数 | 是否必选 | 释意 |
|
||||
| :----: | :------: | :----------------------------------------------------------: |
|
||||
| secret | Y | api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数 |
|
||||
| key | Y | addStreamProxy接口返回的key |
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"code" : 0,
|
||||
"data" : {
|
||||
"flag" : true # 成功与否
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
- `/index/api/addFFmpegSource`
|
||||
|
||||
- 功能:通过fork FFmpeg进程的方式拉流代理,支持任意协议
|
||||
- 范例:[http://127.0.0.1/index/api/addFFmpegSource?src_url=http://live.hkstv.hk.lxdns.com/live/hks2/playlist.m3u8&dst_url=rtmp://127.0.0.1/live/hks2&timeout_ms=10000](http://127.0.0.1/index/api/addFFmpegSource?src_url=http://live.hkstv.hk.lxdns.com/live/hks2/playlist.m3u8&dst_url=rtmp://127.0.0.1/live/hks2&timeout_ms=10000)
|
||||
- 参数:
|
||||
|
||||
| 参数 | 是否必选 | 释意 |
|
||||
| :--------: | :------: | :----------------------------------------------------------: |
|
||||
| secret | Y | api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数 |
|
||||
| src_url | Y | FFmpeg拉流地址,支持任意协议或格式(只要FFmpeg支持即可) |
|
||||
| dst_url | Y | FFmpeg rtmp推流地址,一般都是推给自己,例如rtmp://127.0.0.1/live/stream_form_ffmpeg |
|
||||
| timeout_ms | Y | FFmpeg推流成功超时时间 |
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"code" : 0,
|
||||
"data" : {
|
||||
"key" : "5f748d2ef9712e4b2f6f970c1d44d93a" #唯一key
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
- `/index/api/delFFmepgSource`
|
||||
|
||||
- 功能:关闭ffmpeg拉流代理
|
||||
- 范例:[http://127.0.0.1/index/api/delFFmepgSource?key=5f748d2ef9712e4b2f6f970c1d44d93a](http://127.0.0.1/index/api/delFFmepgSource?key=5f748d2ef9712e4b2f6f970c1d44d93a)
|
||||
|
||||
- 参数:
|
||||
|
||||
| 参数 | 是否必选 | 释意 |
|
||||
| :----: | :------: | :----------------------------------------------------------: |
|
||||
| secret | Y | api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数 |
|
||||
| key | Y | addFFmpegSource接口返回的key |
|
||||
|
||||
|
||||
- 响应:
|
||||
|
||||
```json
|
||||
{
|
||||
"code" : 0,
|
||||
"data" : {
|
||||
"flag" : true # 成功与否
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user