|
@@ -28,6 +28,9 @@ import java.io.*;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
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;
|
|
@@ -46,9 +49,14 @@ public class CameraUtil {
|
|
|
private static String transcribeFilePath;
|
|
|
private static String webUrl;
|
|
|
private static String bakUrl;
|
|
|
+ private static CmdCameraUtil cUtil;
|
|
|
|
|
|
@Autowired
|
|
|
private CaneraConfig caneraConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CmdCameraUtil cmdCameraUtil;
|
|
|
+
|
|
|
@Autowired
|
|
|
private SysDictDataMapper dictDataMapper;
|
|
|
@Resource
|
|
@@ -63,7 +71,7 @@ public class CameraUtil {
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public static String historyPlay(List<String> fromVideoFileList, String ph) {
|
|
|
+ public static String historyPlay(List<String> fromVideoFileList, String ph, String uuid) {
|
|
|
// 视频服务映射路径
|
|
|
String NewfilePath = BaseConfig.getProfile() + "/" + ph;
|
|
|
log.info("NewfilePath:{}", NewfilePath);
|
|
@@ -71,14 +79,29 @@ public class CameraUtil {
|
|
|
if (ObjectUtils.isEmpty(fromVideoFileList) || fromVideoFileList.size() <= 0) {
|
|
|
throw new BaseException("当前相机无视频录像");
|
|
|
}
|
|
|
- new Thread(() -> {
|
|
|
- try {
|
|
|
- myConvetor(fromVideoFileList, NewfilePath);
|
|
|
- } catch (IOException e) {
|
|
|
- log.error(e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
+ ExecutorService executor = Executors.newFixedThreadPool(10);
|
|
|
+
|
|
|
+ executor.submit(new Runnable() {
|
|
|
+ @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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
- }).start();
|
|
|
+ });
|
|
|
+ executor.shutdown();
|
|
|
+
|
|
|
return Constants.RESOURCE_PREFIX + "/" + ph;
|
|
|
}
|
|
|
|
|
@@ -94,6 +117,12 @@ public class CameraUtil {
|
|
|
return bakUrl + "/hdl/" + channel + "/" + cameraCode + ".flv";
|
|
|
}
|
|
|
return webUrl + "/hdl/" + channel + "/" + cameraCode + ".flv";
|
|
|
+
|
|
|
+
|
|
|
+// if (!flay) {
|
|
|
+// return bakUrl + "/ws/" + channel + "/" + cameraCode + ".flv";
|
|
|
+// }
|
|
|
+// return webUrl + "/ws/" + channel + "/" + cameraCode + ".flv";
|
|
|
}
|
|
|
|
|
|
public static String getPlayFlv(String cameraCode, String channel) {
|
|
@@ -132,12 +161,13 @@ public class CameraUtil {
|
|
|
*/
|
|
|
public static String historyPlayListStr(String channel, Date startTm, Date endTm) {
|
|
|
List<String> list = filterPlayList(channel, startTm, endTm, filePath);
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
String ph = "flv/" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date())
|
|
|
+ "/" + channel + "/"
|
|
|
- + UUID.randomUUID().toString() + ".flv";
|
|
|
+ + uuid + ".flv";
|
|
|
if (!ObjectUtils.isEmpty(list)) {
|
|
|
try {
|
|
|
- return historyPlay(list, ph);
|
|
|
+ return historyPlay(list, ph, uuid);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
e.printStackTrace();
|
|
@@ -187,9 +217,13 @@ public class CameraUtil {
|
|
|
String substring1 = substring.substring(0, substring.indexOf("-"));
|
|
|
String[] s2 = substring1.split("_");
|
|
|
if (!ObjectUtils.isEmpty(s2)) {
|
|
|
+
|
|
|
String s3 = s2[0] + s2[1];
|
|
|
String s4 = s2[0] + s2[2];
|
|
|
Date sdate = DateUtils.dateTime(DateUtils.YYYYMMDDHHMMSS, s3);
|
|
|
+ if (s2[1].startsWith("23") && s2[2].startsWith("00")) {
|
|
|
+ sdate = DateUtils.addDays(sdate, -1);
|
|
|
+ }
|
|
|
Date edate = DateUtils.dateTime(DateUtils.YYYYMMDDHHMMSS, s4);
|
|
|
/* sdate |startTm| edate |endTm| */
|
|
|
if (startTm.compareTo(sdate) >= 0
|
|
@@ -232,14 +266,14 @@ public class CameraUtil {
|
|
|
* @param newfilePath 生产新的视频文件路径
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public static void myConvetor(List<String> fromVideoFileList,
|
|
|
- String newfilePath) throws IOException {
|
|
|
+ public static Map<String, String> myConvetor(List<String> fromVideoFileList,
|
|
|
+ String newfilePath,
|
|
|
+ String uuid) throws IOException {
|
|
|
/*
|
|
|
* for f in *.flv; do echo "file '$f'" >> mylist.txt; done
|
|
|
ffmpeg -f concat -i mylist.txt -c copy output.flv
|
|
|
* */
|
|
|
|
|
|
- List<String> rspList = new ArrayList<String>();
|
|
|
File file = new File(newfilePath);
|
|
|
boolean flay = false;
|
|
|
if (!file.getParentFile().exists()) {
|
|
@@ -251,18 +285,24 @@ public class CameraUtil {
|
|
|
|
|
|
|
|
|
StringBuffer sm = new StringBuffer("for f in ");
|
|
|
+ String pathStr = null;
|
|
|
for (int t = 0; t < fromVideoFileList.size(); t++) {
|
|
|
File ft = new File(fromVideoFileList.get(t));
|
|
|
if (ft.exists()) {
|
|
|
if (t != fromVideoFileList.size() - 1) {
|
|
|
- sm.append(fromVideoFileList.get(t) + " ");
|
|
|
+// sm.append(fromVideoFileList.get(t) + " ");
|
|
|
+ sm.append(fromVideoFileList.get(t).substring(fromVideoFileList.get(t).lastIndexOf("/") + 1, fromVideoFileList.get(t).length()) + " ");
|
|
|
} else {
|
|
|
- sm.append(fromVideoFileList.get(t));
|
|
|
+// sm.append(fromVideoFileList.get(t));
|
|
|
+ sm.append(fromVideoFileList.get(t).substring(fromVideoFileList.get(t).lastIndexOf("/") + 1, fromVideoFileList.get(t).length()));
|
|
|
+ pathStr = fromVideoFileList.get(t).substring(0, fromVideoFileList.get(t).lastIndexOf("/"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- String substring = newfilePath.substring(0, newfilePath.lastIndexOf("."));
|
|
|
- substring = substring + ".txt";
|
|
|
+// String substring = newfilePath.substring(0, newfilePath.lastIndexOf("."));
|
|
|
+// substring = substring + ".txt";
|
|
|
+
|
|
|
+ String substring = uuid + ".txt";
|
|
|
log.info("临时转化的文件:{}", substring);
|
|
|
|
|
|
|
|
@@ -274,39 +314,47 @@ public class CameraUtil {
|
|
|
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())), true);
|
|
|
|
|
|
try {
|
|
|
- String commit1 = ffmpegPath + " -f concat -safe 0 -i " + substring + " -c copy " + newfilePath;
|
|
|
+ String commit1 = ffmpegPath + " -f concat -safe 0 -i " + pathStr + "/" + substring + " -c copy " + newfilePath;
|
|
|
+
|
|
|
+ log.info("合并视频命令:{}", commit1);
|
|
|
List<String> commands = new ArrayList<>();
|
|
|
if (flay) {
|
|
|
commands.add("chomd -R 777 " + file.getParentFile().getPath());
|
|
|
}
|
|
|
+ //
|
|
|
+ commands.add("cd " + pathStr);
|
|
|
// 合并成一个临时文件
|
|
|
commands.add(commit);
|
|
|
+
|
|
|
// 临时文件转化为 flv
|
|
|
- commands.add(commit1);
|
|
|
+// commands.add(commit1);
|
|
|
+ log.info("录像视频命令:{}", commands);
|
|
|
for (String line : commands) {
|
|
|
+ log.info("命令:{}", line);
|
|
|
out.println(line);
|
|
|
}
|
|
|
out.println("exit");// 这个命令必须执行,否则in流不结束。
|
|
|
+ log.info("命令:{}", "exit");
|
|
|
String rspLine = "";
|
|
|
while ((rspLine = in.readLine()) != null) {
|
|
|
- System.out.println(rspLine);
|
|
|
- rspList.add(rspLine);
|
|
|
- }
|
|
|
- int i = proc.waitFor();
|
|
|
- log.info("执行结果:{}", i);
|
|
|
- //删除生成的ts文件
|
|
|
- File file1 = new File(substring);
|
|
|
- if (file1.exists()) {
|
|
|
- file1.delete();
|
|
|
+ log.info("*****:{}", rspLine);
|
|
|
}
|
|
|
+ proc.waitFor();
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("cmd", commit1);
|
|
|
+ map.put("path", pathStr + "/" + substring);
|
|
|
+ return map;
|
|
|
+
|
|
|
+
|
|
|
} catch (InterruptedException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
in.close();
|
|
|
out.close();
|
|
|
proc.destroy();
|
|
|
}
|
|
|
- log.info("返回结果:{}", rspList);
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -318,6 +366,7 @@ public class CameraUtil {
|
|
|
transcribeFilePath = caneraConfig.getTranscribeFilePath();
|
|
|
webUrl = caneraConfig.getWebUrl();
|
|
|
bakUrl = caneraConfig.getBakUrl();
|
|
|
+ cUtil = cmdCameraUtil;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -345,6 +394,7 @@ public class CameraUtil {
|
|
|
|
|
|
// 删除
|
|
|
commands.add(commit);
|
|
|
+ log.info("删除昨天的录像视频命令:{}", commands);
|
|
|
for (String line : commands) {
|
|
|
out.println(line);
|
|
|
}
|
|
@@ -522,8 +572,28 @@ public class CameraUtil {
|
|
|
return listFiles;
|
|
|
}
|
|
|
|
|
|
+ public static void execute(String command) {
|
|
|
+ try {
|
|
|
+ ProcessBuilder process = new ProcessBuilder(command);
|
|
|
+ process.inheritIO().start().waitFor();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) throws InterruptedException, ParseException, IOException {
|
|
|
- CameraUtil cameraUtil = new CameraUtil();
|
|
|
- cameraUtil.closeRecording();
|
|
|
+// CameraUtil cameraUtil = new CameraUtil();
|
|
|
+// cameraUtil.closeRecording();
|
|
|
+// String s = "/opt/streams/record/flv/42010001541320001116/20230403_235506_000506-22e1523b-d170-11ed-8a42-fa163e4e1e9f.flv";
|
|
|
+// String fileStr = s.substring(s.lastIndexOf("/") + 1, s.length());
|
|
|
+// String pathStr = s.substring(0, s.lastIndexOf("/"));
|
|
|
+// System.out.println(fileStr);
|
|
|
+// System.out.println(pathStr);
|
|
|
+
|
|
|
+ String s = "20230403235512";
|
|
|
+ Date sdate = DateUtils.dateTime(DateUtils.YYYYMMDDHHMMSS, s);
|
|
|
+ sdate = DateUtils.addDays(sdate, -1);
|
|
|
+ System.out.println(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, sdate));
|
|
|
}
|
|
|
}
|