ZLMediaKit支持的HTTP API

MediaServer是ZLMediaKit的主進(jìn)程,目前支持以下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方式,參數(shù)既可以使用urlencoded方式也可以使用json方式。
操作這些api一般需要提供secret參數(shù)以便鑒權(quán),如果操作ip是127.0.0.1,那么可以無(wú)需鑒權(quán)。

API詳解

  • /index/api/getThreadsLoad

    • 功能:獲取各epoll(或select)線程負(fù)載以及延時(shí)

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

    • 參數(shù):無(wú)

    • 響應(yīng):

      {
         "data" : [
            {
               "delay" : 0, #該線程延時(shí)
               "load" : 0 #該線程負(fù)載,0 ~ 100
            },
            {
               "delay" : 0,
               "load" : 0
            }
         ]
      }
      
  • /index/api/getServerConfig

    • 功能:獲取服務(wù)器配置

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

    • 參數(shù):

      參數(shù) 是否必選 釋意
      secret Y api操作密鑰(配置文件配置),如果操作ip是127.0.0.1,則不需要此參數(shù)
    • 響應(yīng):

      {
         "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>您訪問(wèn)的資源不存在!</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

    • 功能:重啟服務(wù)器,只有Daemon方式才能重啟,否則是直接關(guān)閉!

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

    • 參數(shù):

      參數(shù) 是否必選 釋意
      secret Y api操作密鑰(配置文件配置),如果操作ip是127.0.0.1,則不需要此參數(shù)
    • 響應(yīng):

      {
         "code" : 0,
         "msg" : "服務(wù)器將在一秒后自動(dòng)重啟"
      }
      
  • /index/api/getMediaList

    • 功能:獲取流列表,可選篩選參數(shù)

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

    • 參數(shù):

      參數(shù) 是否必選 釋意
      secret Y api操作密鑰(配置文件配置),如果操作ip是127.0.0.1,則不需要此參數(shù)
      schema N 篩選協(xié)議,例如 rtsp或rtmp
      vhost N 篩選虛擬主機(jī),例如__defaultVost__
      app N 篩選應(yīng)用名,例如 live
    • 響應(yīng):

      {
         "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

    • 功能:關(guān)閉流(目前所有類型的流都支持關(guān)閉)

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

    • 參數(shù):

      參數(shù) 是否必選 釋意
      secret Y api操作密鑰(配置文件配置),如果操作ip是127.0.0.1,則不需要此參數(shù)
      schema Y 協(xié)議,例如 rtsp或rtmp
      vhost Y 虛擬主機(jī),例如__defaultVost__
      app Y 應(yīng)用名,例如 live
      stream Y 流id,例如 test
      force N 是否強(qiáng)制關(guān)閉(有人在觀看是否還關(guān)閉)
    • 響應(yīng):

      {
         "code" : 0,# 0:成功,-1:關(guān)閉失敗,-2:該流不存在
         "msg" : "success"
      }
      
  • /index/api/getAllSession

    • 功能:獲取所有TcpSession列表(獲取所有tcp客戶端相關(guān)信息)

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

    • 參數(shù):

      參數(shù) 是否必選 釋意
      secret Y api操作密鑰(配置文件配置),如果操作ip是127.0.0.1,則不需要此參數(shù)
      local_port N 篩選本機(jī)端口,例如篩選rtsp鏈接:554
      peer_ip N 篩選客戶端ip
    • 響應(yīng):

      {
         "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",  # 本機(jī)網(wǎng)卡ip
               "local_port" : 1935,           # 本機(jī)端口號(hào) (這是個(gè)rtmp播放器或推流器)
               "peer_ip" : "127.0.0.1",   # 客戶端ip 
               "peer_port" : 51130,               # 客戶端端口號(hào)
               "typeid" : "N8mediakit11RtmpSessionE"  # 客戶端TCPSession typeid
            }
         ]
      }
      
  • /index/api/kick_session

    • 功能:斷開(kāi)tcp連接,比如說(shuō)可以斷開(kāi)rtsp、rtmp播放器等

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

    • 參數(shù):

      參數(shù) 是否必選 釋意
      secret Y api操作密鑰(配置文件配置),如果操作ip是127.0.0.1,則不需要此參數(shù)
      Id Y 客戶端唯一id,可以通過(guò)getAllSession接口獲取
    • 響應(yīng):

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

    • 功能:動(dòng)態(tài)添加rtsp/rtmp拉流代理(只支持H264/H265/aac負(fù)載)

    • 范例:http://127.0.0.1/index/api/addStreamProxy?vhost=__defaultVhost__&app=proxy&stream=0&url=rtmp://live.hkstv.hk.lxdns.com/live/hks2

    • 參數(shù):

      參數(shù) 是否必選 釋意
      secret Y api操作密鑰(配置文件配置),如果操作ip是127.0.0.1,則不需要此參數(shù)
      vhost Y 添加的流的虛擬主機(jī),例如__defaultVhost__
      app Y 添加的流的應(yīng)用名,例如live
      stream Y 添加的流的id名,例如test
      url Y 拉流地址,例如rtmp://live.hkstv.hk.lxdns.com/live/hks2
      enable_hls N 是否轉(zhuǎn)hls
      enable_mp4 N 是否mp4錄制
      rtp_type N rtsp拉流時(shí),拉流方式,0:tcp,1:udp,2:組播
    • 響應(yīng):

      {
         "code" : 0,
         "data" : {
            "key" : "__defaultVhost__/proxy/0"  # 流的唯一標(biāo)識(shí)
         }
      }
      
  • /index/api/delStreamProxy

    • 功能:關(guān)閉拉流代理

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

    • 參數(shù):

      參數(shù) 是否必選 釋意
      secret Y api操作密鑰(配置文件配置),如果操作ip是127.0.0.1,則不需要此參數(shù)
      key Y addStreamProxy接口返回的key
    • 響應(yīng):

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

    • 功能:關(guān)閉ffmpeg拉流代理

    • 范例:http://127.0.0.1/index/api/delFFmepgSource?key=5f748d2ef9712e4b2f6f970c1d44d93a

    • 參數(shù):

      參數(shù) 是否必選 釋意
      secret Y api操作密鑰(配置文件配置),如果操作ip是127.0.0.1,則不需要此參數(shù)
      key Y addFFmpegSource接口返回的key
    • 響應(yīng):

      {
         "code" : 0,
         "data" : {
            "flag" : true # 成功與否
         }
      }
      
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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