|
@@ -56,6 +56,8 @@ public class CameraUtil {
|
|
|
|
|
|
public final static String mvkey = "WAIT_MERGE_VIDEO_ALARM_ID";
|
|
|
|
|
|
+ public final static String tsFilekey = "mergeVideoTsFile";
|
|
|
+
|
|
|
// 相机配置
|
|
|
@Autowired
|
|
|
private CaneraConfig caneraConfig;
|
|
@@ -411,15 +413,13 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
}
|
|
|
|
|
|
if (fileTs.size() > 0) {
|
|
|
- Map<String, Object> mergeVideoTsFile = rc.getCacheMap("mergeVideoTsFile");
|
|
|
+ Map<String, Object> mergeVideoTsFile = rc.getCacheMap(tsFilekey);
|
|
|
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);
|
|
|
+ mergeVideoTsFile.put(new Date().getTime() + "", fileTs);
|
|
|
+ rc.deleteObject(tsFilekey);
|
|
|
+ rc.setCacheMap(tsFilekey, mergeVideoTsFile);
|
|
|
|
|
|
sm.append("-c copy " + newfilePath);
|
|
|
log.info("合并命令:{}", sm.toString());
|
|
@@ -776,9 +776,11 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
Date date = new Date();
|
|
|
Calendar calendar = new GregorianCalendar();
|
|
|
Map<String, Object> alarmIdMap = redisCache.getCacheMap(mvkey);
|
|
|
+ List<String> dl = new ArrayList<>();
|
|
|
log.info("WAIT_MERGE_VIDEO_ALARM_ID:{}", alarmIdMap);
|
|
|
if (!ObjectUtils.isEmpty(alarmIdMap)) {
|
|
|
Set<String> alarmIds = alarmIdMap.keySet();
|
|
|
+ log.info("mergeVideo方法:alarmIds:{}", alarmIds);
|
|
|
if (!ObjectUtils.isEmpty(alarmIds) && alarmIds.size() > 0) {
|
|
|
for (String alarmId : alarmIds) {
|
|
|
Object oTime = alarmIdMap.get(alarmId);
|
|
@@ -796,12 +798,17 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
|
|
|
redisCache.setCacheObject("STREAMING_ALARM_VIDEO:" + alarmId, url);
|
|
|
redisCache.expire("STREAMING_ALARM_VIDEO:" + alarmId, 365L, TimeUnit.DAYS);
|
|
|
- alarmIdMap.remove(alarmId);
|
|
|
+ dl.add(alarmId);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if (dl.size() > 0) {
|
|
|
+ for (String s : dl) {
|
|
|
+ alarmIdMap.remove(s);
|
|
|
+ }
|
|
|
+ }
|
|
|
log.info("删除后的alarmIdMap:{}", alarmIdMap);
|
|
|
redisCache.deleteObject(mvkey);
|
|
|
redisCache.setCacheMap(mvkey, alarmIdMap);
|
|
@@ -811,35 +818,26 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
|
|
|
public void deleteTsFile() {
|
|
|
Date date = new Date();
|
|
|
- Set<String> keys = new HashSet<>();
|
|
|
+ List<String> keys = new ArrayList<>();
|
|
|
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);
|
|
|
- }
|
|
|
- });
|
|
|
+ Date fileTime = new Date(Long.parseLong(s));
|
|
|
+ calendar.setTime(fileTime);
|
|
|
+ calendar.add(calendar.MINUTE, 10); //把日期往后增加10分钟,整数 往后推,负数往前移动
|
|
|
+ fileTime = calendar.getTime(); //这个时间就是日期往后推一天的结果
|
|
|
+ if (date.compareTo(fileTime) > 0) {
|
|
|
+ List<String> list = (List<String>) o;
|
|
|
+ for (String s1 : list) {
|
|
|
+ File ft = new File(s1);
|
|
|
+ if (ft.exists()) {
|
|
|
+ ft.delete();
|
|
|
+ }
|
|
|
}
|
|
|
+ //
|
|
|
+ keys.add(s);
|
|
|
}
|
|
|
});
|
|
|
// 删除key
|
|
@@ -849,6 +847,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ log.info("mergeVideoTsFile:{}", mergeVideoTsFile);
|
|
|
redisCache.deleteObject("mergeVideoTsFile");
|
|
|
redisCache.setCacheMap("mergeVideoTsFile", mergeVideoTsFile);
|
|
|
}
|