Skip to content

thinkgos/zlm-http-api

Repository files navigation

zlm-http-api

ZLMediaKit http api and webhook implement.

http restful api

  • 0. /index/api/getApiList 获取API列表

  • 1. /index/api/getThreadsLoad 获取各 epoll(或 select)线程负载以及延时

  • 2. /index/api/getWorkThreadsLoad 获取各后台 epoll(或 select)线程负载以及延时

  • 3. /index/api/getServerConfig 获取服务器配置

  • 4. /index/api/setServerConfig 设置服务器配置

  • 5. /index/api/restartServer 重启服务器, 只有Daemon方式才能重启, 否则是直接关闭!

  • 6. /index/api/getMediaList 获取流列表, 可选筛选参数

  • 7. /index/api/close_stream 关闭流(已过期, 请使用close_streams接口替换)

  • 8. /index/api/close_streams 关闭流(目前所有类型的流都支持关闭), 有人在观看是否强制关闭

  • 9. /index/api/getAllSession 获取所有TcpSession列表(获取所有tcp客户端相关信息)

  • 10. /index/api/kick_session 断开tcp连接, 比如说可以断开rtsp、rtmp播放器等

  • 11. /index/api/kick_sessions 断开tcp连接, 比如说可以断开rtsp、rtmp播放器等

  • 12. /index/api/addStreamProxy 动态添加拉流代理rtsp/rtmp/hls/http-ts/http-flv(只支持 H264/H265/aac/G711/opus 负载)

  • 13. /index/api/delStreamProxy 关闭拉流代理(流注册成功后, 也可以使用close_streams接口替代)

  • 13.1. /index/api/listStreamProxy 获取拉流代理列表

  • 13.2. /index/api/getProxyInfo 获取拉流代理信息

  • 14. /index/api/addFFmpegSource 通过 fork FFmpeg 进程的方式拉流代理, 支持任意协议

  • 15. /index/api/delFFmpegSource 关闭 ffmpeg 拉流代理(流注册成功后, 也可以使用close_streams接口替代)

  • 15.1 /index/api/listFFmpegSource 获取FFmpeg代理

  • 16. /index/api/isMediaOnline 判断直播流是否在线(已过期, 请使用getMediaList接口替代)

  • 17. /index/api/getMediaInfo 获取流相关信息(已过期, 请使用getMediaList接口替代)

  • 18. /index/api/getRtpInfo 获取rtp推流信息

  • 19. /index/api/getMp4RecordFile 搜索文件系统, 获取流对应的录像文件列表或日期文件夹列表

  • 20. /index/api/startRecord 开始录制hls或MP4

  • 21. /index/api/stopRecord 停止录制流

  • 22. /index/api/isRecording 获取流录制状态

  • 22.1. /index/api/deleteRecordDirectory 删除录像文件夹

  • 23. /index/api/getSnap 获取截图或生成实时截图并返回

  • 24. /index/api/openRtpServer 创建GB28181 RTP 接收端口, 如果该端口接收数据超时, 则会自动被回收(不用调用 closeRtpServer 接口)

  • 25. /index/api/closeRtpServer 关闭 GB28181 RTP接收端口

  • 26. /index/api/listRtpServer 获取 openRtpServer 接口创建的所有 RTP 服务器

  • 27. /index/api/startSendRtp 作为GB28181客户端, 启动 ps-rtp 推流, 支持rtp/udp方式.

  • 28. /index/api/stopSendRtp 作为GB28181客户端, 停止GB28181 ps-rtp 推流

  • 29. /index/api/getStatistic 获取主要对象个数统计, 主要用于分析内存性能.

  • 30. /index/api/addStreamPusherProxy 添加rtsp/rtmp主动推流代理(把本服务器的直播流推送到其他服务器去)

  • 31. /index/api/delStreamPusherProxy 关闭推流代理(可以使用close_streams接口关闭源直播流也可以停止推流)

  • 31.1 /index/api/listStreamPusherProxy 获取推流代理列表

  • 31.2 /index/api/getProxyPusherInfo 获取推流代理信息

  • 32. index/api/version 获取版本信息, 如分支, commit id, 编译时间

  • 33. /index/api/getMediaPlayerList 获取某个流观看者列表

  • 100. /index/api/downloadFile 下载文件, 直接下载, 建议加鉴权, 避免任意文件被下载.

    • file_path(必选参数): 文件绝对路径, 根据文件名生成Content-Type该接口将触发on_http_access hook.
    • save_name(可选参数): 浏览器下载文件后保存文件名.

WebHook api

Link: WebHook api

  • on_flow_report 流量统计事件
  • on_http_access 访问http文件服务器上hls之外的文件时触发
  • on_play 播放器鉴权事件(如果rtsp启用专有鉴权, 将不会触发该事件)
  • on_publish 推流鉴权事件
  • on_record_mp4 录制mp4完成后通知事件; 此事件对回复不敏感.
  • on_record_ts 录制hls完成后通知事件; 此事件对回复不敏感.
  • on_rtp_server_timeout 调用openRtpServer接口, rtp server长时间未收到数据, 执行此 web hook, 对回复不敏感.
  • on_send_rtp_stopped 发送rtp(startSendRtp)被动关闭时回调
  • on_rtsp_auth rtsp专用的鉴权事件, 先触发on_rtsp_realm事件然后才会触发on_rtsp_auth事件.
  • on_rtsp_realm 该rtsp流是否开启rtsp专用方式的鉴权事件, 开启后才会触发on_rtsp_auth事件
  • on_shell_login shell登录鉴权, telnet调试方式
  • on_stream_changed rtsp/rtmp 流注册或注销时触发此事件; 此事件对回复不敏感.
  • on_stream_none_reader 流无人观看时事件
  • on_stream_not_found 流未找到事件
  • on_server_started 服务器启动事件
  • on_server_exited 服务器退出事件
  • on_server_keepalive 服务器定时上报, 上报间隔可配置, 默认10s上报一次

播放url规则

详细查看原文档: 播放url规则

1. url的组成部分

rtsp://somedomain.com:554/live/0?token=abcdefg&field=value为例,该url分为以下几个部分:

  • 协议(schema): rtsp 协议, 默认端口 554
  • 虚拟主机(vhost): somedomain.com, 该字段既可以是域名也可以是ip, 如果是ip则对应的虚拟主机为__defaultVhost__
  • 服务端口号(port): 554, 如果不指定端口号, 则使用协议默认端口号
  • 应用名(app): live
  • 流id(streamid): 0
  • 参数(args): token=abcdefg&field=value

2. ZLMediaKit 中的流媒体源

ZLMediaKit中, 流媒体源是一种可以被用于直播转发、推流转发等功能的数据对象, 在本项目中被称作为MediaSource, 目前支持 5 种类型的流媒体源, 分别是RtspMediaSourceRtmpMediaSourceHlsMediaSourceTSMediaSourceFMP4MediaSource.

定位一个流媒体源, 主要通过4个元素(我们后续称其为4元组), 分别是:

  • 协议(scheam)
  • 虚拟主机(vhost)
  • 应用名(app)
  • 流id(streamid)

RtspMediaSource支持 rtsp 播放、rtsp 推流、webrtc 播放、webrtc 推流. RtmpMediaSource支持 rtmp 推流/播放、http-flv 播放、ws-flv 播放. HlsMediaSource支持 hls 播放. TSMediaSource 支持 http-ts 播放、ws-ts 播放. FMP4MediaSource支持 http-fmp4 播放、ws-fmp4 播放.

主流摄像头rtsp地址

大华

rtsp://<username>:<password>@<ip>:<port>/cam/realmonitor?channel=<channel>&subtype=<subtype>

  • username: 登录用户名
  • password: 登录密码
  • ip: 摄像头ip地址
  • port: 摄像头端口号, 默认554可省略
  • channel: 通道号, 通常从1开始,
  • subtype: 码流类型, 一般为0表示主码流(高清), 1表示子码流(低码率).

宇视

rtsp://<username>:<password>@<ip>:<port>/Streaming/Channels/<channel>0<stream>

  • username: 登录用户名
  • password: 登录密码
  • ip: 摄像头ip地址
  • port: 摄像头端口号, 默认554可省略
  • channel: 通道号(1表示第一路, 2表示第二路)
  • stream: 码流类型(1表示主码流, 2表示子码流)

License

MIT

About

ZLMediaKit go http api and webhook implement

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages