| | |
| | | public class VideoUtil { |
| | | |
| | | @Value("${videoPoint.url}") |
| | | private String url; |
| | | private String url; |
| | | |
| | | @Value("${videoPoint.userName}") |
| | | private String userName; |
| | | private String userName; |
| | | |
| | | @Value("${videoPoint.passWord}") |
| | | private String passWord; |
| | | private String passWord; |
| | | |
| | | @Value("${videoPoint.ip}") |
| | | private String ip; |
| | | private String ip; |
| | | |
| | | /* |
| | | * @Description subType:类型int,选填。码流类型,0:主码流、1:辅流1、2:辅流2。默认为0主码流。scheme:类型string,选填。协议类型,支持RTSP、FLV_HTTP、HLS三种,默认RTSP。 |
| | | * @Param [code, scheme, subType] |
| | | * @return java.lang.String |
| | | **/ |
| | | @SneakyThrows |
| | | public String getVideo(String code, String scheme,Integer subType) { |
| | | public String getVideo(String code, String scheme, Integer subType) { |
| | | System.out.println("开始视频请求:" + code); |
| | | String clientType = "winpc"; |
| | | String reqUrl = "/videoService/accounts/authorize"; |
| | | String deviceUrl = "/videoService/devicesManager/devices"; |
| | | String monitorUrl = "/videoService/realmonitor/uri?subType=" + subType + "&scheme=" + scheme + "&channelId="; |
| | | // String monitorUrl = "/videoService/realmonitor/uri?subType=" + subType + "&scheme=" + scheme + "&channelId="; |
| | | |
| | | String monitorUrl = "/videoService/realmonitor/uri?trackId=&encryptedInfo=&userId=&urlType=1&keyIndex=®ionId=&packtype=Private&planId=&subType=" + subType + "&isroute=false&streamType=&locationEnable=false&domainId=&duration=600&scheme=RTSP&dataType=2&extend=&channelId="; |
| | | if (!"RTSP".equals(scheme)) { |
| | | monitorUrl = "/videoService/realmonitor/uri?subType=" + subType + "&scheme=" + scheme + "&channelId="; |
| | | } |
| | | RestTemplate restTemplate = new RestTemplate(); |
| | | restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { |
| | | @Override |
| | |
| | | HttpHeaders deviceHeaders = new HttpHeaders(); |
| | | deviceHeaders.add("X-Subject-Token", objectMapper.readTree(secondResEntity.getBody()).get("token").textValue()); |
| | | HttpEntity<Object> deviceEntity = new HttpEntity<>(deviceHeaders); |
| | | // System.out.println("视频设备请求地址:" + url + deviceUrl + "/" + code); |
| | | ResponseEntity<String> exchange = restTemplate.exchange(url + deviceUrl + "/" + code, HttpMethod.GET, deviceEntity, String.class); |
| | | // System.out.println("开始视频身份请求结果:" + exchange.getBody()); |
| | | String channelId = objectMapper.readTree(objectMapper.readTree(objectMapper.readTree(exchange.getBody()).get("encoderUnit").toString()).get("channels").get(0).toString()).get("channelId").textValue(); |
| | | // System.out.println("视频请求地址:" + url + monitorUrl + channelId); |
| | | ResponseEntity<String> monitorReq = restTemplate.exchange(url + monitorUrl + channelId, HttpMethod.GET, deviceEntity, String.class); |
| | | // System.out.println("视频请求返回参数:" + monitorReq.getBody()); |
| | | return objectMapper.readTree(monitorReq.getBody()).get("url").textValue(); |
| | | } |
| | | } |