|
@@ -35,12 +35,15 @@ import java.util.stream.Collectors;
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.jcraft.jsch.Channel;
|
|
|
import com.jcraft.jsch.ChannelExec;
|
|
|
import com.jcraft.jsch.JSch;
|
|
|
import com.jcraft.jsch.JSchException;
|
|
|
import com.jcraft.jsch.Session;
|
|
|
+import com.ozs.common.utils.HttpClientUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -509,10 +512,88 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
rc.setCacheMap(tsFilekey, mergeVideoTsFile);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 旧的视频服务的回放视频接口
|
|
|
+ *
|
|
|
+ * @param channel
|
|
|
+ * @param startTm
|
|
|
+ * @param endTm
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public static List<Map<String, Object>> getRecordList(String channel, Date startTm, Date endTm) {
|
|
|
return filterRecordList(channel, startTm, endTm, filePath, recordUrl + "/profile/");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新的视频服务的回放视频接口
|
|
|
+ *
|
|
|
+ * @param cameraCode
|
|
|
+ * @param channel
|
|
|
+ * @param startTm
|
|
|
+ * @param endTm
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getRecordUrl(String cameraCode, String channel, Date startTm, Date endTm) {
|
|
|
+ String result = null;
|
|
|
+ String url = webUrl + "/api/gb28181/invite?id=" + cameraCode + "&channel=" + channel + "&startTime=" + startTm + "&endTime=" + endTm;
|
|
|
+ try {
|
|
|
+ result = HttpClientUtil.get(url);
|
|
|
+ if (result.equals("200")) {
|
|
|
+ String path = apiSummary(cameraCode + "/" + channel+"/"+startTm.getTime()/1000+"-"+endTm.getTime()/1000);
|
|
|
+ if (StringUtils.isNotEmpty(path)){
|
|
|
+ return path;
|
|
|
+ }else {
|
|
|
+ return "当前相机暂无回放视频";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info(e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 调用流媒体获取流列表信息
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String apiSummary(String path) {
|
|
|
+ int maxRetries = 5;
|
|
|
+ int retryCount = 0;
|
|
|
+ boolean success = false;
|
|
|
+ JSONArray streamArray = null;
|
|
|
+ while (!success && retryCount < maxRetries) {
|
|
|
+ try {
|
|
|
+ String data = HttpClientUtil.gets(webUrl + "/api/summary");
|
|
|
+ log.info("data------------------>" + data);
|
|
|
+ if (StringUtils.isNotEmpty(data)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
+ streamArray = jsonObject.getJSONArray("Streams");
|
|
|
+ success = true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("Exception caught: " + e.getMessage());
|
|
|
+ // 增加重试计数
|
|
|
+ retryCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!ObjectUtils.isEmpty(streamArray)) {
|
|
|
+ for (int i = 0; i < streamArray.size(); i++) {
|
|
|
+ JSONObject subObj = streamArray.getJSONObject(i);
|
|
|
+ String streamPath = subObj.getString("StreamPath");
|
|
|
+ if (streamPath.equals(path)) {
|
|
|
+ //取出VideoTracks
|
|
|
+ JSONArray videoJson = subObj.getJSONArray("VideoTracks");
|
|
|
+ if (videoJson != null && videoJson.size() > 0) {
|
|
|
+ return wsUrl + "/ws/" + streamPath;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 定时任务参数flv文件
|
|
|
* -----------------------------废弃
|
|
@@ -738,6 +819,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
|
|
|
/**
|
|
|
* 旧的视频回放的接口
|
|
|
+ *
|
|
|
* @param channel
|
|
|
* @param startTm
|
|
|
* @param endTm
|
|
@@ -1148,7 +1230,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
removePrice();
|
|
|
}
|
|
|
|
|
|
- public void removePrice() {
|
|
|
+ public void removePrice() {
|
|
|
String host = "124.70.58.209"; // 远程主机
|
|
|
String user = "root"; // SSH用户名
|
|
|
String password = "y06ak@ql95K50"; // SSH密码
|
|
@@ -1184,7 +1266,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
BufferedReader reader2 = new BufferedReader(new InputStreamReader(in2));
|
|
|
while ((line = reader2.readLine()) != null) {
|
|
|
System.out.println(line); // 输出第二次`ls -l`的结果
|
|
|
- commandOutput.append("/"+line);
|
|
|
+ commandOutput.append("/" + line);
|
|
|
|
|
|
// 执行第三次命令输出
|
|
|
Channel channel3 = session.openChannel("exec");
|
|
@@ -1195,8 +1277,8 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
BufferedReader reader3 = new BufferedReader(new InputStreamReader(in3));
|
|
|
while ((line = reader3.readLine()) != null) {
|
|
|
System.out.println(line); // 输出第三次`ls -l`的结果
|
|
|
- commandOutput.append("/"+line);
|
|
|
-
|
|
|
+ commandOutput.append("/" + line);
|
|
|
+
|
|
|
// 执行第四次命令输出
|
|
|
Channel channel4 = session.openChannel("exec");
|
|
|
((ChannelExec) channel4).setCommand("ls " + commandOutput.toString()); // 在远程服务器上执行第四次`ls`命令
|
|
@@ -1206,7 +1288,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
BufferedReader reader4 = new BufferedReader(new InputStreamReader(in4));
|
|
|
while ((line = reader4.readLine()) != null) {
|
|
|
System.out.println(line); // 输出第四次`ls -l`的结果
|
|
|
- commandOutput.append("/"+line);
|
|
|
+ commandOutput.append("/" + line);
|
|
|
// 执行第五次命令输出
|
|
|
Channel channel5 = session.openChannel("exec");
|
|
|
((ChannelExec) channel5).setCommand("ls -l " + commandOutput.toString()); // 在远程服务器上执行第五次`ls`命令
|
|
@@ -1219,31 +1301,31 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
Pattern pattern = Pattern.compile("\\S+$"); // 匹配最后一个非空白字符之后的内容,即文件名
|
|
|
Matcher matcher = pattern.matcher(line);
|
|
|
if (matcher.find()) {
|
|
|
- long date = getDate(line,matcher.group());
|
|
|
+ long date = getDate(line, matcher.group());
|
|
|
System.out.println(matcher.group());
|
|
|
- if ((int)date<=-7){
|
|
|
+ if ((int) date <= -7) {
|
|
|
//执行删除
|
|
|
- System.out.println("执行删除:"+date);
|
|
|
+ System.out.println("执行删除:" + date);
|
|
|
Channel channel6 = session.openChannel("exec");
|
|
|
- System.out.println("参数"+commandOutput+"/"+matcher.group());
|
|
|
- ((ChannelExec) channel6).setCommand("rm -rf "+commandOutput+"/"+matcher.group());
|
|
|
+ System.out.println("参数" + commandOutput + "/" + matcher.group());
|
|
|
+ ((ChannelExec) channel6).setCommand("rm -rf " + commandOutput + "/" + matcher.group());
|
|
|
InputStream in6 = channel6.getInputStream();
|
|
|
channel6.connect();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
channel5.disconnect();
|
|
|
- commandOutput.setLength(commandOutput.length()-1);
|
|
|
+ commandOutput.setLength(commandOutput.length() - 1);
|
|
|
}
|
|
|
channel4.disconnect();
|
|
|
- commandOutput.setLength(commandOutput.length()-1);
|
|
|
+ commandOutput.setLength(commandOutput.length() - 1);
|
|
|
}
|
|
|
channel3.disconnect();
|
|
|
- commandOutput.setLength(commandOutput.length()-1);
|
|
|
-
|
|
|
+ commandOutput.setLength(commandOutput.length() - 1);
|
|
|
+
|
|
|
}
|
|
|
channel2.disconnect();
|
|
|
- commandOutput.setLength(commandOutput.length()-1);
|
|
|
+ commandOutput.setLength(commandOutput.length() - 1);
|
|
|
}
|
|
|
channel.disconnect();
|
|
|
session.disconnect();
|
|
@@ -1251,8 +1333,8 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
System.out.println(e);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public static long getDate(String text,String two){
|
|
|
+
|
|
|
+ public static long getDate(String text, String two) {
|
|
|
|
|
|
// 使用空格分割字符串
|
|
|
String[] parts = text.split(" ");
|
|
@@ -1274,7 +1356,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
LocalDate currentDate = LocalDate.now();
|
|
|
long daysDiff = ChronoUnit.DAYS.between(currentDate, date);
|
|
|
System.out.println("Days difference with current date: " + daysDiff);
|
|
|
- return daysDiff;
|
|
|
+ return daysDiff;
|
|
|
} catch (DateTimeParseException e) {
|
|
|
System.out.println("Error parsing date: " + e.getMessage());
|
|
|
}
|
|
@@ -1306,7 +1388,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
String day = dateParts[1];
|
|
|
int num = Integer.parseInt(day);
|
|
|
if (num >= 1 && num <= 9) {
|
|
|
- day="0"+day;
|
|
|
+ day = "0" + day;
|
|
|
}
|
|
|
String fullDateStr = month + " " + day + " " + defaultYear;
|
|
|
|