|
@@ -261,13 +261,13 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
* @param channel 相机通道
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String getPlayFlvRtsp(String cameraCode, String channel, boolean flay) {
|
|
|
- if (!flay) {
|
|
|
- log.info("-----getPlayFlvRtsp------11------>" + bakUrlRtsp + "/hdl/" + cameraCode + "/" + channel + ".flv");
|
|
|
- return bakUrlRtsp + "/hdl/" + cameraCode + "/" + channel + "/h264_720.flv";
|
|
|
+ public static String getPlayFlvRtsp(String cameraCode, String channel, boolean flay,String state) {
|
|
|
+ if (state.contains("master")) {
|
|
|
+ log.info("-----getPlayFlvRtsp------11------>" + bakUrlRtsp + "/master/hdl/" + cameraCode + "/" + channel + ".flv");
|
|
|
+ return bakUrlRtsp + "/master/hdl/" + cameraCode + "/" + channel + "/h264_720.flv";
|
|
|
}
|
|
|
- log.info("-------getPlayFlvRtsp----22------>" + bakUrlRtsp + "/hdl/" + cameraCode + "/" + channel + ".flv");
|
|
|
- return bakUrlRtsp + "/hdl/" + cameraCode + "/" + channel + "/h264_1080.flv";
|
|
|
+ log.info("-------getPlayFlvRtsp----22------>" + bakUrlRtsp + "/slave/hdl/" + cameraCode + "/" + channel + ".flv");
|
|
|
+ return bakUrlRtsp + "/slave/hdl/" + cameraCode + "/" + channel + "/h264_1080.flv";
|
|
|
|
|
|
|
|
|
// if (!flay) {
|
|
@@ -394,7 +394,8 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
if (!contains) {
|
|
|
return null;
|
|
|
} else {
|
|
|
- return getPlayFlvRtsp(cameraCode, channel, type);
|
|
|
+ String cacheObject = redisCache.getCacheObject(cameraCode);
|
|
|
+ return getPlayFlvRtsp(cameraCode, channel, type,cacheObject);
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
@@ -429,8 +430,9 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
log.info("-------无视频---------");
|
|
|
return s;
|
|
|
} else {
|
|
|
- log.info("-------getPlayFlvRtsp---------" + getPlayFlvRtsp(cameraCode, channel, type));
|
|
|
- return getPlayFlvRtsp(cameraCode, channel, type);
|
|
|
+ log.info("-------getPlayFlvRtsp---------" + getPlayFlvRtsp(cameraCode, channel, type,s));
|
|
|
+ redisCache.setCacheObject(cameraCode, s,2000,TimeUnit.SECONDS);
|
|
|
+ return getPlayFlvRtsp(cameraCode, channel, type,s);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1157,9 +1159,9 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
} else {
|
|
|
long end = System.currentTimeMillis();
|
|
|
JSONObject outJson = JSONObject.parse(previewURLs);
|
|
|
- stringBuilder.append("测试结果:" + ("0".equals(outJson.getString("code")) ? "成功" : "失败")+"\t");
|
|
|
- stringBuilder.append("调用时间:" + sdf.format(new Date(begin))+"\t");
|
|
|
- stringBuilder.append("数据返回时间:" + sdf.format(new Date(end))+"\t");
|
|
|
+ stringBuilder.append("测试结果:" + ("0".equals(outJson.getString("code")) ? "成功" : "失败") + "\t");
|
|
|
+ stringBuilder.append("调用时间:" + sdf.format(new Date(begin)) + "\t");
|
|
|
+ stringBuilder.append("数据返回时间:" + sdf.format(new Date(end)) + "\t");
|
|
|
stringBuilder.append("延迟:" + (end - begin) + "毫秒");
|
|
|
return stringBuilder.toString();
|
|
|
}
|
|
@@ -1222,15 +1224,40 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
String urls = data.getString("url");
|
|
|
log.info("urls----->" + urls);
|
|
|
try {
|
|
|
- log.info("httpUrl---------->" + httpUrl + "/rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + channel + "&save=0");
|
|
|
- String msg = HttpUtils.sendGet(httpUrl + "/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")) {
|
|
|
-// log.info("code---------->" + httpUrls + "/rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + channel + "&save=0");
|
|
|
-// String code = HttpUtils.sendGet(httpUrls + "/rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + channel + "&save=0");
|
|
|
-// log.info("code---------->" + code);
|
|
|
- return "暂无视频-" + camerasVo.getCameraIndexCode();
|
|
|
+ //两个流媒体的个数
|
|
|
+ //第一个是性能高的
|
|
|
+ int urlCount = urlCount(httpUrl);
|
|
|
+ //第二个是性能低的
|
|
|
+ int urlCounts = urlCount(httpUrls);
|
|
|
+ if (urlCount == 0) {
|
|
|
+ log.info("httpUrl---------->" + httpUrl + "/rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + channel + "&save=0");
|
|
|
+ String msg = HttpUtils.sendGet(httpUrl + "/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();
|
|
|
+ }
|
|
|
+ return "master";
|
|
|
+ }else{
|
|
|
+ if (urlCounts * 2 > urlCount) {
|
|
|
+ log.info("httpUrl---------->" + httpUrl + "/rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + channel + "&save=0");
|
|
|
+ String msg = HttpUtils.sendGet(httpUrl + "/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();
|
|
|
+ }
|
|
|
+ return "master";
|
|
|
+ }else {
|
|
|
+ log.info("httpUrl---------->" + httpUrls + "/rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + channel + "&save=0");
|
|
|
+ String msg = HttpUtils.sendGet(httpUrls + "/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();
|
|
|
+ }
|
|
|
+ return "slave";
|
|
|
+ }
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
return "暂无视频-" + camerasVo.getCameraIndexCode();
|
|
@@ -1238,7 +1265,6 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
} else {
|
|
|
return "天网无视频-" + camerasVo.getCameraIndexCode();
|
|
|
}
|
|
|
- return "正常输出";
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1300,6 +1326,41 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
if (!msg.equals("ok")) {
|
|
|
return "暂无视频-" + code;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * //两个流媒体的个数
|
|
|
+ * //第一个是性能高的
|
|
|
+ * int urlCount = urlCount(httpUrl);
|
|
|
+ * //第二个是性能低的
|
|
|
+ * int urlCounts = urlCount(httpUrls);
|
|
|
+ * //向流媒体推报警回放视频
|
|
|
+ * if (urlCount == 0) {
|
|
|
+ * log.info("msg---------->" + httpUrl + "/rtsp/api/pull?target=" + urls + "&streamPath=" + code + "/playback&save=0");
|
|
|
+ * String msg = HttpUtils.sendGet(httpUrl + "/rtsp/api/pull?target=" + urls + "&streamPath=" + code + "/playback&save=0");
|
|
|
+ * log.info("msg---------->" + msg);
|
|
|
+ * if (!msg.equals("ok")) {
|
|
|
+ * return "暂无视频-" + code;
|
|
|
+ * }
|
|
|
+ * return "master";
|
|
|
+ * } else {
|
|
|
+ * if (urlCounts * 2 > urlCount) {
|
|
|
+ * log.info("msg---------->" + httpUrl + "/rtsp/api/pull?target=" + urls + "&streamPath=" + code + "/playback&save=0");
|
|
|
+ * String msg = HttpUtils.sendGet(httpUrl + "/rtsp/api/pull?target=" + urls + "&streamPath=" + code + "/playback&save=0");
|
|
|
+ * log.info("msg---------->" + msg);
|
|
|
+ * if (!msg.equals("ok")) {
|
|
|
+ * return "暂无视频-" + code;
|
|
|
+ * }
|
|
|
+ * return "master";
|
|
|
+ * } else {
|
|
|
+ * log.info("msg---------->" + httpUrls + "/rtsp/api/pull?target=" + urls + "&streamPath=" + code + "/playback&save=0");
|
|
|
+ * String msg = HttpUtils.sendGet(httpUrls + "/rtsp/api/pull?target=" + urls + "&streamPath=" + code + "/playback&save=0");
|
|
|
+ * log.info("msg---------->" + msg);
|
|
|
+ * if (!msg.equals("ok")) {
|
|
|
+ * return "暂无视频-" + code;
|
|
|
+ * }
|
|
|
+ * return "slave";
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ */
|
|
|
// String FilePath = "/opt/streams/map/" + code + ".mp4";
|
|
|
// Process process = rtspToMP4.StartRecord(ffmpegPath, urls, FilePath);
|
|
|
// log.info("------playbackURLs----->>>>:" + process);
|
|
@@ -1551,4 +1612,41 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
log.info("-----getQueryRecords-------path----" + path);
|
|
|
return caneraConfig.getRecordUrl() + Constants.RESOURCE_PREFIX + path;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 流媒体的条数
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static int urlCount(String url) {
|
|
|
+ int maxRetries = 5;
|
|
|
+ int retryCount = 0;
|
|
|
+ int count = 0;
|
|
|
+ boolean success = false;
|
|
|
+ JSONArray streamArray = null;
|
|
|
+ List<BaseCameraManagementResponse> baseCameraManagementResponseList = new ArrayList<>();
|
|
|
+ while (!success && retryCount < maxRetries) {
|
|
|
+ try {
|
|
|
+ String data = HttpClientUtil.gets(url + "/api/summary");
|
|
|
+ log.info("data------------------>" + data);
|
|
|
+ if (StringUtils.isNotEmpty(data)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
+ streamArray = jsonObject.getJSONArray("Streams");
|
|
|
+ success = true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("Exception caught: " + e.getMessage());
|
|
|
+ // 增加重试计数
|
|
|
+ retryCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int i = 0; i < streamArray.size(); i++) {
|
|
|
+ JSONObject subObj = streamArray.getJSONObject(i);
|
|
|
+ String PathValue = subObj.getString("Path");
|
|
|
+ if (PathValue.contains("/h264_720")) {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
}
|