跳至主要內容

Web Hook 接口

ZLMediaKit大约 16 分钟

HOOK 预览

MediaServer 可以把内部的一些事件通过 http post 第三方 http 服务器的方式通知出去,以下是相关的默认配置:

[hook]
enable=1
admin_params=secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc
timeoutSec=10

on_flow_report=https://127.0.0.1/index/hook/on_flow_report
on_http_access=https://127.0.0.1/index/hook/on_http_access
on_play=https://127.0.0.1/index/hook/on_play
on_publish=https://127.0.0.1/index/hook/on_publish
on_record_mp4=https://127.0.0.1/index/hook/on_record_mp4
on_rtsp_auth=https://127.0.0.1/index/hook/on_rtsp_auth
on_rtsp_realm=https://127.0.0.1/index/hook/on_rtsp_realm
on_shell_login=https://127.0.0.1/index/hook/on_shell_login
on_stream_changed=https://127.0.0.1/index/hook/on_stream_changed
on_stream_none_reader=https://127.0.0.1/index/hook/on_stream_none_reader
on_stream_not_found=https://127.0.0.1/index/hook/on_stream_not_found
on_server_started=https://127.0.0.1/index/hook/on_server_started
on_server_keepalive=https://127.0.0.1/index/hook/on_server_keepalive
on_rtp_server_timeout=https://127.0.0.1/index/hook/on_rtp_server_timeout

如果是鉴权事件,且访问 IP 是127.0.0.1或者鉴权 url 参数与admin_params一致,那么会直接鉴权成功(不会触发鉴权 web hook)。

大家也可以参考此issueopen in new window

详解

1、enable :

  • 解释:

    是否开启 http hook,如果选择关闭,ZLMediaKit 将采取默认动作(例如不鉴权等)

2、timeoutSec:

  • 解释:

    事件触发 http post 超时时间。

3、admin_params:

  • 解释:

    超级管理员的 url 参数,如果访问者 url 参数与此一致,那么 rtsp/rtmp/hls/http-flv/ws-flv 播放或推流将无需鉴权。该选项用于开发者调试用。

4、on_flow_report:

  • 解释:

    流量统计事件,播放器或推流器断开时并且耗用流量超过特定阈值时会触发此事件,阈值通过配置文件 general.flowThreshold 配置;此事件对回复不敏感。

  • 触发请求:

    POST /index/hook/on_flow_report HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 298
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "mediaServerId" : "your_server_id",
       "app" : "live",
       "duration" : 6,
       "params" : "token=1677193e-1244-49f2-8868-13b3fcc31b17",
       "player" : false,
       "schema" : "rtmp",
       "stream" : "obs",
       "totalBytes" : 1508161,
       "vhost" : "__defaultVhost__",
       "ip" : "192.168.0.21",
       "port" : 55345,
       "id" : "140259799100960"
    }
    
  • 请求参数详解:

    参数名参数类型参数解释
    appstring流应用名
    durationinttcp 链接维持时间,单位秒
    paramsstring推流或播放 url 参数
    playerbooltrue 为播放器,false 为推流器
    schemastring播放或推流的协议,可能是 rtsp、rtmp、http
    streamstring流 ID
    totalBytesint耗费上下行流量总和,单位字节
    vhoststring流虚拟主机
    ipstring客户端 ip
    portint客户端端口号
    idstringTCP 链接唯一 ID
    mediaServerIdstring服务器 id,通过配置文件设置
  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 40
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 07:09:32 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
       "code" : 0,
       "msg" : "success"
    }
    
    

5、on_http_access:

  • 解释:

    访问 http 文件服务器上 hls 之外的文件时触发。

  • 触发请求:

    POST /index/hook/on_http_access HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 583
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "mediaServerId" : "your_server_id",
       "header.Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
       "header.Accept-Encoding" : "gzip, deflate",
       "header.Accept-Language" : "en-US,en;q=0.5",
       "header.Cache-Control" : "max-age=0",
       "header.Connection" : "keep-alive",
       "header.Host" : "10.0.17.132",
       "header.Upgrade-Insecure-Requests" : "1",
       "header.User-Agent" : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0",
       "id" : "140259799100960",
       "ip" : "10.0.17.132",
       "is_dir" : true,
       "params" : "",
       "path" : "/live/",
       "port" : 65073
    }
    
    
  • 请求参数详解:

    参数名参数类型参数解释
    header.*stringhttp 客户端请求 header
    idstringTCP 链接唯一 ID
    ipstringhttp 客户端 ip
    is_dirboolhttp 访问路径是文件还是目录
    paramsstringhttp url 参数
    pathstring请求访问的文件或目录
    portunsigned shorthttp 客户端端口号
    mediaServerIdstring服务器 id,通过配置文件设置
  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 68
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 07:27:01 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
       "code" : 0,
       "err" : "",
       "path" : "",
       "second" : 600
    }
    
    
  • 回复参数详解:

    参数名参数类型参数解释
    codeint请固定返回 0
    errstring不允许访问的错误提示,允许访问请置空
    pathstring该客户端能访问或被禁止的顶端目录,如果为空字符串,则表述为当前目录
    secondint本次授权结果的有效期,单位秒
    mediaServerIdstring服务器 id,通过配置文件设置

6、on_play:

  • 解释:

    播放器鉴权事件,rtsp/rtmp/http-flv/ws-flv/hls 的播放都将触发此鉴权事件; 如果流不存在,那么先触发 on_play 事件然后触发 on_stream_not_found 事件。 播放 rtsp 流时,如果该流启动了 rtsp 专属鉴权(on_rtsp_realm)那么将不再触发 on_play 事件。

  • 触发请求:

    POST /index/hook/on_play HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 189
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "mediaServerId" : "your_server_id",
       "app" : "live",
       "id" : "140574554588960",
       "ip" : "10.0.17.132",
       "params" : "",
       "port" : 65217,
       "schema" : "rtmp",
       "stream" : "obs",
       "vhost" : "__defaultVhost__"
    }
    
    
  • 请求参数详解:

    参数名参数类型参数解释
    appstring流应用名
    idstringTCP 链接唯一 ID
    ipstring播放器 ip
    paramsstring播放 url 参数
    portunsigned short播放器端口号
    schemastring播放的协议,可能是 rtsp、rtmp、http
    streamstring流 ID
    vhoststring流虚拟主机
    mediaServerIdstring服务器 id,通过配置文件设置
  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 40
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 07:41:21 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
       "code" : 0,
       "msg" : "success"
    }
    
    
  • 回复参数详解:

    参数名参数类型参数解释
    codeint错误代码,0 代表允许播放
    msgstring不允许播放时的错误提示

7、on_publish:

  • 解释:

    rtsp/rtmp/rtp 推流鉴权事件。

  • 触发请求:

    POST /index/hook/on_publish HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 231
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "mediaServerId" : "your_server_id",
       "app" : "live",
       "id" : "140186529001776",
       "ip" : "10.0.17.132",
       "params" : "token=1677193e-1244-49f2-8868-13b3fcc31b17",
       "port" : 65284,
       "schema" : "rtmp",
       "stream" : "obs",
       "vhost" : "__defaultVhost__"
    }
    
    
  • 请求参数详解:

    参数名参数类型参数解释
    appstring流应用名
    idstringTCP 链接唯一 ID
    ipstring推流器 ip
    paramsstring推流 url 参数
    portunsigned short推流器端口号
    schemastring推流的协议,可能是 rtsp、rtmp
    streamstring流 ID
    vhoststring流虚拟主机
    mediaServerIdstring服务器 id,通过配置文件设置
  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 89
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 07:46:43 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
     "code" : 0,
     "add_mute_audio" : true,
     "continue_push_ms" : 10000,
     "enable_audio" : true,
     "enable_fmp4" : true,
     "enable_hls" : true,
     "enable_hls_fmp4" : false,
     "enable_mp4" : false,
     "enable_rtmp" : true,
     "enable_rtsp" : true,
     "enable_ts" : true,
     "hls_save_path" : "/hls_save_path/",
     "modify_stamp" : false,
     "mp4_as_player" : false,
     "mp4_max_second" : 3600,
     "mp4_save_path" : "/mp4_save_path/",
     "auto_close" : false,
     "stream_replace" : ""
    }
    
    
  • 回复参数详解:

    参数名参数类型参数解释必须参数
    codeint错误代码,0 代表允许推流Y
    msgstring不允许推流时的错误提示Y
    enable_hlsbool是否转换成 hls-mpegts 协议N
    enable_hls_fmp4bool是否转换成 hls-fmp4 协议N
    enable_mp4bool是否允许 mp4 录制N
    enable_rtspbool是否转 rtsp 协议N
    enable_rtmpbool是否转 rtmp/flv 协议N
    enable_tsbool是否转 http-ts/ws-ts 协议N
    enable_fmp4bool是否转 http-fmp4/ws-fmp4 协议N
    hls_demandbool该协议是否有人观看才生成N
    rtsp_demandbool该协议是否有人观看才生成N
    rtmp_demandbool该协议是否有人观看才生成N
    ts_demandbool该协议是否有人观看才生成N
    fmp4_demandbool该协议是否有人观看才生成N
    enable_audiobool转协议时是否开启音频N
    add_mute_audiobool转协议时,无音频是否添加静音 aac 音频N
    mp4_save_pathstringmp4 录制文件保存根目录,置空使用默认N
    mp4_max_secondintmp4 录制切片大小,单位秒N
    mp4_as_playerboolMP4 录制是否当作观看者参与播放人数计数N
    hls_save_pathstringhls 文件保存保存根目录,置空使用默认N
    modify_stampint该流是否开启时间戳覆盖(0:绝对时间戳/1:系统时间戳/2:相对时间戳)N
    continue_push_msuint32断连续推延时,单位毫秒,置空使用配置文件默认值N
    auto_closebool无人观看是否自动关闭流(不触发无人观看 hook)N
    stream_replacestring是否修改流 id, 通过此参数可以自定义流 id(譬如替换 ssrc)N

8、on_record_mp4:

  • 解释:

    录制 mp4 完成后通知事件;此事件对回复不敏感。

  • 触发请求:

    POST /index/hook/on_record_mp4 HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 473
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "mediaServerId" : "your_server_id",
       "app" : "live",
       "file_name" : "15-53-02.mp4",
       "file_path" : "/root/zlmediakit/httpRoot/__defaultVhost__/record/live/obs/2019-09-20/15-53-02.mp4",
       "file_size" : 1913597,
       "folder" : "/root/zlmediakit/httpRoot/__defaultVhost__/record/live/obs/",
       "start_time" : 1568965982,
       "stream" : "obs",
       "time_len" : 11.0,
       "url" : "record/live/obs/2019-09-20/15-53-02.mp4",
       "vhost" : "__defaultVhost__"
    }
    
  • 请求参数详解:

    参数名参数类型参数解释
    appstring录制的流应用名
    file_namestring文件名
    file_pathstring文件绝对路径
    file_sizeint文件大小,单位字节
    folderstring文件所在目录路径
    start_timeint开始录制时间戳
    streamstring录制的流 ID
    time_lenfloat录制时长,单位秒
    urlstringhttp/rtsp/rtmp 点播相对 url 路径
    vhoststring流虚拟主机
    mediaServerIdstring服务器 id,通过配置文件设置
  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 40
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 07:53:13 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
       "code" : 0,
       "msg" : "success"
    }
    

9、on_rtsp_realm:

  • 解释:

    该 rtsp 流是否开启 rtsp 专用方式的鉴权事件,开启后才会触发 on_rtsp_auth 事件。

    需要指出的是 rtsp 也支持 url 参数鉴权,它支持两种方式鉴权。

  • 触发请求:

    POST /index/hook/on_rtsp_realm HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 189
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "mediaServerId" : "your_server_id",
       "app" : "live",
       "id" : "140553560034336",
       "ip" : "10.0.17.132",
       "params" : "",
       "port" : 65473,
       "schema" : "rtsp",
       "stream" : "obs",
       "vhost" : "__defaultVhost__"
    }
    
  • 请求参数详解:

    参数名参数类型参数解释
    appstring流应用名
    idstringTCP 链接唯一 ID
    ipstringrtsp 播放器 ip
    paramsstring播放 rtsp url 参数
    portunsigned shortrtsp 播放器端口号
    schemastringrtsp 或 rtsps
    streamstring流 ID
    vhoststring流虚拟主机
    mediaServerIdstring服务器 id,通过配置文件设置
  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 51
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 08:05:49 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
       "code" : 0,
       "realm" : "zlmediakit_reaml"
    }
    
    
  • 回复参数详解:

    参数名参数类型参数解释
    codeint请固定返回 0
    realmstring该 rtsp 流是否需要 rtsp 专有鉴权,空字符串代码不需要鉴权

10、on_rtsp_auth:

  • 解释:

    rtsp 专用的鉴权事件,先触发 on_rtsp_realm 事件然后才会触发 on_rtsp_auth 事件。

  • 触发请求:

    POST /index/hook/on_rtsp_auth HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 274
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "mediaServerId" : "your_server_id",
       "app" : "live",
       "id" : "140553560034336",
       "ip" : "10.0.17.132",
       "must_no_encrypt" : false,
       "params" : "",
       "port" : 65473,
       "realm" : "zlmediakit_reaml",
       "schema" : "rtsp",
       "stream" : "obs",
       "user_name" : "test",
       "vhost" : "__defaultVhost__"
    }
    
    
  • 请求参数详解:

    参数名参数类型参数解释
    appstring流应用名
    idstringTCP 链接唯一 ID
    ipstringrtsp 播放器 ip
    must_no_encryptbool请求的密码是否必须为明文(base64 鉴权需要明文密码)
    paramsstringrtsp url 参数
    portunsigned shortrtsp 播放器端口号
    realmstringrtsp 播放鉴权加密 realm
    schemastringrtsp 或 rtsps
    streamstring流 ID
    user_namestring播放用户名
    vhoststring流虚拟主机
    mediaServerIdstring服务器 id,通过配置文件设置
  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 61
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 08:05:49 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
       "code" : 0,
       "encrypted" : false,
       "passwd" : "test"
    }
    
    
  • 回复参数详解:

    参数名参数类型参数解释
    codeint错误代码,0 代表允许播放
    msgstring播放鉴权失败时的错误提示
    encryptedbool用户密码是明文还是摘要
    passwdstring用户密码明文或摘要(md5(username:realm:password))

11、on_shell_login:

  • 解释:

    shell 登录鉴权,ZLMediaKit 提供简单的 telnet 调试方式

    使用telnet 127.0.0.1 9000能进入 MediaServer 进程的 shell 界面。

  • 触发请求:

    POST /index/hook/on_shell_login HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 124
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "mediaServerId" : "your_server_id",
       "id" : "140227419332496",
       "ip" : "10.0.17.132",
       "passwd" : "111111",
       "port" : 49242,
       "user_name" : "xzl"
    }
    
  • 请求参数详解:

    参数名参数类型参数解释
    idstringTCP 链接唯一 ID
    ipstringtelnet 终端 ip
    passwdbooltelnet 终端登录用户密码
    portunsigned shorttelnet 终端端口号
    user_namestringtelnet 终端登录用户名
    mediaServerIdstring服务器 id,通过配置文件设置
  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 40
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 08:23:00 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
       "code" : 0,
       "msg" : "success"
    }
    
  • 回复参数详解:

    参数名参数类型参数解释
    codeint错误代码,0 代表允许登录 telnet
    msgstring不允许登录 telnet 时的错误提示

12、on_stream_changed:

  • 解释:

    rtsp/rtmp 流注册或注销时触发此事件;此事件对回复不敏感。

  • 触发请求:

    • 注销时:
    POST /index/hook/on_stream_changed HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 118
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "mediaServerId" : "your_server_id",
       "app" : "live",
       "regist" : false,
       "schema" : "rtsp",
       "stream" : "obs",
       "vhost" : "__defaultVhost__"
    }
    
    • 注册时:

      POST /index/hook/on_stream_changed HTTP/1.1
      Accept: */*
      Accept-Language: zh-CN,zh;q=0.8
      Connection: keep-alive
      Content-Length: 118
      Content-Type: application/json
      Host: 127.0.0.1
      Tools: ZLMediaKit
      User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
      
      {
          "regist" : true,
          "aliveSecond": 0, #存活时间,单位秒
          "app": "live", # 应用名
          "bytesSpeed": 0, #数据产生速度,单位byte/s
          "createStamp": 1617956908,  #GMT unix系统时间戳,单位秒
          "mediaServerId": "your_server_id", # 服务器id
          "originSock": {
              "identifier": "000001C257D35E40",
              "local_ip": "172.26.20.112", # 本机ip
              "local_port": 50166, # 本机端口
              "peer_ip": "172.26.20.112", # 对端ip
              "peer_port": 50155 # 对端port
          },
          "originType": 8,  # 产生源类型,包括 unknown = 0,rtmp_push=1,rtsp_push=2,rtp_push=3,pull=4,ffmpeg_pull=5,mp4_vod=6,device_chn=7,rtc_push=8
          "originTypeStr": "rtc_push",
          "originUrl": "", #产生源的url
          "readerCount": 0, # 本协议观看人数
          "schema": "rtsp", # 协议
          "stream": "test",  # 流id
          "totalReaderCount": 0, # 观看总人数,包括hls/rtsp/rtmp/http-flv/ws-flv/rtc
          "tracks": [{
             "channels" : 1, # 音频通道数
             "codec_id" : 2, # H264 = 0, H265 = 1, AAC = 2, G711A = 3, G711U = 4
             "codec_id_name" : "CodecAAC", # 编码类型名称
             "codec_type" : 1, # Video = 0, Audio = 1
             "ready" : true, # 轨道是否准备就绪
             "sample_bit" : 16, # 音频采样位数
             "sample_rate" : 8000 # 音频采样率
          },
          {
             "codec_id" : 0, # H264 = 0, H265 = 1, AAC = 2, G711A = 3, G711U = 4
             "codec_id_name" : "CodecH264", # 编码类型名称
             "codec_type" : 0, # Video = 0, Audio = 1
             "fps" : 59,  # 视频fps
             "height" : 720, # 视频高
             "ready" : true,  # 轨道是否准备就绪
             "width" : 1280 # 视频宽
          }],
          "vhost": "__defaultVhost__"
      }
      
  • 请求参数详解:

    参数名参数类型参数解释
    appstring流应用名
    registbool流注册或注销
    schemastringrtsp 或 rtmp
    streamstring流 ID
    vhoststring流虚拟主机
    mediaServerIdstring服务器 id,通过配置文件设置
  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 40
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 08:27:35 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
       "code" : 0,
       "msg" : "success"
    }
    

13、on_stream_none_reader:

  • 解释:

    流无人观看时事件,用户可以通过此事件选择是否关闭无人看的流。 一个直播流注册上线了,如果一直没人观看也会触发一次无人观看事件,触发时的协议 schema 是随机的,看哪种协议最晚注册(一般为 hls)。 后续从有人观看转为无人观看,触发协议 schema 为最后一名观看者使用何种协议。 目前 mp4/hls 录制不当做观看人数(mp4 录制可以通过配置文件 mp4_as_player 控制,但是 rtsp/rtmp/rtp 转推算观看人数,也会触发该事件。

  • 触发请求:

    POST /index/hook/on_stream_none_reader HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 98
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "mediaServerId" : "your_server_id",
       "app" : "live",
       "schema" : "rtmp",
       "stream" : "obs",
       "vhost" : "__defaultVhost__"
    }
    
  • 请求参数详解:

参数名参数类型参数解释
appstring流应用名
schemastringrtsp 或 rtmp
streamstring流 ID
vhoststring流虚拟主机
mediaServerIdstring服务器 id,通过配置文件设置
  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 37
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 08:51:23 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
       "close" : true,
       "code" : 0
    }
    
  • 回复参数详解:

    参数名参数类型参数解释
    codeint请固定返回 0
    closebool是否关闭推流或拉流

14、on_stream_not_found:

  • 解释:

    流未找到事件,用户可以在此事件触发时,立即去拉流,这样可以实现按需拉流;此事件对回复不敏感。

  • 触发请求:

    POST /index/hook/on_stream_not_found HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 189
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "mediaServerId" : "your_server_id",
       "app" : "live",
       "id" : "140183261486112",
       "ip" : "10.0.17.132",
       "params" : "",
       "port" : 49614,
       "schema" : "rtsp",
       "stream" : "obs",
       "vhost" : "__defaultVhost__"
    }
    
  • 请求参数详解:

    参数名参数类型参数解释
    appstring流应用名
    idstringTCP 链接唯一 ID
    ipstring播放器 ip
    paramsstring播放 url 参数
    portunsigned short播放器端口号
    schemastring播放的协议,可能是 rtsp、rtmp
    streamstring流 ID
    vhoststring流虚拟主机
    mediaServerIdstring服务器 id,通过配置文件设置
  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 51
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 08:55:49 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
       "code" : 0,
       "msg" : "success
    }
    

15、on_server_started

  • 解释:

    服务器启动事件,可以用于监听服务器崩溃重启;此事件对回复不敏感。

  • 触发请求:

    POST /index/hook/on_server_started HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 3096
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "api.apiDebug" : "1",
       "api.secret" : "035c73f7-bb6b-4889-a715-d9eb2d1925cc",
       "ffmpeg.bin" : "/usr/local/bin/ffmpeg",
       "ffmpeg.cmd" : "%s -re -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s",
       "ffmpeg.log" : "./ffmpeg/ffmpeg.log",
       "general.mediaServerId" : "your_server_id",
       "general.addMuteAudio" : "1",
       "general.enableVhost" : "1",
       "general.flowThreshold" : "1024",
       "general.maxStreamWaitMS" : "5000",
       "general.publishToHls" : "1",
       "general.publishToMP4" : "0",
       "general.publishToRtxp" : "1",
       "general.resetWhenRePlay" : "1",
       "general.streamNoneReaderDelayMS" : "5000",
       "general.ultraLowDelay" : "1",
       "hls.fileBufSize" : "65536",
       "hls.filePath" : "./httpRoot",
       "hls.segDur" : "2",
       "hls.segNum" : "3",
       "hls.segRetain" : "5",
       "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_server_started" : "http://127.0.0.1/index/hook/on_server_started",
       "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" : "15",
       "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" : "./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.fastStart" : "0",
       "record.fileBufSize" : "65536",
       "record.filePath" : "./httpRoot",
       "record.fileRepeat" : "0",
       "record.fileSecond" : "3600",
       "record.sampleMS" : "500",
       "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.directProxy" : "1",
       "rtsp.handshakeSecond" : "15",
       "rtsp.keepAliveSecond" : "15",
       "rtsp.modifyStamp" : "0",
       "rtsp.port" : "554",
       "rtsp.sslport" : "322",
       "shell.maxReqSize" : "1024",
       "shell.port" : "9000"
    }
    
  • 请求参数详解: 配置文件 json 对象

  • 默认回复:

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 51
    Content-Type: application/json; charset=utf-8
    Date: Fri, Sep 20 2019 08:55:49 GMT
    Keep-Alive: timeout=10, max=100
    Server: ZLMediaKit-4.0
    
    {
       "code" : 0,
       "msg" : "success
    }
    

16、on_server_keepalive

  • 解释:

    服务器定时上报时间,上报间隔可配置,默认 10s 上报一次

  • 触发请求

    POST /index/hook/on_server_keepalive HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 189
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "data" : {
          "Buffer" : 12,
          "BufferLikeString" : 0,
          "BufferList" : 0,
          "BufferRaw" : 12,
          "Frame" : 0,
          "FrameImp" : 0,
          "MediaSource" : 0,
          "MultiMediaSourceMuxer" : 0,
          "RtmpPacket" : 0,
          "RtpPacket" : 0,
          "Socket" : 108,
          "TcpClient" : 0,
          "TcpServer" : 96,
          "TcpSession" : 0,
          "UdpServer" : 12,
          "UdpSession" : 0
       },
       "mediaServerId" : "192.168.255.10"
    }
    

17、on_rtp_server_timeout

  • 解释:

    调用 openRtpServer 接口,rtp server 长时间未收到数据,执行此 web hook,对回复不敏感

  • 触发请求

    POST /index/hook/on_rtp_server_timeout HTTP/1.1
    Accept: */*
    Accept-Language: zh-CN,zh;q=0.8
    Connection: keep-alive
    Content-Length: 189
    Content-Type: application/json
    Host: 127.0.0.1
    Tools: ZLMediaKit
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
    
    {
       "local_port" : 0,
       "re_use_port" : true,
       "ssrc" : 0,
       "stream_id" : "test",
       "tcp_mode" : 0,
       "mediaServerId" : "192.168.255.10"
    }
    
  • 请求参数详解:

    参数名参数类型参数解释
    local_portintopenRtpServer 输入的参数
    re_use_portboolopenRtpServer 输入的参数
    ssrcuint32openRtpServer 输入的参数
    stream_idstringopenRtpServer 输入的参数
    tcp_modeintopenRtpServer 输入的参数
    mediaServerIdstring服务器 id,通过配置文件设置