ZLMediaKit支持的HTTP API

MediaServer是ZLMediaKit的主进程,目前支持以下http api接口,这些接口全部支持GET/POST方式,

      "/index/api/addFFmpegSource",
      "/index/api/addStreamProxy",
      "/index/api/close_stream",
      "/index/api/delFFmepgSource",
      "/index/api/delStreamProxy",
      "/index/api/getAllSession",
      "/index/api/getApiList",
      "/index/api/getMediaList",
      "/index/api/getServerConfig",
      "/index/api/getThreadsLoad",
      "/index/api/kick_session",
      "/index/api/restartServer",
      "/index/api/setServerConfig",
      

其中POST方式,参数既可以使用urlencoded方式也可以使用json方式。
操作这些api一般需要提供secret参数以便鉴权,如果操作ip是127.0.0.1,那么可以无需鉴权。

API详解

  • /index/api/getThreadsLoad

    • 功能:获取各epoll(或select)线程负载以及延时

    • 范例:http://127.0.0.1/index/api/getThreadsLoad

    • 参数:无

    • 响应:

      {
         "data" : [
            {
               "delay" : 0, #该线程延时
               "load" : 0 #该线程负载,0 ~ 100
            },
            {
               "delay" : 0,
               "load" : 0
            }
         ]
      }
      
  • /index/api/getServerConfig

    • 功能:获取服务器配置

    • 范例:http://127.0.0.1/index/api/getServerConfig

    • 参数:

      参数 是否必选 释意
      secret Y api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数
    • 响应:

      {
         "code" : 0,
         "data" : [
            {
               "api.apiDebug" : "1",
               "api.secret" : "035c73f7-bb6b-4889-a715-d9eb2d1925cc",
               "ffmpeg.bin" : "/usr/local/bin/ffmpeg",
               "ffmpeg.cmd" : "%s -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s",
               "ffmpeg.log" : "/Users/xzl/git/ZLMediaKit/cmake-build-debug/bin/ffmpeg/ffmpeg.log",
               "general.enableVhost" : "1",
               "general.flowThreshold" : "1024",
               "general.maxStreamWaitMS" : "5000",
               "general.streamNoneReaderDelayMS" : "5000",
               "hls.fileBufSize" : "65536",
               "hls.filePath" : "/Users/xzl/git/ZLMediaKit/cmake-build-debug/bin/httpRoot",
               "hls.segDur" : "3",
               "hls.segNum" : "3",
               "hook.access_file_except_hls" : "1",
               "hook.admin_params" : "secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc",
               "hook.enable" : "1",
               "hook.on_flow_report" : "https://127.0.0.1/index/hook/on_flow_report",
               "hook.on_http_access" : "https://127.0.0.1/index/hook/on_http_access",
               "hook.on_play" : "https://127.0.0.1/index/hook/on_play",
               "hook.on_publish" : "https://127.0.0.1/index/hook/on_publish",
               "hook.on_record_mp4" : "https://127.0.0.1/index/hook/on_record_mp4",
               "hook.on_rtsp_auth" : "https://127.0.0.1/index/hook/on_rtsp_auth",
               "hook.on_rtsp_realm" : "https://127.0.0.1/index/hook/on_rtsp_realm",
               "hook.on_shell_login" : "https://127.0.0.1/index/hook/on_shell_login",
               "hook.on_stream_changed" : "https://127.0.0.1/index/hook/on_stream_changed",
               "hook.on_stream_none_reader" : "https://127.0.0.1/index/hook/on_stream_none_reader",
               "hook.on_stream_not_found" : "https://127.0.0.1/index/hook/on_stream_not_found",
               "hook.timeoutSec" : "10",
               "http.charSet" : "utf-8",
               "http.keepAliveSecond" : "100",
               "http.maxReqCount" : "100",
               "http.maxReqSize" : "4096",
               "http.notFound" : "<html><head><title>404 Not Found</title></head><body bgcolor=\"white\"><center><h1>您访问的资源不存在!</h1></center><hr><center>ZLMediaKit-4.0</center></body></html>",
               "http.port" : "80",
               "http.rootPath" : "/Users/xzl/git/ZLMediaKit/cmake-build-debug/bin/httpRoot",
               "http.sendBufSize" : "65536",
               "http.sslport" : "443",
               "multicast.addrMax" : "239.255.255.255",
               "multicast.addrMin" : "239.0.0.0",
               "multicast.udpTTL" : "64",
               "record.appName" : "record",
               "record.filePath" : "/Users/xzl/git/ZLMediaKit/cmake-build-debug/bin/httpRoot",
               "record.fileSecond" : "3600",
               "record.sampleMS" : "100",
               "rtmp.handshakeSecond" : "15",
               "rtmp.keepAliveSecond" : "15",
               "rtmp.modifyStamp" : "1",
               "rtmp.port" : "1935",
               "rtp.audioMtuSize" : "600",
               "rtp.clearCount" : "10",
               "rtp.cycleMS" : "46800000",
               "rtp.maxRtpCount" : "50",
               "rtp.videoMtuSize" : "1400",
               "rtsp.authBasic" : "0",
               "rtsp.handshakeSecond" : "15",
               "rtsp.keepAliveSecond" : "15",
               "rtsp.port" : "554",
               "rtsp.sslport" : "322",
               "shell.maxReqSize" : "1024",
               "shell.port" : "9000"
            }
         ]
      }
      
  • /index/api/restartServer

    • 功能:重启服务器,只有Daemon方式才能重启,否则是直接关闭!

    • 范例:http://127.0.0.1/index/api/restartServer

    • 参数:

      参数 是否必选 释意
      secret Y api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数
    • 响应:

      {
         "code" : 0,
         "msg" : "服务器将在一秒后自动重启"
      }
      
  • /index/api/getMediaList

    • 功能:获取流列表,可选筛选参数

    • 范例:http://127.0.0.1/index/api/getMediaList

    • 参数:

      参数 是否必选 释意
      secret Y api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数
      schema N 筛选协议,例如 rtsp或rtmp
      vhost N 筛选虚拟主机,例如__defaultVost__
      app N 筛选应用名,例如 live
    • 响应:

      {
         "code" : 0,
         "data" : [
            {
               "app" : "live",
               "schema" : "rtsp",
               "stream" : "0",
               "vhost" : "__defaultVhost__"
            },
            {
               "app" : "live",
               "schema" : "rtmp",
               "stream" : "0",
               "vhost" : "__defaultVhost__"
            }
         ],
         "msg" : "success"
      }
      
  • /index/api/close_stream

    • 功能:关闭流(目前所有类型的流都支持关闭)

    • 范例:http://127.0.0.1/index/api/close_stream?schema=rtmp&vhost=__defaultVhost__&app=live&stream=0&force=1

    • 参数:

      参数 是否必选 释意
      secret Y api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数
      schema Y 协议,例如 rtsp或rtmp
      vhost Y 虚拟主机,例如__defaultVost__
      app Y 应用名,例如 live
      stream Y 流id,例如 test
      force N 是否强制关闭(有人在观看是否还关闭)
    • 响应:

      {
         "code" : 0,# 0:成功,-1:关闭失败,-2:该流不存在
         "msg" : "success"
      }
      
  • /index/api/getAllSession

    • 功能:获取所有TcpSession列表(获取所有tcp客户端相关信息)

    • 范例:http://127.0.0.1/index/api/getAllSession

    • 参数:

      参数 是否必选 释意
      secret Y api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数
      local_port N 筛选本机端口,例如筛选rtsp链接:554
      peer_ip N 筛选客户端ip
    • 响应:

      {
         "code" : 0,
         "data" : [
            {
               "id" : "140614477848784",
               "local_ip" : "127.0.0.1",
               "local_port" : 80,
               "peer_ip" : "127.0.0.1",
               "peer_port" : 51136,
               "typeid" : "16WebSocketSessionI11EchoSessionN8mediakit11HttpSessionEE"
            },
            {
               "id" : "140614443300192",
               "local_ip" : "127.0.0.1",
               "local_port" : 80,
               "peer_ip" : "127.0.0.1",
               "peer_port" : 51135,
               "typeid" : "16WebSocketSessionI11EchoSessionN8mediakit11HttpSessionEE"
            },
            {
               "id" : "140614440178720",  # 该tcp链接唯一id
               "local_ip" : "127.0.0.1",  # 本机网卡ip
               "local_port" : 1935,           # 本机端口号 (这是个rtmp播放器或推流器)
               "peer_ip" : "127.0.0.1",   # 客户端ip 
               "peer_port" : 51130,               # 客户端端口号
               "typeid" : "N8mediakit11RtmpSessionE"  # 客户端TCPSession typeid
            }
         ]
      }
      
  • /index/api/kick_session

    • 功能:断开tcp连接,比如说可以断开rtsp、rtmp播放器等

    • 范例:http://127.0.0.1/index/api/kick_session?id=140614440178720

    • 参数:

      参数 是否必选 释意
      secret Y api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数
      Id Y 客户端唯一id,可以通过getAllSession接口获取
    • 响应:

      {
         "code" : 0,
         "msg" : "success"
      }
      
  • /index/api/delStreamProxy

    • 功能:关闭拉流代理

    • 范例:http://127.0.0.1/index/api/delStreamProxy?key=__defaultVhost__/proxy/0

    • 参数:

      参数 是否必选 释意
      secret Y api操作密钥(配置文件配置),如果操作ip是127.0.0.1,则不需要此参数
      key Y addStreamProxy接口返回的key
    • 响应:

      {
         "code" : 0,
         "data" : {
            "flag" : true # 成功与否
         }
      }
      
  • /index/api/delFFmepgSource(目前windows下无效)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。