Skip to content

TDS-VIDEO 开发接口

概要

TDS包含了流媒体服务器功能,rtsp与webrtc协议。

支持Onvif,Visca云台控制协议设备接入,并通过TDS-RPC进行云台控制

TDS可以接收rtsp客户端的推流,也可以主动向媒体源拉流,从而建立一路媒体结点,对外提供流媒体服务。

流媒体服务有两种用法,一种是关联位号,在位号中配置本位号的媒体源地址。一种是不关联位号,直接拉流。

如果关联了位号,客户端可以通过位号的方式访问流媒体,如果没有关联位号,则使用媒体url的方式访问媒体。

TDS可以将运行目录下的 rtsp目录下的 .h264文件,对外提供rtsp服务,服务的streamUrl和rtsp目录下的目录保持一致。

打开码流 【openStream】

打开媒体源的码流,如果打开成功或者已经处于打开状态,都返回成功

可以同时指定流转发地址,可以不指定。

请求 (子服务本地打开场景)

json
{
    "jsonrpc": "2.0", "method": "openStream", 
    "params": {
       // ** tag模式
       "tag":"机房1.摄像头1",
       "pushToTag":"数据中心.二楼.机房1.摄像头1",  //级联模式推流到中心服务器位号 
       //中心服务的ip地址,如果缺省,则使用当前主服务TDS所在ip
       //如果主服务流媒体与TDS不在同一个IP,主服务指定pushToIP
       "pushToIP":"202.177.38.8",

       // ** url模式
       "originUrl":"rtsp://192.168.0.100/stream/cam1",
       "relayUrl":"rtsp://202.107.3.70/stream/1楼/cam1",
       "streamUrl":"/1_cam1"  //指定访问地址,如果tag模式,默认为  /%tag%      
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "openStream", 
    "result": "ok", 
    "id": 1
}

关闭码流 【closeStream】

请求

json
{
    "jsonrpc": "2.0", "method": "closeStream", 
    "params": {
       "tag":"机房1.摄像头1"
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "closeStream", 
    "result": "ok", 
    "id": 1
}

开始录像 【startRecord】

请求服务端开始录像 请求

json
{
    "jsonrpc": "2.0", "method": "startRecord", 
    "params": {
       "tag":"机房1.摄像头1",
       "preSeconds": 3  //预录时间
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "startRecord", 
    "result": "ok", 
    "id": 1
}

停止录像 【stopRecord】

请求服务端开始录像 请求

json
{
    "jsonrpc": "2.0", "method": "stopRecord", 
    "params": {
       "tag":"机房1.摄像头1"
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "stopRecord", 
    "result": {
        "fileUrl":"/db/record/机房1.摄像头1_20260503_111314.mp4",
        "duration":10,
        "preSeconds":3
    }, 
    "id": 1
}

获取录像列表 【getRecordList】

请求服务端开始录像 请求

json
{
    "jsonrpc": "2.0", "method": "getRecordList", 
    "params": {
       "tag":"机房1.摄像头1"
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "getRecordList", 
    "result": [
        {
            "tag":"机房1.摄像头1",
            "time":"2025-11-12 11:00:00",
            "duration":10,
            "preSeconds":3,
            "fileUrl":"/db/record/机房1.摄像头1_20260503_111314.mp4"
        },{
            "tag":"机房1.摄像头2",
            "time":"2025-11-12 11:00:00",
            "duration":10,
            "preSeconds":3,
            "fileUrl":"/db/record/机房1.摄像头2_20260503_111314.mp4"
        }
    ], 
    "id": 1
}

获取录像列表 【deleteRecord】

请求服务端开始录像 请求

json
{
    "jsonrpc": "2.0", "method": "deleteRecord", 
    "params": {
       "tag":"机房1.摄像头1",
       "time":"2025-11-12 11:00:00"
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "deleteRecord", 
    "result":"ok", 
    "id": 1
}

播放码流 【playWebRtc】

该命令用于浏览器进行webrtc拉流时的信令控制。一般需要配合浏览器端的webrtc流播放代码使用。

json
{
    "jsonrpc": "2.0", "method": "playWebRtc", 
    "params": {
       //tag模式
       "tag":"机房1.摄像头1",
       //streamUrl模式
       "streamUrl":"/room1/cam1",
       "clientRtpPort":5000
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "playWebRtc", 
    "result": {
        "tag":  "机房1.摄像头1",
        "clientRtpPort":5000,
        "serverRtpPort":60301,
        "sdp": "v=0\r\no=- 0 0 IN IP4 192.168.0.110\r\ns=TDS\r\nc=IN IP4 192.168.0.110\r\nt=0 0\r\nm=video 0 RTP/AVP 96\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1;profile-level-id=4D0028;sprop-parameter-sets="
    }, 
    "id": 1
}

获取流媒体信息 【getStreamInfo】

浏请求**

json
{
    "jsonrpc": "2.0", "method": "getStreamInfo", 
    "params": {
    }, 
    "id": 1
}

响应

json
{
   "server": "MasterTDS,tds v2523 b260721-145611",
   "method": "getStreamInfo",
   "id": 1,
   "result": [
      {
         "clientSessions": [],
         "originPullUrl": "file://D:/Workspace/tds/out/tds/rtsp/1.h264",
         "recordCtrl": {
            "preSeconds": 0,
            "recording": false
         },
         "relayPushUrl": "",
         "rtpBuffer": {
            "bufferedSeconds": 0,
            "maxSeconds": 60,
            "size": 0
         },
         "startTime": 484740001795100,
         "statis": {
            "bitrate": 0,
            "bytesForwarded": 0,
            "bytesReceived": 0,
            "fps": 0,
            "frameForwarded": 0,
            "frameReceived": 0,
            "reconnectCount": 0
         },
         "streamUrl": "/1",
         "tag": "1"
      }
   ]
}

开始云台移动 【startPanTilt】

请求

json
{
    "jsonrpc": "2.0", "method": "startPanTilt", 
    "params": {
       "tag":"机房1.摄像头1",
       "dir":"left",
       "panSpeed":5,
       "tiltSpeed":5
    }, 
    "id": 1
}

tag string 支持云台控制的设备的位号

dir string 移动方向

  • up 向上移动 upLeft 左上 upRight 右上

  • down 向下移动 downLeft 左下 downRight 右下

  • left 向左移动

  • right 向右移动

panSpeed int 水平移动速度

tiltSpeed int 垂直移动速度

time int 移动时间。单位ms。如果有该参数,移动会自动停止

响应

json
{
    "jsonrpc": "2.0", "method": "startPanTilt", 
    "result": "ok", 
    "id": 1
}

停止云台移动 【stopPanTilt】

请求

json
{
    "jsonrpc": "2.0", "method": "stopPanTilt", 
    "params": {}, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "stopPanTilt", 
    "result": "ok", 
    "id": 1
}

开始缩放 【startZoom】

请求

json
{
    "jsonrpc": "2.0", "method": "startZoom", 
    "params": {
       "tag":"机房1.摄像头1",
       "dir":"in",
       "speed":5
    }, 
    "id": 1
}

tag string 相机位号

dir string 移动方向

  • in 放大

  • out 缩小

speed int 缩放速度。无该参数,使用摄像机内置的默认标准速度

time int 缩放时间。单位ms。如果有该参数,缩放会自动停止

响应

json
{
    "jsonrpc": "2.0", "method": "startZoom", 
    "result": "ok", 
    "id": 1
}

停止缩放 【stopZoom】

请求

json
{
    "jsonrpc": "2.0", "method": "stopZoom", 
    "params": {}, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "stopZoom", 
    "result": "ok", 
    "id": 1
}

开始聚焦 【startFocus】

请求

json
{
    "jsonrpc": "2.0", "method": "startFocus", 
    "params": {
       "tag":"机房1.摄像头1",
       "dir":"far",
       "speed":5
    }, 
    "id": 1
}

tag string 相机位号

dir string 聚焦方向

  • far 远处聚焦

  • near 近处聚焦

speed int 聚焦速度。无该参数,使用摄像机内置的默认标准速度

time int 聚焦时间。单位ms。如果有该参数,缩放会自动停止

响应

json
{
    "jsonrpc": "2.0", "method": "startFocus", 
    "result": "ok", 
    "id": 1
}

停止缩放 【stopFocus】

请求

json
{
    "jsonrpc": "2.0", "method": "stopFocus", 
    "params": {}, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "stopFocus", 
    "result": "ok", 
    "id": 1
}

调用预置位 【gotoPreset】

请求

json
{
    "jsonrpc": "2.0", "method": "gotoPreset", 
    "params": {
        "tag":"科技大楼.605",   //摄像头设备绑定的位号
        "presetIndex": 1,
        "preset": "东面.预置位1"   //preset 或者 presetIndex 2选1
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "gotoPreset", 
    "result": "ok", 
    "id": 1
}

添加预置位 【addPreset】

将当前云台参数添加为预置位

请求

json
{
    "jsonrpc": "2.0", "method": "addPreset", 
    "params": {
        "presetIndex": 1
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "addPreset", 
    "result": {
        "presetIndex": 1
    }
    "id": 1
}

删除预置位 【deletePreset】

将当前云台参数添加为预置位

请求

json
{
    "jsonrpc": "2.0", "method": "deletePreset", 
    "params": {
        "presetIndex": 1
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "deletePreset", 
    "result": {
        "presetIndex": 1
    }
    "id": 1
}

启动预置位巡检 【startPreset​Patrol​】

将当前云台参数添加为预置位

请求

json
{
    "jsonrpc": "2.0", "method": "startPresetPatrol", 
    "params": {
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "startPresetPatrol", 
    "result": "ok",
    "id": 1
}

停止预置位巡检 【pausePreset​Patrol​】

将当前云台参数添加为预置位

请求

json
{
    "jsonrpc": "2.0", "method": "pausePresetPatrol", 
    "params": {
        "parseTime":600
    }, 
    "id": 1
}

响应

json
{
    "jsonrpc": "2.0", "method": "pausePresetPatrol", 
    "result": "ok",
    "id": 1
}

云台批量调用

使用JSON-RPC的Batch模式,依次执行多个命令

将 机房1.摄像头1 先左移1.5秒,再上移2秒,再右移动1秒,

注意3个命令全部执行完之后才会返回

请求

json
[
    {
        "method": "startPanTilt", 
        "params": {
           "tag":"机房1.摄像头1",
           "dir":"left",
           "time":1500
        }, 
        "id": 1
    },{
        "method": "startPanTilt", 
        "params": {
           "tag":"机房1.摄像头1",
           "dir":"up",
           "time":2000
        }, 
        "id": 2
    },{
        "method": "startPanTilt", 
        "params": {
           "tag":"机房1.摄像头1",
           "dir":"right",
           "time":1000
        }, 
        "id": 3
    }
]

响应

json
[
    {
        "method": "startPanTilt", 
        "result": "ok", 
        "id": 1
    },{
        "method": "startPanTilt", 
        "result": "ok", 
        "id": 2
    },{
        "method": "startPanTilt", 
        "result": "ok", 
        "id": 3
    }
]