소스 검색

视频回放

hexiao 1 년 전
부모
커밋
47f3627def

+ 10 - 0
hazard-admin/src/main/java/com/ozs/web/controller/tool/TestController.java

@@ -65,6 +65,16 @@ public class TestController extends BaseController {
         return R.ok();
     }
 
+    @GetMapping("/deleteTs")
+    public R<String> deleteTs() {
+        try {
+            cameraUtil.deleteTsFile();
+        } catch (Exception e) {
+            return R.ok(e.getMessage().toString());
+        }
+        return R.ok();
+    }
+
     @ApiOperation("获取用户列表")
     @GetMapping("/list")
     public R<List<UserEntity>> userList() {

+ 57 - 7
hazard-admin/src/main/java/com/ozs/web/core/util/CameraUtil.java

@@ -55,7 +55,7 @@ public class CameraUtil {
     private static String webUrl;
     private static String bakUrl;
     private static CmdCameraUtil cUtil;
-
+    private static RedisCache rc;
     @Autowired
     private CaneraConfig caneraConfig;
 
@@ -414,13 +414,19 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
             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();
-            }
+        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);
+//        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) {
@@ -684,6 +690,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
         bakUrl = caneraConfig.getBakUrl();
         recordUrl = caneraConfig.getRecordUrl();
         cUtil = cmdCameraUtil;
+        rc = redisCache;
     }
 
 
@@ -812,4 +819,47 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
         redisCache.setCacheMap("WAIT_MERGE_VIDEO_ALARM_ID", 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);
+                }
+            }
+        }
+    }
 }