|
@@ -10,6 +10,7 @@ import com.ozs.common.core.redis.RedisCache;
|
|
|
import com.ozs.common.exception.base.BaseException;
|
|
|
import com.ozs.common.utils.DateUtils;
|
|
|
import com.ozs.common.utils.http.HttpUtils;
|
|
|
+import com.ozs.framework.config.ServerConfig;
|
|
|
import com.ozs.service.entity.BaseCameraManagement;
|
|
|
import com.ozs.service.service.BaseCameraManagementService;
|
|
|
import com.ozs.system.mapper.SysDictDataMapper;
|
|
@@ -19,8 +20,6 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
@@ -33,8 +32,6 @@ import java.util.*;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.regex.Matcher;
|
|
|
-import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -47,8 +44,7 @@ import java.util.stream.Collectors;
|
|
|
public class CameraUtil {
|
|
|
|
|
|
private static final ExecutorService executor = Executors.newFixedThreadPool(20);
|
|
|
- private static String historyUrl;
|
|
|
- private static String recordUrl;
|
|
|
+
|
|
|
private static String ffmpegPath;
|
|
|
private static String filePath;
|
|
|
private static String transcribeFilePath;
|
|
@@ -56,19 +52,33 @@ public class CameraUtil {
|
|
|
private static String bakUrl;
|
|
|
private static CmdCameraUtil cUtil;
|
|
|
private static RedisCache rc;
|
|
|
+ private static ServerConfig sc;
|
|
|
|
|
|
public final static String mvkey = "WAIT_MERGE_VIDEO_ALARM_ID";
|
|
|
+
|
|
|
+ public final static String tsFilekey = "mergeVideoTsFile";
|
|
|
+
|
|
|
+ // 相机配置
|
|
|
@Autowired
|
|
|
private CaneraConfig caneraConfig;
|
|
|
|
|
|
+ // 命令工具
|
|
|
@Autowired
|
|
|
private CmdCameraUtil cmdCameraUtil;
|
|
|
|
|
|
+ // 字典
|
|
|
@Autowired
|
|
|
private SysDictDataMapper dictDataMapper;
|
|
|
|
|
|
+ // redis
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
+
|
|
|
+ // redis
|
|
|
+ @Autowired
|
|
|
+ private ServerConfig serverConfig;
|
|
|
+
|
|
|
+
|
|
|
@Resource
|
|
|
BaseCameraManagementService baseCameraManagementService;
|
|
|
|
|
@@ -93,15 +103,6 @@ public class CameraUtil {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try {
|
|
|
-// Map<String, String> map = myConvetor(fromVideoFileList, NewfilePath, uuid);
|
|
|
-// if (!ObjectUtils.isEmpty(map)) {
|
|
|
-// cUtil.cmd(map.get("cmd"));
|
|
|
-// //删除生成的ts文件
|
|
|
-// File file1 = new File(map.get("path"));
|
|
|
-// if (file1.exists()) {
|
|
|
-// file1.delete();
|
|
|
-// }
|
|
|
-// }
|
|
|
txConvetor(fromVideoFileList, NewfilePath, uuid);
|
|
|
} catch (IOException e) {
|
|
|
log.error(e.getMessage());
|
|
@@ -146,7 +147,7 @@ public class CameraUtil {
|
|
|
* @return
|
|
|
*/
|
|
|
public static String startRecording(String cameraCode, String channel) {
|
|
|
- return historyUrl + "/api/record/flv/start?streamPath=" + channel + "/" + cameraCode;
|
|
|
+ return webUrl + "/api/record/flv/start?streamPath=" + channel + "/" + cameraCode;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -156,7 +157,7 @@ public class CameraUtil {
|
|
|
* @return
|
|
|
*/
|
|
|
public static String endRecording(String taskId) {
|
|
|
- return historyUrl + "/api/record/flv/stop?id=" + taskId;
|
|
|
+ return webUrl + "/api/record/flv/stop?id=" + taskId;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -211,7 +212,7 @@ public class CameraUtil {
|
|
|
String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, endTm);
|
|
|
|
|
|
String param = "channel=" + channel + "&startTime=" + startTime + "&endTime=" + endTime;
|
|
|
- String s = HttpUtils.sendGet(historyUrl + "/api/record/flv/list", param);
|
|
|
+ String s = HttpUtils.sendGet(webUrl + "/api/record/flv/list", param);
|
|
|
// 视频拼接
|
|
|
if (!StringUtils.isBlank(s) || "null".equals(s)) {
|
|
|
List<Map<String, Object>> maps = JSON.parseArray(s, Map.class);
|
|
@@ -412,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());
|
|
@@ -436,7 +435,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
}
|
|
|
|
|
|
public static List<Map<String, Object>> getRecordList(String channel, Date startTm, Date endTm) {
|
|
|
- return filterRecordList(channel, startTm, endTm, filePath, recordUrl + "/");
|
|
|
+ return filterRecordList(channel, startTm, endTm, filePath, sc.getUrl() + "/profile/");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -670,25 +669,11 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @PostConstruct
|
|
|
- public void init() {
|
|
|
- historyUrl = caneraConfig.getHistoryUrl();
|
|
|
- ffmpegPath = caneraConfig.getFfmpegPath();
|
|
|
- filePath = caneraConfig.getFilePath();
|
|
|
- transcribeFilePath = caneraConfig.getTranscribeFilePath();
|
|
|
- webUrl = caneraConfig.getWebUrl();
|
|
|
- bakUrl = caneraConfig.getBakUrl();
|
|
|
- recordUrl = caneraConfig.getRecordUrl();
|
|
|
- cUtil = cmdCameraUtil;
|
|
|
- rc = redisCache;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
public static List<Map<String, Object>> filterRecordList(String channel,
|
|
|
Date startTm,
|
|
|
Date endTm,
|
|
|
String mappingUrl,
|
|
|
- String webUrl) {
|
|
|
+ String wUrl) {
|
|
|
List<Map<String, Object>> rmaps = new ArrayList<>();
|
|
|
|
|
|
if (StringUtils.isBlank(channel)
|
|
@@ -702,7 +687,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, endTm);
|
|
|
|
|
|
String param = "channel=" + channel + "&startTime=" + startTime + "&endTime=" + endTime;
|
|
|
- String s = HttpUtils.sendGet(historyUrl + "/api/record/flv/list", param);
|
|
|
+ String s = HttpUtils.sendGet(webUrl + "/api/record/flv/list", param);
|
|
|
// 视频拼接
|
|
|
if (!StringUtils.isBlank(s) || "null".equals(s)) {
|
|
|
List<Map<String, Object>> maps = JSON.parseArray(s, Map.class);
|
|
@@ -730,7 +715,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
Date edate = DateUtils.dateTime(DateUtils.YYYYMMDDHHMMSS, s4);
|
|
|
mo.put("startTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, sdate));
|
|
|
mo.put("entTime", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, edate));
|
|
|
- mo.put("url", webUrl + path.toString());
|
|
|
+ mo.put("url", wUrl + path.toString());
|
|
|
mo.put("path", mappingUrl + path.toString());
|
|
|
mo.put("fileName", substring);
|
|
|
mo.put("size", size);
|
|
@@ -771,6 +756,18 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.flv
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ ffmpegPath = caneraConfig.getFfmpegPath();
|
|
|
+ filePath = caneraConfig.getFilePath();
|
|
|
+ transcribeFilePath = caneraConfig.getTranscribeFilePath();
|
|
|
+ webUrl = caneraConfig.getWebUrl();
|
|
|
+ bakUrl = caneraConfig.getBakUrl();
|
|
|
+ cUtil = cmdCameraUtil;
|
|
|
+ rc = redisCache;
|
|
|
+ sc = serverConfig;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 定时合成视频
|
|
@@ -779,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);
|
|
@@ -799,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);
|
|
@@ -814,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
|
|
@@ -852,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);
|
|
|
}
|