|
@@ -55,7 +55,9 @@ public class CameraUtil {
|
|
|
private static String webUrl;
|
|
|
private static String bakUrl;
|
|
|
private static CmdCameraUtil cUtil;
|
|
|
+ private static RedisCache rc;
|
|
|
|
|
|
+ public final static String mvkey = "WAIT_MERGE_VIDEO_ALARM_ID";
|
|
|
@Autowired
|
|
|
private CaneraConfig caneraConfig;
|
|
|
|
|
@@ -410,17 +412,27 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
}
|
|
|
|
|
|
if (fileTs.size() > 0) {
|
|
|
+ Map<String, Object> mergeVideoTsFile = rc.getCacheMap("mergeVideoTsFile");
|
|
|
+ if (ObjectUtils.isEmpty(mergeVideoTsFile)) {
|
|
|
+ mergeVideoTsFile = new HashMap<>();
|
|
|
+ }
|
|
|
+ Map<Date, List<String>> objectObjectHashMap = new HashMap<>();
|
|
|
+ objectObjectHashMap.put(new Date(), fileTs);
|
|
|
+ mergeVideoTsFile.put(newfilePath, objectObjectHashMap);
|
|
|
+ rc.deleteObject("mergeVideoTsFile");
|
|
|
+ rc.setCacheMap("mergeVideoTsFile", mergeVideoTsFile);
|
|
|
+
|
|
|
sm.append("-c copy " + newfilePath);
|
|
|
log.info("合并命令:{}", sm.toString());
|
|
|
cUtil.cmd(sm.toString());
|
|
|
}
|
|
|
- Thread.sleep(2000L);
|
|
|
- for (String fileT : fileTs) {
|
|
|
- File ft = new File(fileT);
|
|
|
- if (ft.exists()) {
|
|
|
- ft.delete();
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+// for (String fileT : fileTs) {
|
|
|
+// File ft = new File(fileT);
|
|
|
+// if (ft.exists()) {
|
|
|
+// ft.delete();
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
public static List<Map<String, Object>> getRecordList(String channel, Date startTm, Date endTm) {
|
|
@@ -537,22 +549,6 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) throws InterruptedException, ParseException, IOException {
|
|
|
-// CameraUtil cameraUtil = new CameraUtil();
|
|
|
-// cameraUtil.closeRecording();
|
|
|
- String s = "/opt/streams/record/flv/42010001541320001116/20230403_235506_000506-22e1523b-d170-11ed-8a42-fa163e4e1e9f.flv";
|
|
|
- String substring = s.substring(0, s.lastIndexOf("."));
|
|
|
- System.out.println(substring);
|
|
|
-// String fileStr = s.substring(s.lastIndexOf("/") + 1, s.length());
|
|
|
-// String pathStr = s.substring(0, s.lastIndexOf("/"));
|
|
|
-// System.out.println(fileStr);
|
|
|
-// System.out.println(pathStr);
|
|
|
-
|
|
|
-// String s = "20230403235512";
|
|
|
-// Date sdate = DateUtils.dateTime(DateUtils.YYYYMMDDHHMMSS, s);
|
|
|
-// sdate = DateUtils.addDays(sdate, -1);
|
|
|
-// System.out.println(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, sdate));
|
|
|
- }
|
|
|
|
|
|
public static File[] getCurFilesList(String filePath) {
|
|
|
File path = new File(filePath);
|
|
@@ -684,6 +680,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
bakUrl = caneraConfig.getBakUrl();
|
|
|
recordUrl = caneraConfig.getRecordUrl();
|
|
|
cUtil = cmdCameraUtil;
|
|
|
+ rc = redisCache;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -781,9 +778,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
public void mergeVideo() {
|
|
|
Date date = new Date();
|
|
|
Calendar calendar = new GregorianCalendar();
|
|
|
-
|
|
|
-
|
|
|
- Map<String, Object> alarmIdMap = redisCache.getCacheMap("WAIT_MERGE_VIDEO_ALARM_ID");
|
|
|
+ Map<String, Object> alarmIdMap = redisCache.getCacheMap(mvkey);
|
|
|
log.info("WAIT_MERGE_VIDEO_ALARM_ID:{}", alarmIdMap);
|
|
|
if (!ObjectUtils.isEmpty(alarmIdMap)) {
|
|
|
Set<String> alarmIds = alarmIdMap.keySet();
|
|
@@ -801,6 +796,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
if (!StringUtils.isBlank(cameraChannelByAlarmId)) {
|
|
|
log.info("报警UUID:{},相机通道:{},开始时间:{},结束时间:{}", alarmId, cameraChannelByAlarmId, (Date) oTime, date);
|
|
|
String url = historyPlayListStr(cameraChannelByAlarmId, (Date) oTime, date);
|
|
|
+
|
|
|
redisCache.setCacheObject("STREAMING_ALARM_VIDEO:" + alarmId, url);
|
|
|
redisCache.expire("STREAMING_ALARM_VIDEO:" + alarmId, 365L, TimeUnit.DAYS);
|
|
|
alarmIdMap.remove(alarmId);
|
|
@@ -809,7 +805,54 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- redisCache.setCacheMap("WAIT_MERGE_VIDEO_ALARM_ID", alarmIdMap);
|
|
|
+ log.info("删除后的alarmIdMap:{}", alarmIdMap);
|
|
|
+ redisCache.deleteObject(mvkey);
|
|
|
+ redisCache.setCacheMap(mvkey, alarmIdMap);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ public void deleteTsFile() {
|
|
|
+ Date date = new Date();
|
|
|
+ Set<String> keys = new HashSet<>();
|
|
|
+ Calendar calendar = new GregorianCalendar();
|
|
|
+ Map<String, Object> mergeVideoTsFile = redisCache.getCacheMap("mergeVideoTsFile");
|
|
|
+ if (!ObjectUtils.isEmpty(mergeVideoTsFile) && mergeVideoTsFile.size() > 0) {
|
|
|
+ mergeVideoTsFile.keySet().forEach(s -> {
|
|
|
+ Object o = mergeVideoTsFile.get(s);
|
|
|
+ if (!ObjectUtils.isEmpty(o)) {
|
|
|
+ Map<Date, List<String>> m = (Map<Date, List<String>>) o;
|
|
|
+ if (!ObjectUtils.isEmpty(m) && m.size() > 0) {
|
|
|
+ m.keySet().forEach(md -> {
|
|
|
+ Date fileTime = (Date) md;
|
|
|
+ // 判断当前时间是否超过报警时间 20分钟
|
|
|
+ calendar.setTime(fileTime);
|
|
|
+ calendar.add(calendar.MINUTE, 10); //把日期往后增加一天,整数 往后推,负数往前移动
|
|
|
+ fileTime = calendar.getTime(); //这个时间就是日期往后推一天的结果
|
|
|
+ if (date.compareTo(fileTime) > 0) {
|
|
|
+ List<String> list = m.get(md);
|
|
|
+ for (String s1 : list) {
|
|
|
+ File ft = new File(s1);
|
|
|
+ if (ft.exists()) {
|
|
|
+ ft.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //
|
|
|
+ m.remove(md);
|
|
|
+ keys.add(s);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 删除key
|
|
|
+ if (keys.size() > 0) {
|
|
|
+ for (String s : mergeVideoTsFile.keySet()) {
|
|
|
+ mergeVideoTsFile.remove(s);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ redisCache.deleteObject("mergeVideoTsFile");
|
|
|
+ redisCache.setCacheMap("mergeVideoTsFile", mergeVideoTsFile);
|
|
|
}
|
|
|
}
|