Skip to main content

Web Hook

ZLMediaKitAbout 13 min

Web Hook Preview

MediaServer can notify certain internal events through HTTP POST to a third-party HTTP server. The following are the relevant default configurations:

[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

If it is an authentication event and the access IP is 127.0.0.1, or the authentication URL parameter matches admin_params, the authentication will be successful directly (without triggering the authentication web hook).

You can also refer to this issueopen in new window.

Explanation

1. enable:

  • Explanation:

    Whether to enable HTTP hook. If disabled, ZLMediaKit will take default actions (e.g., no authentication).

2. timeoutSec:

  • Explanation:

    Timeout for triggering the event and sending the HTTP POST.

3. admin_params:

  • Explanation:

    URL parameters for the super administrator. If the visitor's URL parameters match this, no authentication will be required for RTSP/RTMP/HLS/HTTP-FLV/WS-FLV playback or publishing. This option is for developer debugging.

4. on_flow_report:

  • Explanation:

    Traffic statistics event. This event is triggered when a player or publisher disconnects and has consumed traffic exceeding a specific threshold defined in the configuration file general.flowThreshold. This event does not require a response.

  • Request Trigger:

    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"
    }
    
  • Request Parameters:

    Parameter NameParameter TypeParameter Explanation
    appstringStream application
    durationintDuration of TCP connection
    paramsstringURL parameters for stream
    playerbooltrue for player, false for publisher
    schemastringProtocol of playback or publishing (e.g., rtsp, rtmp, http)
    streamstringStream ID
    totalBytesintTotal consumed upstream and downstream traffic in bytes
    vhoststringStream virtual host
    ipstringClient's IP address
    portintClient's port number
    idstringUnique ID of TCP connection
    mediaServerIdstringServer ID set in the configuration file
  • Default Response:

    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:

  • Explanation:

    Triggered when accessing files on the http file server other than HLS.

  • Trigger request:

    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
    }
    
    
  • Request parameters:

    Parameter NameParameter TypeParameter Description
    header.*stringHTTP client request headers
    idstringUnique TCP connection ID
    ipstringHTTP client IP address
    is_dirboolIndicates whether the path is a file or directory in the HTTP request
    paramsstringHTTP URL parameters
    pathstringRequested file or directory
    portunsigned shortHTTP client port number
    mediaServerIdstringServer ID set through configuration file
  • Default response:

    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
    }
    
    
  • Response parameter details:

    Parameter NameParameter TypeParameter Description
    codeintAlways return 0
    errstringError message for disallowed access, leave empty for allowed access
    pathstringThe top-level directory that the client can access or is forbidden to access. If it's an empty string, it represents the current directory
    secondintValidity period of the authorization result for this request, in seconds
    mediaServerIdstringServer ID set through configuration file

6. on_play:

  • Explanation:

    Player authentication event triggered for rtsp/rtmp/http-flv/ws-flv/hls playback. This event is triggered for playback of streams. If the stream does not exist, the on_play event is triggered first, followed by the on_stream_not_found event. When playing an rtsp stream, if the stream has started rtsp-specific authentication (on_rtsp_realm), the on_play event will not be triggered.

  • Trigger request:

    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__"
    }
    
    
  • Request parameters:

    Parameter NameParameter TypeParameter Description
    appstringStream application name
    idstringUnique TCP connection ID
    ipstringPlayer IP address
    paramsstringPlayback URL parameters
    portunsigned shortPlayer port number
    schemastringPlayback protocol, which can be rtsp, rtmp, or http
    streamstringStream ID
    vhoststringStream virtual host
    mediaServerIdstringServer ID set through configuration file
  • Default response:

    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"
    }
    
    
  • Response parameter details:

    Parameter NameParameter TypeParameter Description
    codeintError code, 0 means playback allowed
    msgstringError message when playback is not allowed

7. on_publish:

  • Explanation:

    RTSP/RTMP/RTP streaming authentication event.

  • Trigger request:

    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__"
    }
    
    
  • Request parameters:

    Parameter NameParameter TypeParameter Description
    appstringName of the streaming app
    idstringUnique ID for TCP connection
    ipstringIP address of the streaming device
    paramsstringParameters for the streaming URL
    portunsigned shortPort number of the streaming device
    schemastringProtocol for streaming, possibly RTSP or RTMP
    streamstringStream ID
    vhoststringStream virtual host
    mediaServerIdstringServer ID set through configuration file
  • Default response:

    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" : ""
    }
    
    
  • Response parameter details:

    Parameter NameParameter TypeParameter DescriptionRequired
    codeintError code, 0 means allowed to streamY
    msgstringError message when streaming is not allowedY
    enable_hlsboolWhether to convert to HLS-MPEGTS protocolN
    enable_hls_fmp4boolWhether to convert to HLS-FMP4 protocolN
    enable_mp4boolWhether to allow MP4 recordingN
    enable_rtspboolWhether to convert to RTSP protocolN
    enable_rtmpboolWhether to convert to RTMP/FLV protocolN
    enable_tsboolWhether to convert to HTTP-TS/WS-TS protocolN
    enable_fmp4boolWhether to convert to HTTP-FMP4/WS-FMP4 protocolN
    hls_demandboolWhether the protocol generates only when someone is watchingN
    rtsp_demandboolWhether the protocol generates only when someone is watchingN
    rtmp_demandboolWhether the protocol generates only when someone is watchingN
    ts_demandboolWhether the protocol generates only when someone is watchingN
    fmp4_demandboolWhether the protocol generates only when someone is watchingN
    enable_audioboolWhether to enable audio when converting protocolsN
    add_mute_audioboolWhether to add silent AAC audio when converting protocolsN
    mp4_save_pathstringRoot directory for saving MP4 recording files, use default if emptyN
    mp4_max_secondintMP4 recording segment size in secondsN
    mp4_as_playerboolWhether to count MP4 recording as viewers in playback countN
    hls_save_pathstringRoot directory for saving HLS files, use default if emptyN
    modify_stampintWhether the stream enables timestamp overlay (0: absolute timestamp / 1: system timestamp / 2: relative timestamp)N
    continue_push_msuint32Delay in milliseconds for continuous reconnection, use default value from configuration file if emptyN
    auto_closeboolWhether to automatically close the stream when no one is watching (without triggering the no-viewer hook)N
    stream_replacestringWhether to modify the stream ID, customizing thestream ID through this parameter (e.g., replacing SSRC)N

8、on_record_mp4:

  • Explanation:

    Notify event after completing the recording of the mp4 file; this event is not sensitive to replies.

  • Trigger request:

    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__"
    }
    
  • Request parameters:

    Parameter NameParameter TypeParameter Description
    appstringName of the recorded stream application
    file_namestringFile name
    file_pathstringAbsolute file path
    file_sizeintFile size in bytes
    folderstringDirectory path of the file
    start_timeintStart time of the recording (timestamp)
    streamstringRecorded stream ID
    time_lenfloatRecording duration in seconds
    urlstringRelative URL path for http/rtsp/rtmp playback
    vhoststringStream virtual host
    mediaServerIdstringServer ID set through the configuration file
  • Default response:

    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:

  • Explanation:

    Whether the RTSP stream enables authentication using the RTSP-specific method, and only triggers the on_rtsp_auth event when enabled. It should be noted that RTSP also supports URL parameter authentication, which supports two authentication methods.

  • Trigger request:

    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__"
    }
    
  • Request parameters:

    Parameter NameParameter TypeParameter Description
    appstringStream application name
    idstringUnique ID of the TCP connection
    ipstringRTSP player IP address
    paramsstringParameters of the RTSP URL
    portunsigned shortRTSP player port number
    schemastringRTSP or RTSPS
    streamstringStream ID
    vhoststringStream virtual host
    mediaServerIdstringServer ID set through the configuration file
  • Default response:

    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"
    }
    
    
  • Response parameter details:

    Parameter NameParameter TypeParameter Description
    codeintPlease return 0
    realmstringWhether the RTSP stream requires RTSP-specific authentication, an empty string means no authentication is needed

10、on_rtsp_auth:

  • Explanation:

    The authentication events specific to RTSP are triggered in the following sequence: first, the on_rtsp_realm event is triggered, followed by the on_rtsp_auth event.

  • Trigger request:

    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__"
    }
    
    
  • Request parameters:

    Parameter NameParameter TypeParameter Explanation
    appstringApplication name
    idstringUnique ID for TCP connection
    ipstringIP address of the RTSP player
    must_no_encryptboolIndicates whether the requested password must be plaintext (Base64 authentication requires plaintext password)
    paramsstringRTSP URL parameters
    portunsigned shortPort number of the RTSP player
    realmstringRTSP authentication encryption realm
    schemastringRTSP or RTSPS
    streamstringStream ID
    user_namestringPlayback username
    vhoststringStream virtual host
    mediaServerIdstringServer ID, set through the configuration file
  • Default response:

    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"
    }
    
    
  • Response parameter details:

    Parameter NameParameter TypeParameter Explanation
    codeintError code, 0 means allowed to play
    msgstringError message when playback authentication fails
    encryptedboolIndicates whether the user password is plaintext or digest
    passwdstringUser password plaintext or digest (md5(username:realm:password))

11、on_shell_login:

  • Explanation:

    Shell login authentication, ZLMediaKit provides a simple telnet debugging method. Use telnet 127.0.0.1 9000 to access the shell interface of the MediaServer process.

  • Trigger request:

    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"
    }
    
  • Request parameters:

    Parameter NameParameter TypeParameter Explanation
    idstringUnique ID for TCP connection
    ipstringTelnet terminal IP
    passwdboolTelnet terminal login password
    portunsigned shortTelnet terminal port number
    user_namestringTelnet terminal login username
    mediaServerIdstringServer ID, set through the configuration file
  • Default response:

    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"
    }
    
  • Response parameter details:

    Parameter NameParameter TypeParameter Explanation
    codeintError code, 0 means allowed to login telnet
    msgstringError message when login telnet is not allowed

12、on_stream_changed:

  • Explanation:

    This event is triggered when an RTSP/RTMP stream is registered or unregistered. This event does not require a response.

  • Trigger request:

    • When unregistering:
    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__"
    }
    
    • When registering:

      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, # The time the stream remains alive, in seconds
          "app": "live", # Application name
          "bytesSpeed": 0, #  Data generation speed in bytes/s
          "createStamp": 1617956908,  # GMT Unix system timestamp in seconds
          "mediaServerId": "your_server_id", # Server ID
          "originSock": {
              "identifier": "000001C257D35E40",
              "local_ip": "172.26.20.112", # Local ip
              "local_port": 50166, # Local Port
              "peer_ip": "172.26.20.112", # Peer ip
              "peer_port": 50155 # Peer Port
          },
          "originType": 8,  # Source type: 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 of the source
          "readerCount": 0, # Number of viewers for this protocol
          "schema": "rtsp", # protocol
          "stream": "test",  # Stream ID
          "totalReaderCount": 0, # Total number of viewers, including hls/rtsp/rtmp/http-flv/ws-flv
          "tracks": [{
             "channels" : 1, # Number of audio channels
             "codec_id" : 2, # H264 = 0, H265 = 1, AAC = 2, G711A = 3, G711U = 4
             "codec_id_name" : "CodecAAC", #  Codec type name
             "codec_type" : 1, # Video = 0, Audio = 1
             "ready" : true, # Whether the track is ready
             "sample_bit" : 16, # Audio sample bit depth
             "sample_rate" : 8000 # Audio sample rate
          },
          {
             "codec_id" : 0, # H264 = 0, H265 = 1, AAC = 2, G711A = 3, G711U = 4
             "codec_id_name" : "CodecH264", # Codec type name
             "codec_type" : 0, # Video = 0, Audio = 1
             "fps" : 59,  # Video frames per second
             "height" : 720, # video high
             "ready" : true,  # Whether the track is ready
             "width" : 1280 # video width
          }],
          "vhost": "__defaultVhost__"
      }
      
  • Request parameters:

    Parameter NameParameter TypeParameter Explanation
    appstringApplication name
    registboolStream registration or unregistration
    schemastringRTSP or RTMP
    streamstringStream ID
    vhoststringStream virtual host
    mediaServerIdstringServer ID, set through the configuration file
  • Default response:

    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:

  • Explanation:

    When there is no audience watching the stream, users can choose to close the stream without viewership through this event.

    If a live stream comes online and no one watches it, it will trigger an event of no viewership. The protocol schema triggered during this event is random and based on the latest registered protocol (usually HLS).

    When transitioning from viewership to no viewership, the protocol schema triggered will be the one used by the last viewer.

    Currently, MP4/HLS recordings are not considered as viewership. The MP4 recording can be controlled through the configuration file parameter "mp4_as_player," but RTSP/RTMP/RTP forwarding is counted as viewership and will also trigger this event.

  • Trigger request:

    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__"
    }
    
  • Request parameters:

    Parameter NameParameter TypeParameter Explanation
    appstringStream App Name
    schemastringRTSP or RTMP
    streamstringStream ID
    vhoststringStream Virtual Host
    mediaServerIdstringServer ID, set through the configuration file
  • Default response:

    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
    }
    
  • Response parameter details:

    Parameter NameParameter TypeParameter Explanation
    codeintPlease return 0
    closeboolWhether to close the stream or not

14、on_stream_not_found:

  • Explanation:

    When a stream is not found, users can immediately pull the stream when this event is triggered, allowing Pulling Streams on Demand. This event is not sensitive to replies.

  • Trigger request:

    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__"
    }
    
  • Request parameters:

    Parameter NameParameter TypeParameter Explanation
    appstringStream App Name
    idstringUnique TCP Connection ID
    ipstringPlayer IP Address
    paramsstringPlayer URL Parameters
    portunsigned shortPlayer Port Number
    schemastringProtocol for playback, possibly RTSP or RTMP
    streamstringStream ID
    vhoststringStream Virtual Host
    mediaServerIdstringServer ID, set through the configuration file
  • Default response:

    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

  • Explanation:

    Server startup event, can be used to monitor server crashes and restarts. This event is not sensitive to replies.

  • Trigger request:

    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"
    }
    
  • Request parameters: json object of configuration file

  • Default response:

    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

  • Explanation:

    The server periodically reports time, which can be configured. The default interval is 10 seconds.

  • Trigger request:

    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

  • Explanation:

    When calling the openRtpServer interface, if the RTP server does not receive data for a long time, this webhook will be executed. It is not sensitive to replies.

  • 触发请求

    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"
    }
    
  • Request parameters:

    Parameter NameParameter TypeParameter Explanation
    local_portintParameter input for openRtpServer
    re_use_portboolParameter input for openRtpServer
    ssrcuint32Parameter input for openRtpServer
    stream_idstringParameter input for openRtpServer
    tcp_modeintParameter input for openRtpServer
    mediaServerIdstringServer ID, set through the configuration file