4 ZLMediaKit web hook

ZLMediaKit web hook回調(diào)

MediaServer可以把內(nèi)部的一些事件通過http post 第三方http服務(wù)器的方式通知出去,以下是相關(guān)的默認(rèn)配置:

[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

如果是鑒權(quán)事件,且訪問IP是127.0.0.1或者鑒權(quán)url參數(shù)與admin_params一致,那么會(huì)直接鑒權(quán)成功(不會(huì)觸發(fā)鑒權(quán)web hook)。

詳解
1. enable :

  • 解釋:
    是否開啟http hook,如果選擇關(guān)閉,ZLMediaKit將采取默認(rèn)動(dòng)作(例如不鑒權(quán)等)

2. timeoutSec:

  • 解釋:
    事件觸發(fā)http post超時(shí)時(shí)間。

3. admin_params:

  • 解釋:
    超級管理員的url參數(shù),如果訪問者url參數(shù)與此一致,那么rtsp/rtmp/hls/http-flv/ws-flv播放或推流將無需鑒權(quán)。該選項(xiàng)用于開發(fā)者調(diào)試用。

4. on_flow_report:

  • 解釋:
    流量統(tǒng)計(jì)事件,播放器或推流器斷開時(shí)并且耗用流量超過特定閾值時(shí)會(huì)觸發(fā)此事件,閾值通過配置文件general.flowThreshold配置;此事件對回復(fù)不敏感。
  • 觸發(fā)請求:
    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"
    }
    
  • 請求參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋
    app string 流應(yīng)用名
    duration int tcp鏈接維持時(shí)間,單位秒
    params string 推流或播放url參數(shù)
    player bool true為播放器,false為推流器
    schema string 播放或推流的協(xié)議,可能是rtsp、rtmp、http
    stream string 流ID
    totalBytes int 耗費(fèi)上下行流量總和,單位字節(jié)
    vhost string 流虛擬主機(jī)
    ip string 客戶端ip
    port int 客戶端端口號
    id string TCP鏈接唯一ID
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
  • 默認(rèn)回復(fù):

    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文件服務(wù)器上hls之外的文件時(shí)觸發(fā)。
  • 觸發(fā)請求:
    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
    }
    
  • 請求參數(shù)詳解:
    參數(shù)名 參數(shù)類型 參數(shù)解釋
    header.* string http客戶端請求header
    id string TCP鏈接唯一ID
    ip string http客戶端ip
    is_dir bool http 訪問路徑是文件還是目錄
    params string http url參數(shù)
    path string 請求訪問的文件或目錄
    port unsigned short http客戶端端口號
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
  • 默認(rèn)回復(fù):
    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
    }
    
  • 回復(fù)參數(shù)詳解:
    參數(shù)名 參數(shù)類型 參數(shù)解釋
    code int 請固定返回0
    err string 不允許訪問的錯(cuò)誤提示,允許訪問請置空
    path string 該客戶端能訪問或被禁止的頂端目錄,如果為空字符串,則表述為當(dāng)前目錄
    second int 本次授權(quán)結(jié)果的有效期,單位秒
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置

6. on_play:

  • 解釋:
    播放器鑒權(quán)事件,rtsp/rtmp/http-flv/ws-flv/hls的播放都將觸發(fā)此鑒權(quán)事件; 如果流不存在,那么先觸發(fā)on_play事件然后觸發(fā)on_stream_not_found事件。 播放rtsp流時(shí),如果該流啟動(dòng)了rtsp專屬鑒權(quán)(on_rtsp_realm)那么將不再觸發(fā)on_play事件。
  • 觸發(fā)請求:
    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__"
    }
    
  • 請求參數(shù)詳解:
    參數(shù)名 參數(shù)類型 參數(shù)解釋
    app string 流應(yīng)用名
    id string TCP鏈接唯一ID
    ip string 播放器ip
    params string 播放url參數(shù)
    port unsigned short 播放器端口號
    schema string 播放的協(xié)議,可能是rtsp、rtmp、http
    stream string 流ID
    vhost string 流虛擬主機(jī)
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
  • 默認(rèn)回復(fù):
    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"
    }
    
    
  • 回復(fù)參數(shù)詳解:
    參數(shù)名 參數(shù)類型 參數(shù)解釋
    code int 錯(cuò)誤代碼,0代表允許播放
    msg string 不允許播放時(shí)的錯(cuò)誤提示

7. on_publish:

  • 解釋:
    rtsp/rtmp/rtp推流鑒權(quán)事件。

  • 觸發(fā)請求:

    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__"
    }
    
    
  • 請求參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋
    app string 流應(yīng)用名
    id string TCP鏈接唯一ID
    ip string 推流器ip
    params string 推流url參數(shù)
    port unsigned short 推流器端口號
    schema string 推流的協(xié)議,可能是rtsp、rtmp
    stream string 流ID
    vhost string 流虛擬主機(jī)
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
  • 默認(rèn)回復(fù):

    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_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/"
    }
    
    
  • 回復(fù)參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋 必須參數(shù)
    code int 錯(cuò)誤代碼,0代表允許推流 Y
    msg string 不允許推流時(shí)的錯(cuò)誤提示 Y
    enable_hls bool 是否轉(zhuǎn)換成hls協(xié)議 N
    enable_mp4 bool 是否允許mp4錄制 N
    enable_rtsp bool 是否轉(zhuǎn)rtsp協(xié)議 N
    enable_rtmp bool 是否轉(zhuǎn)rtmp/flv協(xié)議 N
    enable_ts bool 是否轉(zhuǎn)http-ts/ws-ts協(xié)議 N
    enable_fmp4 bool 是否轉(zhuǎn)http-fmp4/ws-fmp4協(xié)議 N
    enable_audio bool 轉(zhuǎn)協(xié)議時(shí)是否開啟音頻 N
    add_mute_audio bool 轉(zhuǎn)協(xié)議時(shí),無音頻是否添加靜音aac音頻 N
    mp4_save_path string mp4錄制文件保存根目錄,置空使用默認(rèn) N
    mp4_max_second int mp4錄制切片大小,單位秒 N
    hls_save_path string hls文件保存保存根目錄,置空使用默認(rèn) N
    continue_push_ms uint32 斷連續(xù)推延時(shí),單位毫秒,置空使用配置文件默認(rèn)值 N
    mp4_as_player bool MP4錄制是否當(dāng)作觀看者參與播放人數(shù)計(jì)數(shù) N
    modify_stamp bool 該流是否開啟時(shí)間戳覆蓋 N

8. on_record_mp4:

  • 解釋:
    錄制mp4完成后通知事件;此事件對回復(fù)不敏感。
  • 觸發(fā)請求:
    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,
       "url" : "record/live/obs/2019-09-20/15-53-02.mp4",
       "vhost" : "__defaultVhost__"
    }
    
  • 請求參數(shù)詳解:
    參數(shù)名 參數(shù)類型 參數(shù)解釋
    app string 錄制的流應(yīng)用名
    file_name string 文件名
    file_path string 文件絕對路徑
    file_size int 文件大小,單位字節(jié)
    folder string 文件所在目錄路徑
    start_time int 開始錄制時(shí)間戳
    stream string 錄制的流ID
    time_len int 錄制時(shí)長,單位秒
    url string http/rtsp/rtmp點(diǎn)播相對url路徑
    vhost string 流虛擬主機(jī)
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
  • 默認(rèn)回復(fù):
    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專用方式的鑒權(quán)事件,開啟后才會(huì)觸發(fā)on_rtsp_auth事件。
    需要指出的是rtsp也支持url參數(shù)鑒權(quán),它支持兩種方式鑒權(quán)。
  • 觸發(fā)請求:
    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__"
    }
    
  • 請求參數(shù)詳解:
    參數(shù)名 參數(shù)類型 參數(shù)解釋
    app string 流應(yīng)用名
    id string TCP鏈接唯一ID
    ip string rtsp播放器ip
    params string 播放rtsp url參數(shù)
    port unsigned short rtsp播放器端口號
    schema string rtsp或rtsps
    stream string 流ID
    vhost string 流虛擬主機(jī)
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
  • 默認(rèn)回復(fù):
    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"
    }
    
    
  • 回復(fù)參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋
    code int 請固定返回0
    realm string 該rtsp流是否需要rtsp專有鑒權(quán),空字符串代碼不需要鑒權(quán)

10、on_rtsp_auth:

  • 解釋:
    rtsp專用的鑒權(quán)事件,先觸發(fā)on_rtsp_realm事件然后才會(huì)觸發(fā)on_rtsp_auth事件。

  • 觸發(fā)請求:

    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__"
    }
    
    
  • 請求參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋
    app string 流應(yīng)用名
    id string TCP鏈接唯一ID
    ip string rtsp播放器ip
    must_no_encrypt bool 請求的密碼是否必須為明文(base64鑒權(quán)需要明文密碼)
    params string rtsp url參數(shù)
    port unsigned short rtsp播放器端口號
    realm string rtsp播放鑒權(quán)加密realm
    schema string rtsp或rtsps
    stream string 流ID
    user_name string 播放用戶名
    vhost string 流虛擬主機(jī)
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
  • 默認(rèn)回復(fù):

    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"
    }
    
    
  • 回復(fù)參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋
    code int 錯(cuò)誤代碼,0代表允許播放
    msg string 播放鑒權(quán)失敗時(shí)的錯(cuò)誤提示
    encrypted bool 用戶密碼是否已加密
    passwd string 用戶密碼

11、on_shell_login:

  • 解釋:
    shell登錄鑒權(quán),ZLMediaKit提供簡單的telnet調(diào)試方式
    使用telnet 127.0.0.1 9000能進(jìn)入MediaServer進(jìn)程的shell界面。

  • 觸發(fā)請求:

    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"
    }
    
  • 請求參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋
    id string TCP鏈接唯一ID
    ip string telnet 終端ip
    passwd bool telnet 終端登錄用戶密碼
    port unsigned short telnet 終端端口號
    user_name string telnet 終端登錄用戶名
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
  • 默認(rèn)回復(fù):

    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"
    }
    
  • 回復(fù)參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋
    code int 錯(cuò)誤代碼,0代表允許登錄telnet
    msg string 不允許登錄telnet時(shí)的錯(cuò)誤提示

12、on_stream_changed:

  • 解釋:
    rtsp/rtmp流注冊或注銷時(shí)觸發(fā)此事件;此事件對回復(fù)不敏感。

  • 觸發(fā)請求:

    • 注銷時(shí):
    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__"
    }
    
    • 注冊時(shí):

      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, #存活時(shí)間,單位秒
          "app": "live", # 應(yīng)用名
          "bytesSpeed": 0, #數(shù)據(jù)產(chǎn)生速度,單位byte/s
          "createStamp": 1617956908,  #GMT unix系統(tǒng)時(shí)間戳,單位秒
          "mediaServerId": "your_server_id", # 服務(wù)器id
          "originSock": {
              "identifier": "000001C257D35E40",
              "local_ip": "172.26.20.112", # 本機(jī)ip
              "local_port": 50166, # 本機(jī)端口
              "peer_ip": "172.26.20.112", # 對端ip
              "peer_port": 50155 # 對端port
          },
          "originType": 8,  # 產(chǎn)生源類型,包括 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": "", #產(chǎn)生源的url
          "readerCount": 0, # 本協(xié)議觀看人數(shù)
          "schema": "rtsp", # 協(xié)議
          "stream": "test",  # 流id
          "totalReaderCount": 0, # 觀看總?cè)藬?shù),包括hls/rtsp/rtmp/http-flv/ws-flv/rtc
          "tracks": [{
             "channels" : 1, # 音頻通道數(shù)
             "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, # 軌道是否準(zhǔn)備就緒
             "sample_bit" : 16, # 音頻采樣位數(shù)
             "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,  # 軌道是否準(zhǔn)備就緒
             "width" : 1280 # 視頻寬
          }],
          "vhost": "__defaultVhost__"
      }
      
  • 請求參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋
    app string 流應(yīng)用名
    regist bool 流注冊或注銷
    schema string rtsp或rtmp
    stream string 流ID
    vhost string 流虛擬主機(jī)
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
  • 默認(rèn)回復(fù):

    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:

  • 解釋:
    流無人觀看時(shí)事件,用戶可以通過此事件選擇是否關(guān)閉無人看的流。

  • 觸發(fā)請求:

    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__"
    }
    
  • 請求參數(shù)詳解:

參數(shù)名 參數(shù)類型 參數(shù)解釋
app string 流應(yīng)用名
schema string rtsp或rtmp
stream string 流ID
vhost string 流虛擬主機(jī)
mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
  • 默認(rèn)回復(fù):

    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
    }
    
  • 回復(fù)參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋
    code int 請固定返回0
    close bool 是否關(guān)閉推流或拉流

14. on_stream_not_found:

  • 解釋:
    流未找到事件,用戶可以在此事件觸發(fā)時(shí),立即去拉流,這樣可以實(shí)現(xiàn)按需拉流;此事件對回復(fù)不敏感。

  • 觸發(fā)請求:

    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__"
    }
    
  • 請求參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋
    app string 流應(yīng)用名
    id string TCP鏈接唯一ID
    ip string 播放器ip
    params string 播放url參數(shù)
    port unsigned short 播放器端口號
    schema string 播放的協(xié)議,可能是rtsp、rtmp
    stream string 流ID
    vhost string 流虛擬主機(jī)
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
  • 默認(rèn)回復(fù):

    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

  • 解釋:
    服務(wù)器啟動(dòng)事件,可以用于監(jiān)聽服務(wù)器崩潰重啟;此事件對回復(fù)不敏感。

  • 觸發(fā)請求:

    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"
    }
    
  • 請求參數(shù)詳解: 配置文件json對象

  • 默認(rèn)回復(fù):

    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

  • 解釋:
    服務(wù)器定時(shí)上報(bào)時(shí)間,上報(bào)間隔可配置,默認(rèn)10s上報(bào)一次

  • 觸發(fā)請求

    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

  • 解釋:
    調(diào)用openRtpServer 接口,rtp server 長時(shí)間未收到數(shù)據(jù),執(zhí)行此web hook,對回復(fù)不敏感

  • 觸發(fā)請求

    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"
    }
    
  • 請求參數(shù)詳解:

    參數(shù)名 參數(shù)類型 參數(shù)解釋
    local_port int openRtpServer 輸入的參數(shù)
    re_use_port bool openRtpServer 輸入的參數(shù)
    ssrc uint32 openRtpServer 輸入的參數(shù)
    stream_id string openRtpServer 輸入的參數(shù)
    tcp_mode int openRtpServer 輸入的參數(shù)
    mediaServerId string 服務(wù)器id,通過配置文件設(shè)置
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容