|
@@ -60,6 +60,7 @@ import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.GregorianCalendar;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Random;
|
|
@@ -242,8 +243,8 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
* @return
|
|
|
*/
|
|
|
public static String getPlayFlv(String cameraCode, String channel, boolean flay, String state) {
|
|
|
- log.info("getPlayFlv----master---------"+wsUrl);
|
|
|
- return wsUrl + "/ws/" + cameraCode + "/" + channel + ".flv";
|
|
|
+ log.info("getPlayFlv----master---------" + wsUrl);
|
|
|
+ return wsUrl + "/ws/" + cameraCode + "/" + channel + ".flv";
|
|
|
|
|
|
// if (!flay) {
|
|
|
// return bakUrl + "/ws/" + channel + "/" + cameraCode + ".flv";
|
|
@@ -273,14 +274,14 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
* @return
|
|
|
*/
|
|
|
public static String getPlayFlvRtsp(String cameraCode, String channel, boolean flay, String url) {
|
|
|
- log.info("---------getPlayFlvRtsp----url--"+url);
|
|
|
- if (url.contains("10.48.31.84")) {
|
|
|
- log.info("-----getPlayFlvRtsp------11------>" + bakUrlRtsp + "/master/hdl/" + cameraCode + "/" + channel + ".flv");
|
|
|
- return bakUrlRtsp + "/master/hdl/" + cameraCode + "/" + channel + "/h264_720.flv";
|
|
|
- }else {
|
|
|
- log.info("-------getPlayFlvRtsp----22------>" + bakUrlRtsp + "/slave/hdl/" + cameraCode + "/" + channel + ".flv");
|
|
|
- return bakUrlRtsp + "/slave/hdl/" + cameraCode + "/" + channel + "/h264_720.flv";
|
|
|
- }
|
|
|
+ log.info("---------getPlayFlvRtsp----url--" + url);
|
|
|
+ if (url.contains("10.48.31.84")) {
|
|
|
+ log.info("-----getPlayFlvRtsp------11------>" + bakUrlRtsp + "/master/hdl/" + cameraCode + "/" + channel + ".flv");
|
|
|
+ return bakUrlRtsp + "/master/hdl/" + cameraCode + "/" + channel + "/h264_720.flv";
|
|
|
+ } else {
|
|
|
+ log.info("-------getPlayFlvRtsp----22------>" + bakUrlRtsp + "/slave/hdl/" + cameraCode + "/" + channel + ".flv");
|
|
|
+ return bakUrlRtsp + "/slave/hdl/" + cameraCode + "/" + channel + "/h264_720.flv";
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// if (!flay) {
|
|
@@ -360,38 +361,38 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
*/
|
|
|
CamerasVo camerasVo = new CamerasVo();
|
|
|
camerasVo.setCameraIndexCode(cameraCode);
|
|
|
- String urLs = previewURLs(camerasVo, channel,httpUrl);
|
|
|
- log.info("web实时流---"+urLs);
|
|
|
+ String urLs = previewURLs(camerasVo, channel, httpUrl);
|
|
|
+ log.info("web实时流---" + urLs);
|
|
|
if (!urLs.contains("无视频")) {
|
|
|
return getPlayFlv(cameraCode, channel, true, urLs);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
return urLs;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
CamerasVo camerasVo = new CamerasVo();
|
|
|
camerasVo.setCameraIndexCode(cameraCode);
|
|
|
- String urLs = previewURLs(camerasVo, channel,httpUrl);
|
|
|
- log.info("web实时流---"+urLs);
|
|
|
+ String urLs = previewURLs(camerasVo, channel, httpUrl);
|
|
|
+ log.info("web实时流---" + urLs);
|
|
|
if (!urLs.contains("无视频")) {
|
|
|
return getPlayFlv(cameraCode, channel, true, urLs);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
return urLs;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
CamerasVo camerasVo = new CamerasVo();
|
|
|
camerasVo.setCameraIndexCode(cameraCode);
|
|
|
- String urLs = previewURLs(camerasVo, channel,httpUrl);
|
|
|
+ String urLs = previewURLs(camerasVo, channel, httpUrl);
|
|
|
if (!urLs.contains("无视频")) {
|
|
|
return getPlayFlv(cameraCode, channel, true, urLs);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
return urLs;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String heartbeatgetPlayFlv(String cameraCode, String channel, boolean type) {
|
|
|
+ public String heartbeatgetPlayFlv(String cameraCode, String channel, boolean type) {
|
|
|
int maxRetries = 3;
|
|
|
int retryCount = 0;
|
|
|
boolean success = false;
|
|
@@ -399,8 +400,8 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
List<String> pathList = new ArrayList<>();
|
|
|
//从redis中获取该相机的IP地址
|
|
|
String cacheObject = redisCache.getCacheObject(cameraCode);
|
|
|
- if(StringUtils.isEmpty(cacheObject)){
|
|
|
- cacheObject=httpUrl;
|
|
|
+ if (StringUtils.isEmpty(cacheObject)) {
|
|
|
+ cacheObject = httpUrl;
|
|
|
}
|
|
|
while (!success && retryCount < maxRetries) {
|
|
|
try {
|
|
@@ -427,7 +428,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
if (!contains) {
|
|
|
return null;
|
|
|
} else {
|
|
|
- return getPlayFlvRtsp(cameraCode, channel,type, cacheObject);
|
|
|
+ return getPlayFlvRtsp(cameraCode, channel, type, cacheObject);
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
@@ -453,10 +454,10 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public String heartbeatgetUrl(String cameraCode, String channel, boolean type,String url) throws Exception {
|
|
|
+ public String heartbeatgetUrl(String cameraCode, String channel, boolean type, String url) throws Exception {
|
|
|
CamerasVo camerasVo = new CamerasVo();
|
|
|
camerasVo.setCameraIndexCode(cameraCode);
|
|
|
- String s = previewURLs(camerasVo, channel,url);
|
|
|
+ String s = previewURLs(camerasVo, channel, url);
|
|
|
log.info("-------heartbeatgetUrl---------" + s);
|
|
|
if (s.contains("无视频")) {
|
|
|
log.info("-------无视频---------");
|
|
@@ -471,7 +472,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
|
|
|
CamerasVo camerasVo = new CamerasVo();
|
|
|
camerasVo.setCameraIndexCode(cameraCode);
|
|
|
- String s = previewURLs(camerasVo, channel,httpUrl);
|
|
|
+ String s = previewURLs(camerasVo, channel, httpUrl);
|
|
|
if (s.contains("无视频")) {
|
|
|
return s;
|
|
|
} else {
|
|
@@ -503,8 +504,8 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
* @return
|
|
|
*/
|
|
|
public static String startRecording(String cameraCode, String channel) {
|
|
|
- log.info("-----startRecording------" + historyUrl + "/recordpro/api/start?streamPath=" + cameraCode + "/" + channel+"&type=mp4");
|
|
|
- return historyUrl + "/recordpro/api/start?streamPath=" + cameraCode + "/" + channel+"&type=mp4";
|
|
|
+ log.info("-----startRecording------" + historyUrl + "/recordpro/api/start?streamPath=" + cameraCode + "/" + channel + "&type=mp4");
|
|
|
+ return historyUrl + "/recordpro/api/start?streamPath=" + cameraCode + "/" + channel + "&type=mp4";
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1126,7 +1127,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
/**
|
|
|
* STEP3:设置接口的URI地址
|
|
|
*/
|
|
|
- final String previewURLsApi = ARTEMIS_PATH+"/api/resource/v1/camera/advance/cameraList";
|
|
|
+ final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/camera/advance/cameraList";
|
|
|
Map<String, String> path = new HashMap<String, String>(2) {
|
|
|
{
|
|
|
put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
|
|
@@ -1148,8 +1149,8 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
/**
|
|
|
* STEP6:调用接口
|
|
|
*/
|
|
|
- String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
|
|
|
- log.info("GetCameraPreviewURL----->"+result);
|
|
|
+ String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
|
|
|
+ log.info("GetCameraPreviewURL----->" + result);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -1231,7 +1232,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
String body = JSONObject.toJSONString(camerasVo);
|
|
|
String previewURLs = getPreviewURLs("/api/video/v1/cameras/previewURLs", body);
|
|
|
log.info("-------------------------------->>>>>previewURLs" + previewURLs);
|
|
|
- log.info("天网接口请求参数:{}"+camerasVo);
|
|
|
+ log.info("天网接口请求参数:{}" + camerasVo);
|
|
|
if (StringUtils.isEmpty(previewURLs)) {
|
|
|
log.info("天网接口异常");
|
|
|
return "天网接口异常";
|
|
@@ -1242,7 +1243,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
// stringBuilder.append("调用时间:" + sdf.format(new Date(begin)) + "\t");
|
|
|
// stringBuilder.append("数据返回时间:" + sdf.format(new Date(end)) + "\t");
|
|
|
// stringBuilder.append("延迟:" + (end - begin) + "毫秒");
|
|
|
- stringBuilder.append("结果:"+previewURLs);
|
|
|
+ stringBuilder.append("结果:" + previewURLs);
|
|
|
return stringBuilder.toString();
|
|
|
}
|
|
|
}
|
|
@@ -1279,7 +1280,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
* @param camerasVo
|
|
|
* @param channel
|
|
|
*/
|
|
|
- public static String previewURLs(CamerasVo camerasVo, String channel,String url) {
|
|
|
+ public static String previewURLs(CamerasVo camerasVo, String channel, String url) {
|
|
|
/**
|
|
|
* jsonBody.put("cameraIndexCode", "01ea43e6676f4e47bd6c5cd9e02aa006");
|
|
|
* jsonBody.put("streamType", 0);
|
|
@@ -1305,15 +1306,15 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
String urls = data.getString("url");
|
|
|
log.info("urls----->" + urls);
|
|
|
try {
|
|
|
- log.info("httpUrl---------->" + url + "/rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + channel + "&save=0");
|
|
|
- String msg = HttpUtils.sendGet(url + "/rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + channel + "&save=0");
|
|
|
- log.info("msg---------->" + msg);
|
|
|
- log.info("boolen--------------" + msg.contains("ok"));
|
|
|
- if (!msg.contains("ok")) {
|
|
|
- return "暂无视频-" + camerasVo.getCameraIndexCode();
|
|
|
- }
|
|
|
- rc.setCacheObject(camerasVo.getCameraIndexCode(),url);
|
|
|
- return "ok";
|
|
|
+ log.info("httpUrl---------->" + url + "/rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + channel + "&save=0");
|
|
|
+ String msg = HttpUtils.sendGet(url + "/rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + channel + "&save=0");
|
|
|
+ log.info("msg---------->" + msg);
|
|
|
+ log.info("boolen--------------" + msg.contains("ok"));
|
|
|
+ if (!msg.contains("ok")) {
|
|
|
+ return "暂无视频-" + camerasVo.getCameraIndexCode();
|
|
|
+ }
|
|
|
+ rc.setCacheObject(camerasVo.getCameraIndexCode(), url);
|
|
|
+ return "ok";
|
|
|
} catch (Exception e) {
|
|
|
return "暂无视频-" + camerasVo.getCameraIndexCode();
|
|
|
}
|
|
@@ -1646,8 +1647,8 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
*
|
|
|
* @param baseCameraManagement
|
|
|
*/
|
|
|
- public String getQueryRecords(String streamPath, String date,String type) {
|
|
|
-
|
|
|
+ public String getQueryRecords(String streamPath, String date, String type) {
|
|
|
+
|
|
|
log.info("-----getQueryRecords------streamPath-----" + streamPath);
|
|
|
log.info("-----getQueryRecords-------date----" + date);
|
|
|
log.info("-----getQueryRecords-------type----" + type);
|
|
@@ -1668,11 +1669,54 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
log.info("-----getQueryRecords-------jsonObj----" + jsonObj);
|
|
|
JSONArray resultArray = jsonObj.getJSONArray("result");
|
|
|
log.info("-----getQueryRecords-------resultArray----" + resultArray);
|
|
|
- JSONObject resultObj = resultArray.getJSONObject(resultArray.size()-1);
|
|
|
- log.info("-----getQueryRecords-------resultObj----" + resultObj);
|
|
|
- String path = resultObj.getString("Path");
|
|
|
- log.info("-----getQueryRecords-------path----" + path);
|
|
|
- return caneraConfig.getRecordUrl() + Constants.RESOURCE_PREFIX + path;
|
|
|
+
|
|
|
+ if (!ObjectUtils.isEmpty(resultArray)) {
|
|
|
+ ArrayList<String> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < resultArray.size(); i++) {
|
|
|
+ JSONObject subObj = resultArray.getJSONObject(i);
|
|
|
+ String size = subObj.getString("Size");
|
|
|
+ String path = subObj.getString("Path");
|
|
|
+ Object created = subObj.get("Created");
|
|
|
+ //从缓存取出预拉的流的集合
|
|
|
+ log.info("size------------------>" + size);
|
|
|
+ log.info("path------------------>" + path);
|
|
|
+ log.info("created------------------>" + created);
|
|
|
+ //判断主码流是否订阅者是2
|
|
|
+ if (Integer.valueOf(size) > 1000) {
|
|
|
+ list.add(created + "=" + path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String records = records(list);
|
|
|
+ log.info("-----getQueryRecords-------records----" + records);
|
|
|
+ String[] split = records.split("=");
|
|
|
+ return caneraConfig.getRecordUrl() + Constants.RESOURCE_PREFIX + split[1];
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String records(List<String> objects) {
|
|
|
+
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSXXX");
|
|
|
+ OffsetDateTime maxTime = null;
|
|
|
+
|
|
|
+ for (String timeString : objects) {
|
|
|
+ String[] split = timeString.split("=");
|
|
|
+ OffsetDateTime time = OffsetDateTime.parse(split[0], formatter);
|
|
|
+ if (maxTime == null || time.isAfter(maxTime)) {
|
|
|
+ maxTime = time;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Iterator<String> iter = objects.iterator();
|
|
|
+ while (iter.hasNext()) {
|
|
|
+ String timeString = iter.next();
|
|
|
+ String[] split = timeString.split("=");
|
|
|
+ OffsetDateTime time = OffsetDateTime.parse(split[0], formatter);
|
|
|
+ if (!time.isEqual(maxTime)) {
|
|
|
+ iter.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return objects.get(0);
|
|
|
}
|
|
|
|
|
|
/**
|