|
@@ -3,6 +3,8 @@ package com.ozs.utils;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.hikvision.artemis.sdk.ArtemisHttpUtil;
|
|
|
+import com.hikvision.artemis.sdk.config.ArtemisConfig;
|
|
|
import com.ozs.common.config.BaseConfig;
|
|
|
import com.ozs.common.constant.Constants;
|
|
|
import com.ozs.common.core.domain.entity.SysDictData;
|
|
@@ -81,6 +83,9 @@ public class CameraUtil {
|
|
|
private static ServerConfig sc;
|
|
|
private static String recordUrl;
|
|
|
private static String hkUrl;
|
|
|
+ private static String host;
|
|
|
+ private static String appKey;
|
|
|
+ private static String appSecret;
|
|
|
|
|
|
@Autowired
|
|
|
private CaneraConfig caneraConfig;
|
|
@@ -507,6 +512,9 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
wsUrl = caneraConfig.getWsUrl();
|
|
|
recordUrl = caneraConfig.getRecordUrl();
|
|
|
hkUrl = caneraConfig.getHkUrl();
|
|
|
+ host = caneraConfig.getHost();
|
|
|
+ appKey = caneraConfig.getAppKey();
|
|
|
+ appSecret = caneraConfig.getAppSecret();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -520,7 +528,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
Date date = new Date();
|
|
|
Calendar calendar = new GregorianCalendar();
|
|
|
calendar.setTime(date);
|
|
|
- calendar.add(calendar.DATE, -1); //把日期往后增加一天,整数 往后推,负数往前移动
|
|
|
+ calendar.add(Calendar.DATE, -1); //把日期往后增加一天,整数 往后推,负数往前移动
|
|
|
date = calendar.getTime(); //这个时间就是日期往后推一天的结果
|
|
|
String path = BaseConfig.getProfile() + "/flv/" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
|
|
|
File file = new File(path);
|
|
@@ -618,81 +626,6 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * 定时任务:关闭录制视频
|
|
|
-// *
|
|
|
-// * @throws IOException
|
|
|
-// * @throws InterruptedException
|
|
|
-// */
|
|
|
-// public void closeRecording() throws IOException, InterruptedException, ParseException {
|
|
|
-// LambdaQueryWrapper<BaseCameraManagement> wrapper = new LambdaQueryWrapper<>();
|
|
|
-// wrapper.eq(BaseCameraManagement::getStartRecording, 1);
|
|
|
-// wrapper.isNotNull(BaseCameraManagement::getTaskId);
|
|
|
-// List<BaseCameraManagement> list = baseCameraManagementService.list(wrapper);
|
|
|
-// log.info("list======================================" + list);
|
|
|
-// List<String> collect = list.stream().map(BaseCameraManagement::getCameraCode).collect(Collectors.toList());
|
|
|
-//// List<String> collect = new ArrayList<>();
|
|
|
-//// collect.add("42010001541320001116");
|
|
|
-// //遍历每个进行视频录制的摄像头
|
|
|
-// File file = new File(transcribeFilePath);
|
|
|
-// log.info("closeRecording-file.Name()======================================" + file.getName());
|
|
|
-// log.info("closeRecording-file.exists()======================================" + file.exists());
|
|
|
-// if (file.exists() && file.isDirectory()) {
|
|
|
-// //获取文件夹中所有的子文件夹和文件
|
|
|
-// File[] files = file.listFiles();
|
|
|
-// if (!ObjectUtils.isEmpty(files) && files.length > 0) {
|
|
|
-// for (File file1 : files) {
|
|
|
-// log.info("closeRecording-file1---------------" + file1);
|
|
|
-// log.info("closeRecording-cameraCode---------------" + collect);
|
|
|
-// String substring = file1.toString().substring(file1.toString().lastIndexOf("\\") + 1);
|
|
|
-// if (collect.contains(substring)) {
|
|
|
-// File[] files1 = CameraUtil.getCurFilesList(file1.toString());
|
|
|
-// if (!ObjectUtils.isEmpty(files1) && files1.length > 0) {
|
|
|
-// int length = files1.length;
|
|
|
-// File file2 = files1[length - 1];
|
|
|
-// log.info("closeRecording-file2---------------" + file2);
|
|
|
-// String time = file2.toString().substring(file2.toString().lastIndexOf("\\") + 1);
|
|
|
-// String substring1 = time.substring(0, 15);
|
|
|
-// String substring2 = substring1.substring(0, 4);
|
|
|
-// String substring3 = substring1.substring(4, 6);
|
|
|
-// String substring4 = substring1.substring(6, 8);
|
|
|
-// String substring5 = substring1.substring(9, 11);
|
|
|
-// String substring6 = substring1.substring(11, 13);
|
|
|
-// String substring7 = substring1.substring(13, 15);
|
|
|
-// String date = substring2 + "-" + substring3 + "-" + substring4 + " " + substring5 + ":" + substring6 + ":" + substring7;
|
|
|
-// System.out.println(date);
|
|
|
-// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
-// Date parse = sdf.parse(date);
|
|
|
-// //当前时间戳
|
|
|
-// long dades = System.currentTimeMillis();
|
|
|
-// //文件的时间戳
|
|
|
-// long time1 = parse.getTime();
|
|
|
-// //当前时间10分钟之前的时间戳
|
|
|
-// long time2 = dades - 600000L;
|
|
|
-// if (time2 <= time1 && time1 < dades) {
|
|
|
-// } else {
|
|
|
-// LambdaQueryWrapper<BaseCameraManagement> lw = new LambdaQueryWrapper<BaseCameraManagement>();
|
|
|
-// lw.eq(BaseCameraManagement::getCameraCode, substring);
|
|
|
-// BaseCameraManagement baseCameraManagement = baseCameraManagementService.getOne(lw);
|
|
|
-// log.info("closeRecording-endRecording------------" + baseCameraManagement.getTaskId());
|
|
|
-// String start = HttpUtils.sendGet(CameraUtil.endRecording(baseCameraManagement.getTaskId()));
|
|
|
-// log.info("closeRecording-endRecording------------" + start);
|
|
|
-// if ("success".equals(start)) {
|
|
|
-// baseCameraManagement.setStartRecording(2);
|
|
|
-// baseCameraManagement.setTaskId("");
|
|
|
-// } else {
|
|
|
-// baseCameraManagement.setStartRecording(2);
|
|
|
-// baseCameraManagement.setTaskId("");
|
|
|
-// log.error("关闭视频录制异常日志如下:" + start);
|
|
|
-// }
|
|
|
-// baseCameraManagementService.updateById(baseCameraManagement);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
|
|
|
public static File[] getCurFilesList(String filePath) {
|
|
|
File path = new File(filePath);
|
|
@@ -752,38 +685,6 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
}
|
|
|
|
|
|
executor.shutdown();
|
|
|
-
|
|
|
-// try {
|
|
|
-// Process proc = Runtime.getRuntime().exec("/bin/bash", null, null);
|
|
|
-// BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
|
|
|
-// PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())), true);
|
|
|
-// String commit = ffmpegPath+" -re -i /opt/streams/file/"+code+".mp4 -c:v copy -c:a copy -f rtsp rtsp://124.70.58.209:8554/live/"+code;
|
|
|
-// List<String> commands = new ArrayList<>();
|
|
|
-//
|
|
|
-// // 删除
|
|
|
-// commands.add(commit);
|
|
|
-// log.info("HTTP流转RTSP流:{}", commands);
|
|
|
-// for (String line : commands) {
|
|
|
-// out.println(line);
|
|
|
-// }
|
|
|
-// out.println("exit");// 这个命令必须执行,否则in流不结束。
|
|
|
-// String rspLine = "";
|
|
|
-// while ((rspLine = in.readLine()) != null) {
|
|
|
-// System.out.println(rspLine);
|
|
|
-//
|
|
|
-// }
|
|
|
-// int i = proc.waitFor();
|
|
|
-// log.info("执行结果:{}", i);
|
|
|
-//
|
|
|
-// in.close();
|
|
|
-// out.close();
|
|
|
-// proc.destroy();
|
|
|
-// } catch (IOException e) {
|
|
|
-// log.error(e.getMessage());
|
|
|
-// } catch (InterruptedException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -884,7 +785,9 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 机车状态修改
|
|
|
+ */
|
|
|
public void heartbeat() {
|
|
|
List<BaseTerminal> list = baseTerminalService.list();
|
|
|
for (BaseTerminal baseTerminal : list) {
|
|
@@ -915,24 +818,71 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 天网接口
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getPreviewURLs(String url, String body) {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
|
|
|
+ */
|
|
|
+ ArtemisConfig.host = host; // 平台的ip端口
|
|
|
+ ArtemisConfig.appKey = appKey; // 密钥appkey
|
|
|
+ ArtemisConfig.appSecret = appSecret;// 密钥appSecret
|
|
|
+
|
|
|
+ /**
|
|
|
+ * STEP2:设置OpenAPI接口的上下文
|
|
|
+ */
|
|
|
+ final String ARTEMIS_PATH = "/artemis";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * STEP3:设置接口的URI地址
|
|
|
+ */
|
|
|
+ final String previewURLsApi = ARTEMIS_PATH + url;
|
|
|
+ Map<String, String> path = new HashMap<String, String>(2) {
|
|
|
+ {
|
|
|
+ put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * STEP4:设置参数提交方式
|
|
|
+ */
|
|
|
+ String contentType = "application/json";
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * STEP6:调用接口
|
|
|
+ */
|
|
|
+ String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
|
|
|
+ log.info("GetCameraPreviewURL----->" + result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public void previewURLs(CamerasVo camerasVo) {
|
|
|
- String result = null;
|
|
|
- String url = "http://" + hkUrl + "/api/video/v2/cameras/previewURLs";
|
|
|
- try {
|
|
|
- result = HttpClientUtil.postJson(url, JSON.toJSONString(camerasVo));
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("previewURLs------------>" + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- JSONObject outJson = (JSONObject) JSONObject.parse(result);
|
|
|
+ /**
|
|
|
+ * jsonBody.put("cameraIndexCode", "01ea43e6676f4e47bd6c5cd9e02aa006");
|
|
|
+ * jsonBody.put("streamType", 0);
|
|
|
+ * jsonBody.put("protocol","rtsp");
|
|
|
+ * jsonBody.put("transmode", 1);
|
|
|
+ * jsonBody.put("expand","streamform=rtp");
|
|
|
+ */
|
|
|
+ camerasVo.setProtocol("rtsp");
|
|
|
+ camerasVo.setTransmode(1);
|
|
|
+ camerasVo.setExpand("streamform=rtp");
|
|
|
+ String body = JSONObject.toJSONString(camerasVo);
|
|
|
+ String previewURLs = getPreviewURLs("/api/video/v1/cameras/previewURLs", body);
|
|
|
+ log.info("-------------------------------->>>>>previewURLs" + previewURLs);
|
|
|
+ JSONObject outJson = JSONObject.parse(previewURLs);
|
|
|
if ("0".equals(outJson.getString("code"))) {
|
|
|
log.info("outJson----->" + outJson);
|
|
|
JSONObject data = outJson.getJSONObject("data");
|
|
|
String urls = data.getString("url");
|
|
|
HttpUtils.sendGet(historyUrl + "rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + camerasVo.getCameraIndexCode() + "&save=0");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public void playbackURLs(List<String> list) {
|
|
@@ -950,17 +900,11 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
playbackVo.setBeginTime(beforeTenMinutes.format(formatter));
|
|
|
playbackVo.setEndTime(afterTenMinutes.format(formatter));
|
|
|
-
|
|
|
-
|
|
|
- String result = null;
|
|
|
- String url = "http://" + hkUrl + "/api/video/v2/cameras/playbackURLs";
|
|
|
- try {
|
|
|
- result = HttpClientUtil.postJson(url, JSON.toJSONString(playbackVo));
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("playbackURLs------------>" + e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- JSONObject outJson = (JSONObject) JSONObject.parse(result);
|
|
|
+ //对象转换json字符串
|
|
|
+ String body = JSONObject.toJSONString(playbackVo);
|
|
|
+ //调用天网接口
|
|
|
+ String previewURLs = getPreviewURLs("/api/video/v1/cameras/playbackURLs", body);
|
|
|
+ JSONObject outJson = (JSONObject) JSONObject.parse(previewURLs);
|
|
|
if ("0".equals(outJson.getString("code"))) {
|
|
|
log.info("outJson----->" + outJson);
|
|
|
JSONObject data = outJson.getJSONObject("data");
|