最近更新时间:2024.03.11 16:24:00
首次发布时间:2022.11.15 09:54:09
您可通过服务端 SDK for Java 来调用慢直播 OpenAPI,实现快速开发。我们提供了多语言的服务端 SDK,功能包括:
SDK 封装了签名,避免过于繁琐的自行计算。
SDK 封装了常用的 OpenAPI 调用,包含请求和响应,并提供了对应的示例,例如空间管理、设备管理、视频流管理等。
SDK 封装了常用的操作流程,比如服务端生成临时安全凭证。
火山引擎 SDK for Java 项目
火山引擎 SDK for Java 版本发布
慢直播服务端 SDK for Java 示例
<dependency> <groupId>com.volcengine</groupId> <artifactId>volc-sdk-java</artifactId> <version>LATEST</version><!--1.0.66+--> </dependency>
下载 jar 包后,导入对应的项目即可。
您需要获取火山引擎账号的 Access Key 和 Secret Key(AK/AK)来初始化服务端 SDK。可通过火山引擎控制台右上角『个人 > API访问密钥』获取火山引擎账号的 AK/SK(建议使用子账号的 AK/SK),如下图所示:
为保证账号和数据的安全,建议通过以下步骤将获取的火山引擎账号的 AK/SK 配置为长期访问凭证,然后在代码中使用环境变量获取 AK/SK 的方式进行调用。本章节介绍不同操作系统下配置长期访问凭证的操作步骤。
2. 在文件末尾添加火山引擎账号的 AK/SK,然后保存文件并退出。nano ~/.bash_profile
3. 执行以下命令生效配置信息。export ACCESS_KEY=AKLTNTM0NDdlZTJkZmEwNDZjNmFjMzhlN2NlNmExxxxxxxx export SECRET_KEY=TjJVNE1qQmpNemMyWmpNeE5ESXdPRGhqTW1GaU1qSTJNMkpqWldRxxxxxx==
4. 执行以下命令验证配置信息。source ~/.bash_profile
如果配置成功,则返回如下结果:echo $ACCESS_KEY echo $SECRET_KEY
AKLTNTM0NDdlZTJkZmEwNDZjNmFjMzhlN2NlNmExxxxxxxx TjJVNE1qQmpNemMyWmpNeE5ESXdPRGhqTW1GaU1qSTJNMkpqWldRxxxxxx==
参考以下示例,创建 SDK:
import com.volcengine.model.video_aiot.request.*; import com.volcengine.model.video_aiot.response.*; import com.volcengine.service.videoaiot.VideoAIoTService; private VideoAIoTService videoAIoTService = VideoAIoTServiceImpl.getInstance(); { videoAIoTService.setAccessKey(System.getenv("ACCESS_KEY")); videoAIoTService.setSecretKey(System.getenv("SECRET_KEY")); }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceName | 是 | 1~100位,可包含大写字母、小写字母、数字、中划线 |
setRegion | 是 | 服务地区,可选:
|
setCallback | 否 | 消息回调地址,回调消息可参考:事件回调接口说明 |
setDescription | 否 | 空间描述 |
setAccessType | 是 | 空间类型,可选:
|
setGbOptions | 否 | 设置 GB 选项,详细信息,参考 OpenAPI 接口说明 |
示例:
public void testCreateSpace() { CreateSpaceRequest createSpaceRequest = new CreateSpaceRequest(); createSpaceRequest.setSpaceName("java-space"); createSpaceRequest.setRegion("cn-beijing-a"); createSpaceRequest.setCallback(""); createSpaceRequest.setDescription("java-sdk-create"); createSpaceRequest.setAccessType("gb28181"); createSpaceRequest.setHLSLowLatency(false); CreateSpaceRequest.GBOptions gbOptions = new CreateSpaceRequest.GBOptions(); gbOptions.setPullOnDemand(true); createSpaceRequest.setGbOptions(gbOptions); try { IDResponse space = videoAIoTService.createSpace(createSpaceRequest); System.out.printf(JSON.toJSONString(space)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceID | 是 | 更新的空间 ID |
setSpaceName | 是 | 1~100位,可包含大写字母、小写字母、数字、中划线 |
setCallback | 否 | 消息回调地址,回调消息可参考:事件回调接口说明 |
setDescription | 否 | 空间描述 |
setGbOptions | 否 | 设置 GB 选项,详细信息,参考 OpenAPI 接口说明 |
示例:
public void testUpdateSpace() { UpdateSpaceRequest updateSpaceRequest = new UpdateSpaceRequest(); updateSpaceRequest.setSpaceID(rtmpSpaceID); updateSpaceRequest.setSpaceName("java-sdk-update"); updateSpaceRequest.setCallback("test-callback"); updateSpaceRequest.setDescription("java-sdk-create"); try { IDResponse idResponse = videoAIoTService.updateSpace(updateSpaceRequest); System.out.printf(JSON.toJSONString(idResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
示例:
public void testStartSpace() { try { IDResponse rawResponse = videoAIoTService.startSpace(rtmpSpaceID); System.out.printf(JSON.toJSONString(rawResponse)); } catch (Exception e) { throw new RuntimeException(e); } try { IDResponse rawResponse = videoAIoTService.stopSpace(rtmpSpaceID); System.out.printf(JSON.toJSONString(rawResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
只允许删除已停用的空间。
示例:
public void testDelSpace() { try { IDResponse rawResp = videoAIoTService.deleteSpace(rtmpSpaceID); System.out.printf(JSON.toJSONString(rawResp)); } catch (Exception e) { throw new RuntimeException(e); } }
示例:
public void testGetSpace() { try { SpaceResponse space = videoAIoTService.getSpace(gbSpaceID); System.out.println(JSON.toJSONString(space)); } catch (Exception e) { throw new RuntimeException(e); } }
示例:
public void testListSpace() { ListSpaceRequest listSpaceRequest = new ListSpaceRequest(); listSpaceRequest.setPageSize(10); listSpaceRequest.setPageNumber(1); try { ListSpaceResponse listSpaceResponse = videoAIoTService.listSpace(listSpaceRequest); ListSpaceResponse.ListSpace spaces = listSpaceResponse.getSpaces(); System.out.printf(JSON.toJSONString(spaces)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceID | 是 | 需要配置模板的空间 ID |
setTemplateID | 是 | 配置的模板 ID |
setTemplateType | 是 | 配置的模板类型,可选:
|
示例:
public void testSetSpaceTemplate() { SetSpaceTemplateRequest setSpaceTemplateRequest = new SetSpaceTemplateRequest(); setSpaceTemplateRequest.setSpaceID(""); setSpaceTemplateRequest.setTemplateID(""); setSpaceTemplateRequest.setTemplateType("screenshot"); try { videoAIoTService.setSpaceTemplate(setSpaceTemplateRequest); } catch (Exception e) { e.printStackTrace(); } }
示例:
public void testunSetSpaceTemplate() { try { videoAIoTService.unsetSpaceTemplate("spaceid", "template_type"); } catch (Exception e) { e.printStackTrace(); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceID | 是 | 设备所属空间 ID |
setDeviceName | 是 | 4~40位,可包含大写字母、小写字母、数字、中划线 |
setDeviceNSID | 是 | 国标 ID,可通过 GenSipID 接口生成国标 ID |
setDescription | 否 | 消息回调地址,回调消息可参考:事件回调接口说明 |
setPassword | 是 | 空间类型,可选:
|
setType | 是 | 设备类型,可选:
|
setUserName | 是 | 国标 ID,同 setDeviceNSID |
示例:
public void testCreateDevice() { String deviceNSID = ""; try { IDResponse ipc = videoAIoTService.genSipID("3402000000xxxxxxxxxx", "IPC"); deviceNSID = ipc.getId().getId(); } catch (Exception e) { throw new RuntimeException(e); } if ("".equalsIgnoreCase(deviceNSID)) { throw new RuntimeException("deviceNSID is empty"); } CreateDeviceRequest createDeviceRequest = new CreateDeviceRequest(); createDeviceRequest.setDeviceName("java-sdk-create0"); createDeviceRequest.setDeviceNSID(deviceNSID); createDeviceRequest.setSpaceID(gbSpaceID); createDeviceRequest.setDescription("java-sdk-create"); createDeviceRequest.setPassword("0p@la123xxxxxxxx"); createDeviceRequest.setType("IPC"); createDeviceRequest.setUserName(deviceNSID); try { CreateDeviceResponse device = videoAIoTService.createDevice(createDeviceRequest); System.out.printf(JSON.toJSONString(device)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setDeviceID | 是 | 设备唯一 ID |
setSipServerID | 否 | 设备所属空间分配的 SIP ID,可通过 控制台 > 设备管理 页面获取 |
setSpaceID | 否 | 设备所属空间 ID |
示例:
public void testGetDevice() { do_TestGetDevice("3402000000xxxxxxxxxx", "23b54cf3-077d-450c-ad02-xxxxxxxx", "3c207531-6c25-43bf-a192-xxxxxxxx"); } public void do_TestGetDevice(String sipServerID, String deviceID, String gbSpaceID) { GetDeviceRequest getDeviceRequest = new GetDeviceRequest(); getDeviceRequest.setDeviceID(deviceID); getDeviceRequest.setSipServerID(sipServerID); getDeviceRequest.setSpaceID(gbSpaceID); try { GetDeviceResponse device = videoAIoTService.getDevice(getDeviceRequest); System.out.printf(JSON.toJSONString(device)); } catch (Exception e) { throw new RuntimeException(e); } }
示例:
public void testListDevice() { ListDeviceRequest listDeviceRequest = new ListDeviceRequest(); listDeviceRequest.setPageSize(10); listDeviceRequest.setPageNumber(1); listDeviceRequest.setSpaceID(gbSpaceID); try { ListDeviceResponse listDeviceResponse = videoAIoTService.listDevice(listDeviceRequest); System.out.println(JSON.toJSONString(listDeviceResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setDeviceID | 是 | 设备唯一 ID |
示例:
public void testGetDeviceChannels() { GetDeviceChannelRequest request = new GetDeviceChannelRequest(); request.setDeviceID(deviceID); try { GetDeviceChannelResponse resp = videoAIoTService.getDeviceChannels(request); System.out.println(JSON.toJSONString(resp)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceID | 是 | 设备所属空间 ID |
setDeviceID | 是 | 设备唯一 ID |
setDeviceName | 否 | 设备名称 |
setDescription | 否 | 设备描述 |
setAutoPullAfterRegister | 否 | 是否按需拉流 |
setCoordinates | 否 | 设备经纬度 |
setAlertNotification | 否 | 设备告警 |
示例:
public void testUpdateDevice() { do_testUpdateDevice("3c207531-6c25-43bf-a192-xxxxxxxx", "43932980-f513-4aae-bc4c-xxxxxxxx"); } public void do_testUpdateDevice(String spaceID, String deviceID) { UpdateDeviceRequest updateDeviceRequest = new UpdateDeviceRequest(); updateDeviceRequest.setDeviceID(deviceID); updateDeviceRequest.setDeviceName("java-sdk-update" + System.currentTimeMillis()); updateDeviceRequest.setDescription("desc" + System.currentTimeMillis()); updateDeviceRequest.setSpaceID(spaceID); updateDeviceRequest.setAutoPullAfterRegister(false); Device.Coordinates co = new Device.Coordinates(); co.setLatitude(10.1); co.setLongitude(10.2); updateDeviceRequest.setLocation("test-location"); updateDeviceRequest.setCoordinates(co); try { IDResponse idResponse = videoAIoTService.updateDevice(updateDeviceRequest); System.out.printf(JSON.toJSONString(idResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
示例:
public void testStartDevice() { do_TestStartDevice("a0c97103-f019-42b4-b60a-xxxxxxxx", "925ca8e1-11cc-4473-aace-xxxxxxxx"); } public void do_TestStartDevice(String spaceID, String deviceID) { DeviceRequest deviceRequest = new DeviceRequest(); deviceRequest.setSpaceID(spaceID); deviceRequest.setDeviceID(deviceID); try { IDResponse idResponse = videoAIoTService.startDevice(deviceRequest); System.out.println(JSON.toJSONString(idResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceID | 是 | 设备所属空间 ID |
setDeviceID | 是 | 设备唯一 ID |
示例:
public void testFreshDevice() { do_TestFreshDevice("925ca8e1-11cc-4473-aace-xxxxxxxx", "a0c97103-f019-42b4-b60a-xxxxxxxx"); } public void do_TestFreshDevice(String deviceID, String spaceID) { DeviceRequest deviceRequest = new DeviceRequest(); deviceRequest.setDeviceID(deviceID); deviceRequest.setSpaceID(spaceID); try { IDResponse rawResponse = videoAIoTService.freshDevice(deviceRequest); System.out.println(JSON.toJSONString(rawResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
只允许删除离线的设备。
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceID | 是 | 设备所属空间 ID |
setDeviceID | 是 | 设备唯一 ID |
示例:
public void testDelDevice() { do_TestDeleteDevice("2db38a3a-2a9d-4bf7-afd9-xxxxxxxx", "fb58fc32-1dd7-4ed4-a26c-xxxxxxxx"); } public void do_TestDeleteDevice(String spaceID, String deviceID) { DeviceRequest request = new DeviceRequest(); request.setSpaceID(spaceID); request.setDeviceID(deviceID); try { IDResponse resp = videoAIoTService.deleteDevice(request); System.out.println(JSON.toJSONString(resp)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceID | 是 | 设备所属空间 ID |
setStreamName | 是 | 视频流名称,包含字母、数字、中划线;1 ~ 100 个字符长 |
示例:
public void testCreateStream() { CreateStreamRequest streamRequest = new CreateStreamRequest(); streamRequest.setSpaceID(rtmpSpaceID); streamRequest.setStreamName("stream01"); try { IDResponse idResponse = videoAIoTService.createStream(streamRequest); System.out.println(JSON.toJSONString(idResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
示例:
public void testForbidStream() { String streamID = "c518f8f3-84ed-4515-8be4-xxxxxxxx"; try { IDResponse idResponse = videoAIoTService.forbidStream(streamID); System.out.println(JSON.toJSONString(idResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
示例:
public void testUnForbidStream() { String streamID = "c518f8f3-84ed-4515-8be4-xxxxxxxx"; try { IDResponse idResponse = videoAIoTService.unForbidStream(streamID); System.out.println(JSON.toJSONString(idResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setStreamID | 是 | 需要删除的视频流 ID |
示例:
public void testDeleteStream() { StreamRequest streamRequest = new StreamRequest(); streamRequest.setStreamID("d4e6611c-ed2b-492a-xxxxxxxx"); try { IDResponse idResponse = videoAIoTService.deleteStream(streamRequest); System.out.println(JSON.toJSONString(idResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
示例:
public void testGetStream() { GetStreamRequest getStreamRequest = new GetStreamRequest(); getStreamRequest.setStreamID("3d87ab7c-88b5-4e5c-9aa0-xxxxxxxx"); try { GetStreamResponse stream = videoAIoTService.getStream(getStreamRequest); System.out.printf(JSON.toJSONString(stream)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceID | 是 | 查询视频流空间 |
setPageSize | 否 | 分页参数 |
setPageNumber | 否 | 分页参数 |
示例:
public void testListStream() { ListStreamsRequest listStreamsRequest = new ListStreamsRequest(); listStreamsRequest.setPageSize(10); listStreamsRequest.setPageNumber(1); listStreamsRequest.setSpaceID(rtmpSpaceID); try { ListStreamsResponse listStreamsResponse = videoAIoTService.listStreams(listStreamsRequest); System.out.println(JSON.toJSONString(listStreamsResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setStreamID | 是 | 需要启动的视频流 ID |
示例:
public void testStartStream() { StreamRequest streamRequest = new StreamRequest(); streamRequest.setStreamID("d4e6611c-ed2b-492a-b86b-xxxxxxxx"); try { IDResponse idResponse = videoAIoTService.startStream(streamRequest); System.out.println(JSON.toJSONString(idResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setStreamID | 是 | 需要停止的视频流 ID |
示例:
public void testDStream() { StreamRequest streamRequest = new StreamRequest(); streamRequest.setStreamID("d4e6611c-ed2b-492a-b86b-xxxxxxxx"); try { IDResponse idResponse = videoAIoTService.stopStream(streamRequest); System.out.println(JSON.toJSONString(idResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setStreamID | 是 | 需要编辑的视频流 ID |
setStreamName | 否 | 视频流名称 |
setDescription | 否 | 视频流描述 |
setSpaceID | 是 | 视频流所属空间 ID |
示例:
public void testUpdateStream() { UpdateStreamRequest updateStreamRequest = new UpdateStreamRequest(); updateStreamRequest.setStreamID(streamID); updateStreamRequest.setStreamName("java-sdk-update11111"); updateStreamRequest.setDescription("123123123"); updateStreamRequest.setSpaceID(rtmpSpaceID); try { IDResponse idResponse = videoAIoTService.updateStream(updateStreamRequest); System.out.printf(JSON.toJSONString(idResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setStreamID | 是 | 查询的流 ID |
setStartTime | 是 | 查询开始时间,UTC 时间,单位:秒 |
setEndTime | 是 | 查询结束时间,UTC 时间,单位:秒 |
示例:
public void testGetStreamData() { // 流维度的数据查询 GetStreamDataRequest streamRequest = new GetStreamDataRequest(); streamRequest.setStreamID("dbc2000c-56e0-4ccc-ba9e-xxxxxxxx"); streamRequest.setStartTime("1662555386"); streamRequest.setEndTime("1662641786"); try { GetStreamDataResponse dataResponse = videoAIoTService.getStreamData(streamRequest); System.out.println(JSON.toJSONString(dataResponse)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceID | 是 | 查询的空间 ID |
setStreamID | 是 | 查询的视频流 ID |
setStartTs | 是 | 查询开始时间,RFC3339 格式时间戳,例如:2022-08-25T16:22:17+08:00 |
setEndTs | 是 | 查询结束时间,RFC3339 格式时间戳,例如:2022-08-26T18:22:16+08:00 |
setPageSize | 否 | 分页参数,单次最大返回 500,默认 20 |
setPageNumber | 否 | 分页参数,默认1 |
示例:
public void testListDeviceScreenshot() { ListDeviceRecordsRequest listDeviceRecords = new ListDeviceRecordsRequest(); listDeviceRecords.setSpaceID("517ff7ec-7700-4862-b1e7-xxxxxxxx"); listDeviceRecords.setStreamID("2a772f0b-753c-4496-b535-xxxxxxxx"); listDeviceRecords.setStartTs("2022-08-25T16:22:17+08:00"); listDeviceRecords.setEndTs("2022-08-26T16:22:17+08:00"); listDeviceRecords.setPageSize(2); listDeviceRecords.setPageNumber(100); try { ListDeviceRecordsResponse resp = videoAIoTService.listDeviceScreenshots(listDeviceRecords); System.out.println(JSON.toJSONString(resp)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setDeviceNSID | 是 | 设备国标 ID |
setChannelID | 是 | 设备通道 ID |
setStartTime | 是 | 查询录像开始时间,秒级时间戳 |
setEndTime | 是 | 查询录像结束时间,秒级时间戳 |
setTimeoutSec | 是 | 查询的超时时间,单位:秒 |
RecordType | 是 | 查询的录像类型:可选:all/alarm/time/manual |
setOrder | 否 | 返回的录像是否排序,默认:false |
示例:
try { GetRecordListRequest request = new GetRecordListRequest(); request.setRecordType("all"); request.setDeviceNSID("340200819911xxxxxxxx"); request.setStartTime(1680451200); request.setEndTime(1680537599); request.setOrder(true); request.setTimeoutSec(20); request.setChannelID("988800000013xxxxxxxx"); GetRecordResponse resp = videoAIoTService.getRecordList(request); System.out.println(JSON.toJSONString(resp)); } catch (Exception e) { e.printStackTrace(); }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setDeviceNSID | 是 | 设备国标 ID |
setChannelID | 是 | 设备通道 ID |
setStartTime | 是 | 查询录像起始时间,秒级时间戳,例如:1686153600 |
setEndTime | 是 | 查询录像结束时间,秒级时间戳,例如:1686182400 |
setTimeoutSec | 是 | 查询的超时时间,单位:秒 |
setRecordType | 是 | 查询的录像类型:
|
setOrder | 否 | 返回的录像是否排序:
|
示例:
public void testGetDeviceRecordListV2() { setTest(); try { GetRecordListV2Request request = new GetRecordListV2Request(); request.setRecordType("all"); request.setDeviceNSID("34020027991180xxxxxx"); request.setStartTime(1688572800); request.setEndTime(1688659199); request.setOrder(true); request.setTimeoutInSec(20); request.setChannelID("98880000001xxxxxxxxx"); GetRecordV2Response resp = videoAIoTService.getRecordListV2(request); System.out.println(JSON.toJSONString(resp)); } catch (Exception e) { e.printStackTrace(); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setDeviceNSID | 是 | 设备国标 ID |
setChannelID | 是 | 设备通道 ID |
setStartTime | 是 | 录像开始时间,秒级时间戳 |
setEndTime | 是 | 录像结束时间,秒级时间戳 |
示例:
try { PlaybackStartRequest request = new PlaybackStartRequest(); request.setStartTime(1680451200); request.setEndTime(1680537599); request.setChannelID("988800000013xxxxxxxx"); request.setDeviceNSID("340200819911xxxxxxxx"); PlaybackStartResponse resp = videoAIoTService.playbackStart(request); System.out.println(JSON.toJSONString(resp)); } catch (Exception e) { e.printStackTrace(); }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setStreamID | 是 | 视频流 ID |
setDeviceNSID | 是 | 设备国标 ID |
setChannelID | 是 | 设备通道 ID |
setStartTime | 是 | 录像开始时间,Unix 时间戳,精确到秒 |
setEndTime | 是 | 录像结束时间,Unix 时间戳,精确到秒 |
示例:
try { PlaybackStartRequestV2 request = new PlaybackStartRequestV2(); request.setStartTime(1680451200); request.setEndTime(1680537599); request.setStreamID("d4e6611c-ed2b-492a-xxxxxxxx"); request.setDeviceNSID("34020081991xxxxxxxxx"); request.setChannelID("98880000001xxxxxxxxx"); PlaybackStartResponse resp = videoAIoTService.playbackStartV2(request); System.out.println(JSON.toJSONString(resp)); } catch (Exception e) { e.printStackTrace(); }
示例:
try { String id = "ae395018-9d80-4a8f-9805-1a68xxxxxxxx" ; //id 表示 PlaybackStart 接口返回的视频流 ID IDResponse resp = videoAIoTService.playbackStop(id); System.out.println(JSON.toJSONString(resp)); } catch (Exception e) { e.printStackTrace(); }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setStreamID | 是 | PlaybackStart 接口返回的视频流 ID |
setCmd | 是 | 操作类型:
|
setNtp | 否 | 指定起始播放时间,单位为:秒(如果当前片段长度为5分钟,指定60秒即从片段的第1分钟开始播放) |
setScale | 否 | 倍速,可选项(需要按设备或网络支持的条件进行设置):
|
示例:
try { PlaybackControlRequest request = new PlaybackControlRequest(); request.setStreamID("5d844cb5-10e2-4113-b642-fea8xxxxxxxx"); request.setCmd(0); request.setNtp(String.valueOf(1));// request.setScale(1); IDResponse resp = videoAIoTService.playbackControl(request); System.out.println(JSON.toJSONString(resp)); } catch (Exception e) { e.printStackTrace(); }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setStreamID | 是 | 视频流 ID,可通过 PlayBackStart 接口获取 |
示例:
public void testPlaybackStat() throws Exception { setTest(); String sid = "3ad6c029-5153-40ca-904f-7810xxxxxxxx"; for (int i = 0; ; i++) { PlaybackStatResponse playbackStatResponse = videoAIoTService.playbackStat(sid); System.out.println(JSON.toJSONString(playbackStatResponse)); if (playbackStatResponse.getResult().getStatus().equals("deleted")) { break; } Thread.sleep(1000); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceID | 是 | 查询的空间 ID |
setStreamID | 是 | 查询的视频流 ID |
setStartTs | 是 | 查询开始时间,RFC3339 格式时间戳,例如:2022-08-25T16:22:17+08:00 |
setEndTs | 是 | 查询结束时间,RFC3339 格式时间戳,例如:2022-08-26T18:22:16+08:00 |
setPageSize | 否 | 分页参数,单次最大返回 500,默认 20 |
setPageNumber | 否 | 分页参数,默认1 |
示例:
public void testListDeviceRecords() { ListDeviceRecordsRequest listDeviceRecords = new ListDeviceRecordsRequest(); listDeviceRecords.setSpaceID("1d02923f-d5ce-40f2-ac90-xxxxxxxx"); listDeviceRecords.setStreamID("fcc2adaf-93b8-44e1-800a-xxxxxxxx"); listDeviceRecords.setStartTs("2022-08-25T16:29:39+08:00"); listDeviceRecords.setEndTs("2022-08-26T16:29:39+08:00"); listDeviceRecords.setPageSize(2); listDeviceRecords.setPageNumber(1); try { ListDeviceRecordsResponse resp = videoAIoTService.listDeviceRecords(listDeviceRecords); System.out.println(JSON.toJSONString(resp)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setStreamID | 是 | 查询的视频流 ID |
setStartTs | 是 | 查询开始时间,UTC 时间,单位:秒 |
setEndTs | 是 | 查询结束时间,UTC 时间,单位:秒 |
setTokenValid | 否 | 返回的 URL Token 过期时间,单位:秒 |
示例:
public void testCloudRecordPlay() { CloudRecordPlayRequest cloudRecordPlayRequest = new CloudRecordPlayRequest(); cloudRecordPlayRequest.setStreamID("4dba59d1-87f8-47f0-805a-xxxxxxxx"); cloudRecordPlayRequest.setStartTs(1663916290); cloudRecordPlayRequest.setEndTs(1663916410); cloudRecordPlayRequest.setTokenValid(3600); try { CloudPlayResponse resp = videoAIoTService.cloudRecordPlay(cloudRecordPlayRequest); System.out.println(JSON.toJSONString(resp)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setSpaceID | 是 | 设备所属空间 ID |
setDeviceID | 是 | 设备国标 ID |
setChannelID | 是 | 设备通道 ID |
setStartTime | 是 | 录像开始时间 |
setEndTime | 是 | 录像结束时间 |
setVersion | 是 | 版本号,设置为2 |
setMps | 否 | 设置对下载的录像文件进行媒体处理的选项 |
示例:
public void testLocalMediaDownload() { LocalMediaDownloadRequest localMediaDownloadRequest = new LocalMediaDownloadRequest(); localMediaDownloadRequest.setSpaceID("7c09b921-xxxx-xxxx-xxxx-e0fce9a072a0\n"); localMediaDownloadRequest.setChannelID("34020035991320xxxxxx"); localMediaDownloadRequest.setDeviceID("34020095991320xxxxxx"); localMediaDownloadRequest.setStartTime(1660719434); localMediaDownloadRequest.setEndTime(1660719534); localMediaDownloadRequest.setVersion("2"); LocalMediaDownloadRequest.Mps mps = new LocalMediaDownloadRequest.Mps(); LocalMediaDownloadRequest.M3U8Option m3u8 = new LocalMediaDownloadRequest.M3U8Option(); m3u8.setToMp4(true); mps.setM3U8Option(m3u8); LocalMediaDownloadRequest.Subtitle subt = new LocalMediaDownloadRequest.Subtitle(); subt.setSubtitleSrc(""); LocalMediaDownloadRequest.Font font = new LocalMediaDownloadRequest.Font(); font.setFontSize(2); font.setAlignment(""); font.setPrimaryColor(""); subt.setFont(font); LocalMediaDownloadRequest.SubtitleItem item = new LocalMediaDownloadRequest.SubtitleItem(); item.setContent("水印文字"); item.setEnd(9000); item.setStart(5000); LocalMediaDownloadRequest.SubtitleItem item1 = new LocalMediaDownloadRequest.SubtitleItem(); item.setContent("水印文字"); item.setEnd(9000); item.setStart(5000); List<LocalMediaDownloadRequest.SubtitleItem> list1 = new ArrayList<LocalMediaDownloadRequest.SubtitleItem>(); list1.add(item); //list1.add(item1); subt.setSubtitleList(list1); mps.setSubtitle(subt); localMediaDownloadRequest.setMediaProcess(mps); try { LocalMediaDownloadResponse download = videoAIoTService.localMediaDownload(localMediaDownloadRequest); System.out.printf(JSON.toJSONString(download)); } catch (Exception e) { throw new RuntimeException(e); } }
流录像不同于录制模板,更适合短时间录制,启停更方便。
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setStreamID | 是 | 录制的视频流 ID |
setAutoPull | 是 | 是否自动拉流录制,若指定 false,需要先通过 启动视频流【仅GB空间】启用视频流后再开始录制 |
setTimeout | 是 | 拉流超时时间,单位:秒,如果超过指定的超时时间视频流仍然不在线,则停止录制任务,返回 timeout 错误 |
setRemux | 否 | 设置转封装,可选字段:mp4,转封装成功后可以在获取录像中查询到转封装结果 |
setRecordTime | 否 | 预估录制时间,单位:秒,超出该时间会自动停止录制任务,默认不生效,由停止录像/Timeout 控制 |
setExpire | 否 | 录像过期时间,单位:秒,过期的录像会被主动删除;默认过期时间为7天,-1表示永不过期 |
示例:
public void testStreamStartRecord() { StreamStartRecordRequest streamStartRecordRequest = new StreamStartRecordRequest(); streamStartRecordRequest.setStreamID("ee9a49ea-916c-4c2f-aced-333e409414df"); streamStartRecordRequest.setRecordTime(100); streamStartRecordRequest.setTimeout(10); streamStartRecordRequest.setExpire(-1); streamStartRecordRequest.setAutoPull(true); try { IDResponse idResponse = videoAIoTService.streamStartRecord(streamStartRecordRequest); System.out.println(JSON.toJSONString(idResponse)); } catch (Exception e) { e.printStackTrace(); } }
返回的录制任务 ID 表示本次录像的唯一 ID,凭此 ID 可以停止录像、查询录像结果、删除录像。
示例:
public void testStreamStopRecord() { try { RawResponse idResponse = videoAIoTService.streamStopRecord("record0x7df8ud0"); System.out.println(JSON.toJSONString(idResponse)); } catch (Exception e) { e.printStackTrace(); } }
示例:
public void testGetStreamRecord() { try { GetStreamRecordResponse idResponse = videoAIoTService.getStreamRecord("record0kvldcqr1"); System.out.println(JSON.toJSONString(idResponse)); } catch (Exception e) { e.printStackTrace(); } }
示例:
public void testDeleteStreamRecord() { try { DeleteStreamRecordResponse idResponse = videoAIoTService.deleteStreamRecord("record0k7248vc4"); System.out.println(JSON.toJSONString(idResponse)); } catch (Exception e) { e.printStackTrace(); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setDeviceID | 是 | 设备国标 ID |
setChannelID | 是 | 设备国标通道 ID |
setAction | 是 | 控制操作 |
setCmd | 是 | 控制指令 |
setParam | 是 | 操作参数 |
可选 Action:
public static final String ACTION_PTZ = "PTZControl"; public static final String ACTION_FI = "FiControl"; public static final String ACTION_PRESET = "PresetControl";
可选 Cmd:
//ptz public static final String PtzCmdStop = "stop"; public static final String PtzCmdRight = "right"; public static final String PtzCmdLeft = "left"; public static final String PtzCmdDown = "down"; public static final String PtzCmdUp = "up"; public static final String PtzCmdRightUp = "rightup"; public static final String PtzCmdRightDown = "rightdown"; public static final String PtzCmdLeftUp = "leftup"; public static final String PtzCmdLeftDown = "leftdown"; public static final String PtzCmdZoomIn = "zoomin"; public static final String PtzCmdZoomOut = "zoomout"; //fi public static final String FiCmdStop = "stop"; public static final String FiCmdFocusFar = "focusfar"; public static final String FiCmdFocusNear = "focusnear"; public static final String FiCmdIrisIn = "irisin"; public static final String FiCmdIrisOut = "irisout"; //preset public static final String PresetCmdSet = "set"; public static final String PresetCmdGoto = "goto"; public static final String PresetCmdRemove = "remove";
Param 参数说明:
控制选项(Action) | 参数意义 | 可选参数值 |
---|---|---|
PTZ | 对于 PTZ 方向参数,如 left、right、up等,表示转动速度 | [0, 255] |
对于 PTZ zoom 参数,表示放大缩小速度 | [0, 15] | |
FI | 焦距修改速度,值越大,焦距变化越快 | [0, 0xFF] |
Preset | 预置位 ID,设置时需要确保该预置位 ID 没有被占用 | [0x01, 0xFF] |
示例:
//ptz control public void testPTZ() throws InterruptedException { DeviceCloudControlRequest deviceCloudControlRequest = new DeviceCloudControlRequest(); deviceCloudControlRequest.setDeviceNSID("34020008991180xxxxxx"); deviceCloudControlRequest.setAction(DeviceCloudControlRequest.ACTION_PTZ); deviceCloudControlRequest.setChannelID("34020000001320xxxxxx"); deviceCloudControlRequest.setParam(51); deviceCloudControlRequest.setCmd(DeviceCloudControlRequest.PtzCmdUp); deviceCloudControlRequest.setSipID("34020000002000xxxxxx"); try { RawResponse rawResponse = videoAIoTService.cloudControl(deviceCloudControlRequest); System.out.println(JSON.toJSONString(rawResponse)); } catch (Exception e) { e.printStackTrace(); } Thread.sleep(2000); deviceCloudControlRequest = new DeviceCloudControlRequest(); deviceCloudControlRequest.setDeviceNSID("34020008991180xxxxxx"); deviceCloudControlRequest.setAction(DeviceCloudControlRequest.ACTION_PTZ); deviceCloudControlRequest.setChannelID("34020000001320xxxxxx"); deviceCloudControlRequest.setParam(51); deviceCloudControlRequest.setCmd(DeviceCloudControlRequest.PtzCmdStop); deviceCloudControlRequest.setSipID("34020000002000xxxxxx"); try { RawResponse rawResponse = videoAIoTService.cloudControl(deviceCloudControlRequest); System.out.println(JSON.toJSONString(rawResponse)); } catch (Exception e) { e.printStackTrace(); } } //fi control public void testFi() throws InterruptedException { DeviceCloudControlRequest deviceCloudControlRequest = new DeviceCloudControlRequest(); deviceCloudControlRequest.setDeviceNSID("34020008991180xxxxxx"); deviceCloudControlRequest.setAction(DeviceCloudControlRequest.ACTION_FI); deviceCloudControlRequest.setChannelID("34020000001320xxxxxx"); deviceCloudControlRequest.setParam(51); deviceCloudControlRequest.setCmd(DeviceCloudControlRequest.FiCmdFocusFar); deviceCloudControlRequest.setSipID("34020000002000xxxxxx"); try { videoAIoTService.cloudControl(deviceCloudControlRequest); } catch (Exception e) { e.printStackTrace(); } Thread.sleep(2000); deviceCloudControlRequest = new DeviceCloudControlRequest(); deviceCloudControlRequest.setDeviceNSID("34020008991180xxxxxx"); deviceCloudControlRequest.setAction(DeviceCloudControlRequest.ACTION_FI); deviceCloudControlRequest.setChannelID("34020000001320xxxxxx"); deviceCloudControlRequest.setParam(51); deviceCloudControlRequest.setCmd(DeviceCloudControlRequest.FiCmdStop); deviceCloudControlRequest.setSipID("34020000002000xxxxxx"); try { RawResponse rawResponse = videoAIoTService.cloudControl(deviceCloudControlRequest); System.out.println(JSON.toJSONString(rawResponse)); } catch (Exception e) { e.printStackTrace(); } } //preset control int presetID = 15; //添加预置位 public void testAddPreset() { DeviceCloudControlRequest deviceCloudControlRequest = new DeviceCloudControlRequest(); deviceCloudControlRequest.setCmd(DeviceCloudControlRequest.PresetCmdSet); deviceCloudControlRequest.setDeviceNSID("340200089911809xxxxxx"); deviceCloudControlRequest.setAction(DeviceCloudControlRequest.ACTION_PRESET); deviceCloudControlRequest.setChannelID("34020000001320xxxxxx"); deviceCloudControlRequest.setParam(presetID); deviceCloudControlRequest.setSipID("34020000002000xxxxxx"); try { videoAIoTService.cloudControl(deviceCloudControlRequest); } catch (Exception e) { e.printStackTrace(); } } //删除预置位 public void testRMPreset() { DeviceCloudControlRequest deviceCloudControlRequest = new DeviceCloudControlRequest(); deviceCloudControlRequest.setCmd(DeviceCloudControlRequest.PresetCmdRemove); deviceCloudControlRequest.setDeviceNSID("34020008991180xxxxxx"); deviceCloudControlRequest.setAction(DeviceCloudControlRequest.ACTION_PRESET); deviceCloudControlRequest.setChannelID("34020000001320xxxxxx"); deviceCloudControlRequest.setParam(presetID); deviceCloudControlRequest.setSipID("34020000002000xxxxxx"); try { videoAIoTService.cloudControl(deviceCloudControlRequest); } catch (Exception e) { e.printStackTrace(); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setDeviceID | 是 | 设备国标 ID |
setChannelID | 是 | 设备国标通道 ID |
setTimeout | 否 | 请求超时时间,单位秒,默认5秒 |
示例:
public void testQueryPreset() { DeviceQueryPresetRequest request = new DeviceQueryPresetRequest(); request.setChannelID("34020000001320xxxxxx"); request.setSipID("34020000002000xxxxxx"); request.setTimeout(5); request.setDeviceID("34020008991180xxxxxx"); try { DeviceQueryPresetResponse deviceQueryPresetResponse = videoAIoTService.queryPresetInfo(request); System.out.println(JSON.toJSONString(deviceQueryPresetResponse)); } catch (Exception e) { e.printStackTrace(); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setDeviceNSID | 是 | 设备国标 ID |
setChannelID | 是 | 设备国标通道 ID |
setAction | 是 | 巡航指令 |
setTrackID | 是 | 巡航组编号,取值范围:[1, 255] |
setPresetID | 否 | 预置位编号,取值范围:[0, 255] |
setSpeed | 否 | 巡航速度,取值范围:[1, 4095] |
setStaySeconds | 否 | 预置位停留时间,单位:秒,取值范围:[1, 4095] |
示例:
public void testCruiseControl() { setTest(); DeviceCruiseControlRequest request = new DeviceCruiseControlRequest(); request.setDeviceNSID("34020029991180xxxxxx"); request.setChannelID("988800000013xxxxxxxx"); // add request.setAction(DeviceCruiseControlRequest.Action_Add); request.setTrackID(1); request.setPresetID(2); try { RawResponse cruiseControlResponse = videoAIoTService.cruiseControl(request); System.out.println(JSON.toJSONString(cruiseControlResponse)); } catch (Exception e) { e.printStackTrace(); } // set stay time and speed request.setAction(DeviceCruiseControlRequest.Action_SetSpeed); request.setSpeed(500); request.setStaySeconds(5); try { RawResponse cruiseControlResponse = videoAIoTService.cruiseControl(request); System.out.println(JSON.toJSONString(cruiseControlResponse)); } catch (Exception e) { e.printStackTrace(); } // start cruise track request.setAction(DeviceCruiseControlRequest.Action_Start); request.setTrackID(1); try { RawResponse cruiseControlResponse = videoAIoTService.cruiseControl(request); System.out.println(JSON.toJSONString(cruiseControlResponse)); } catch (Exception e) { e.printStackTrace(); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setPlanName | 是 | 录像计划名称 |
setBindTemplate | 是 | 设置绑定的模板 ID |
setBindStreams | 否 | 设置绑定的视频流 ID 列表 |
setDescription | 否 | 录像计划描述 |
setStatus | 是 | 是否启用录像计划:
|
setBindChannels | 否 | 设置绑定的通道(和 setBindStreams 行为是一致的,二选一即可) |
示例:
public void testCreateRecordPlan() { setTest(); CreateRecordPlanRequest createRecordPlanRequest = new CreateRecordPlanRequest(); createRecordPlanRequest.setPlanName("test-plan"); createRecordPlanRequest.setBindTemplate("0609aef4-eb80-41c7-9858-48347dxxxxxx"); createRecordPlanRequest.setBindStreams(new ArrayList<String>() { { add("7f2f1b54-2714-4f66-ae78-cd477axxxxxx"); } }); createRecordPlanRequest.setDescription("javasdktest"); createRecordPlanRequest.setStatus("enabled"); try { IDResponse recordPlan = videoAIoTService.createRecordPlan(createRecordPlanRequest); System.out.println(recordPlan); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setPlanID | 是 | 编辑的录像计划 ID |
setPlanName | 否 | 录像计划名称 |
setBindTemplate | 否 | 设置绑定的录像模板 ID |
setDelList | 否 | 设置删除的视频流 |
setAddList | 否 | 设置新增的视频流 |
setStatus | 否 | 是否启用录像计划:
|
示例:
public void testUpdateRecordPlan() { setTest(); UpdateRecordPlanRequest updateRecordPlanRequest = new UpdateRecordPlanRequest(); updateRecordPlanRequest.setPlanName("sdk-update"); updateRecordPlanRequest.setPlanID("2f11a13a-038f-445a-800e-03572exxxxxx"); updateRecordPlanRequest.setBindTemplate("a87c5902-453a-4cb1-a4e2-87171bxxxxxx"); updateRecordPlanRequest.setStatus("enabled"); UpdateRecordPlanRequest.ModifyList delList = new UpdateRecordPlanRequest.ModifyList(); delList.setStreams(new ArrayList<String>(){ {add("7f2f1b54-2714-4f66-ae78-cd477axxxxxx");} }); updateRecordPlanRequest.setDelList(delList); UpdateRecordPlanRequest.ModifyList addList = new UpdateRecordPlanRequest.ModifyList(); addList.setStreams(new ArrayList<String>(){ {add("3e088b33-4e28-4af3-a6f1-daff5axxxxxx");} }); updateRecordPlanRequest.setAddList(addList); try { IDResponse recordPlan = videoAIoTService.updateRecordPlan(updateRecordPlanRequest); System.out.println(JSON.toJSONString(recordPlan)); } catch (Exception e) { throw new RuntimeException(e); } }
示例:
public void testGetRecordPlan() { String planID = ""; try { RecordPlanResponse recordPlan = videoAIoTService.getRecordPlan(planID); System.out.println(JSON.toJSONString(recordPlan)); } catch (Exception e) { throw new RuntimeException(e); } }
示例:
public void testGetRecordPlan() { String planID = ""; try { IDResponse id = videoAIoTService.deleteRecordPlan(planID); System.out.println(JSON.toJSONString(id)); } catch (Exception e) { throw new RuntimeException(e); } }
说明:
方法名 | 是否必须 | 说明 |
---|---|---|
setFilterName | 否 | 模糊搜索录像计划名称 |
示例:
public void testListRecordPlan() { setTest(); ListRecordPlansRequest listRecordPlansRequest = new ListRecordPlansRequest(); listRecordPlansRequest.setFilterName("test"); try { ListRecordPlansResponse recordPlan = videoAIoTService.listRecordPlans(listRecordPlansRequest); System.out.println(JSON.toJSONString(recordPlan)); } catch (Exception e) { throw new RuntimeException(e); } }
示例:
public void testListRecordPlanChannel() { setTest(); String planID = "f4aaa8ec-cab4-4120-95cd-5be2cfxxxxxx"; try { ListRecordPlanChannelsResponse recordPlan = videoAIoTService.listRecordPlanChannels(planID); System.out.println(JSON.toJSONString(recordPlan)); } catch (Exception e) { throw new RuntimeException(e); } }