Browse Source

Merge branch 'master' of http://124.70.58.209:3000/ytrd-project-management/GeoHazardMonitor

gao.qiang 2 years ago
parent
commit
415e869850

+ 18 - 1
hazard-admin/src/main/java/com/ozs/web/controller/accountmanagment/BaseCameraManagementController.java

@@ -27,6 +27,7 @@ import com.ozs.service.service.BaseDeviceDynamicManagementService;
 import com.ozs.service.service.BaseRailwayManagementService;
 import com.ozs.service.service.MsgAlarmService;
 import com.ozs.system.service.ISysDeptService;
+import com.ozs.web.core.config.CaneraConfig;
 import com.ozs.web.core.util.CameraUtil;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -80,6 +81,10 @@ public class BaseCameraManagementController extends BaseController {
     private MsgAlarmService msgAlarmService;
     @Autowired
     private BaseRailwayManagementService baseRailwayManagementService;
+    @Autowired
+    private ServerConfig serverConfig;
+    @Autowired
+    private CaneraConfig caneraConfig;
 
     /**
      * 相机台账管理分页
@@ -334,9 +339,21 @@ public class BaseCameraManagementController extends BaseController {
         if (ObjectUtils.isEmpty(one)) {
             throw new BaseException("相机编号【" + vo.getCameraCode() + "】不存在");
         }
-        return success(CameraUtil.historyPlayList(one.getChannel(), vo.getStartTime(), vo.getEntTime()));
+        return success(CameraUtil.historyPlayList(one.getChannel(), vo.getStartTime(), vo.getEntTime(), caneraConfig.getMappingUrl()));
     }
 
+    @ApiOperation("播放回放")
+    @PostMapping("/api/play")
+    public AjaxResult play(@Validated @RequestBody BaseCameraResVo vo) {
+        LambdaQueryWrapper<BaseCameraManagement> lw = new LambdaQueryWrapper<BaseCameraManagement>();
+        lw.eq(BaseCameraManagement::getCameraCode, vo.getCameraCode());
+        BaseCameraManagement one = baseCameraManagementService.getOne(lw);
+        if (ObjectUtils.isEmpty(one)) {
+            throw new BaseException("相机编号【" + vo.getCameraCode() + "】不存在");
+        }
+        return new AjaxResult(200, "ok", CameraUtil.historyPlayListStr(one.getChannel(), vo.getStartTime(), vo.getEntTime()));
+//        return success(CameraUtil.historyPlayList(one.getChannel(), vo.getStartTime(), vo.getEntTime()));
+    }
 
     @ApiOperation("视频服务设备数量")
     @GetMapping("/totalNumberOfDevices")

+ 5 - 0
hazard-admin/src/main/java/com/ozs/web/core/config/CaneraConfig.java

@@ -30,5 +30,10 @@ public class CaneraConfig {
     @Value("${base.mappingUrl:http://47.106.159.135/}")
     private String mappingUrl;
 
+    @Value("${base.filePath:/opt/streams/}")
+    private String filePath;
+
+    @Value("${base.flvPath:/opt/streams/record/flv/hazard/}")
+    private String flvPath;
 
 }

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

@@ -29,8 +29,10 @@ public class CameraUtil {
 
     private static String url;
     private static String historyUrl;
-    private static String ffmpegPath;
+    private static String ffmpegPath = "C:\\Users\\Administrator.DESKTOP-0NUUTMM\\Downloads\\ffmpeg-5.1.2-essentials_build\\ffmpeg-5.1.2-essentials_build\\bin\\ffmpeg.exe";
     private static String mappingUrl;
+    private static String flvPath;
+    private static String filePath;
     @Autowired
     private CaneraConfig caneraConfig;
 
@@ -45,13 +47,20 @@ public class CameraUtil {
      */
     public static String historyPlay(List<String> fromVideoFileList, String ph) throws IOException {
         // 视频服务映射路径
-        String NewfilePath = BaseConfig.getProfile() + ph;
+        String NewfilePath = flvPath + ph;
         log.info("NewfilePath:{}", NewfilePath);
         log.info("fromVideoFileList:{}", fromVideoFileList);
         convetor(fromVideoFileList, NewfilePath);
-        return "/profile" + ph;
+        return mappingUrl + "record/flv/hazard/" + ph;
     }
 
+    /**
+     * 实时播放的拼接流
+     *
+     * @param cameraCode 相机编码
+     * @param channel    相机通道
+     * @return
+     */
     public static String getPlayFlv(String cameraCode, String channel) {
         return historyUrl + "/hdl/" + channel + "/" + cameraCode + ".flv";
     }
@@ -72,7 +81,22 @@ public class CameraUtil {
     }
 
 
-    public static List<String> historyPlayList(String channel, Date startTm, Date endTm) {
+    public static String historyPlayListStr(String channel, Date startTm, Date endTm) {
+        List<String> list = historyPlayList(channel, startTm, endTm, filePath);
+        String ph = "flv/" + DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date())
+                + "-" + channel + "-"
+                + UUID.randomUUID().toString() + ".flv";
+        try {
+            return historyPlay(list, ph);
+        } catch (IOException e) {
+            log.error(e.getMessage());
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+    public static List<String> historyPlayList(String channel, Date startTm, Date endTm, String mappingUrl) {
         if (StringUtils.isBlank(channel)
                 || ObjectUtils.isEmpty(startTm)
                 || ObjectUtils.isEmpty(endTm)) {
@@ -84,9 +108,7 @@ public class CameraUtil {
         // 调用视频服务返回参数
         String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, startTm);
         String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, endTm);
-        String ph = "/flv/" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date())
-                + "/" + channel + "/" + startTime + "/" + endTime + "/"
-                + UUID.randomUUID().toString() + ".flv";
+
         String param = "channel=" + channel + "&startTime=" + startTime + "&endTime=" + endTime;
         String s = HttpUtils.sendGet(historyUrl + "/api/record/flv/list", param);
         // 视频拼接
@@ -104,19 +126,23 @@ public class CameraUtil {
                         String s4 = s2[0] + s2[2];
                         Date sdate = DateUtils.dateTime(DateUtils.YYYYMMDDHHMMSS, s3);
                         Date edate = DateUtils.dateTime(DateUtils.YYYYMMDDHHMMSS, s4);
-                        /*     s | e     | */
-                        if (startTm.compareTo(sdate) <= 0 && endTm.compareTo(edate) > 0) {
+                        /*     sdate  |startTm|  edate     |endTm| */
+                        if (startTm.compareTo(sdate) >= 0
+                                && startTm.compareTo(edate) <= 0
+                                && endTm.compareTo(edate) >= 0) {
                             m.put(sdate, mappingUrl + path.toString());
-                            /*  |   s    e    | */
-                        } else if (startTm.compareTo(sdate) >= 0 && endTm.compareTo(edate) <= 0) {
+                            /*  |startTm|   sdate    edate   |endTm| */
+                        } else if (startTm.compareTo(sdate) <= 0 && endTm.compareTo(edate) >= 0) {
                             m.put(sdate, mappingUrl + path.toString());
 
-                            /*  |   s     |  e  */
-                        } else if (startTm.compareTo(sdate) >= 0 && endTm.compareTo(edate) >= 0) {
+                            /*  |startTm|   sdate     |endTm|  edate  */
+                        } else if (startTm.compareTo(sdate) <= 0
+                                && endTm.compareTo(sdate) >= 0
+                                && endTm.compareTo(edate) <= 0) {
                             m.put(sdate, mappingUrl + path.toString());
 
-                            /*  s|      | e  */
-                        } else if (startTm.compareTo(sdate) <= 0 && endTm.compareTo(edate) >= 0) {
+                            /*  sdate |startTm|      |endTm| edate  */
+                        } else if (startTm.compareTo(sdate) >= 0 && endTm.compareTo(edate) <= 0) {
                             m.put(sdate, mappingUrl + path.toString());
                         }
                     }
@@ -130,23 +156,10 @@ public class CameraUtil {
                 ls.add(m.get(d));
             });
             return ls;
-//            try {
-//                return historyPlay(ls, ph);
-//            } catch (IOException e) {
-//                e.printStackTrace();
-//            }
         }
         return null;
     }
 
-    @PostConstruct
-    public void init() {
-        url = caneraConfig.getUrl();
-        mappingUrl = caneraConfig.getMappingUrl();
-        historyUrl = caneraConfig.getHistoryUrl();
-        ffmpegPath = caneraConfig.getFfmpegPath();
-    }
-
     /**
      * * 参数:
      * **List<String> fromVideoFileList 需要合并的多视频url地址以List存放**
@@ -156,100 +169,114 @@ public class CameraUtil {
     public static void convetor(List<String> fromVideoFileList,
                                 String NewfilePath) throws IOException {
 
-        new Thread(
-                () -> {
-                    try {
-                        List<String> voidTS = new ArrayList<>();
-                        Process process = null;
-                        ProcessBuilder builder = null;
-                        List<String> command = null;
-                        for (int i = 0; i < fromVideoFileList.size(); i++) {
-                            String fromVideoFile = fromVideoFileList.get(i);
-                            command = new ArrayList<String>();
-                            command.add(ffmpegPath);
-                            command.add("-y");
-                            command.add("-i");
-                            command.add(fromVideoFile);
-                            command.add("-vcodec");
-                            command.add("copy");
-                            command.add("-bsf:v");
-                            command.add("h264_mp4toannexb");
-                            command.add("-f");
-                            command.add("mpegts");
-                            command.add(fromVideoFile.substring(0,
-                                    fromVideoFile.lastIndexOf(".")) + ".ts");
-                            builder = new ProcessBuilder(command);
-                            voidTS.add(fromVideoFile.substring(0,
-                                    fromVideoFile.lastIndexOf("."))
-                                    + ".ts");
-                            try {
-                                process = builder.start();
-                                InputStream errorStream = process
-                                        .getErrorStream();
-                                InputStreamReader inputStreamReader = new InputStreamReader(
-                                        errorStream);
-                                BufferedReader br = new BufferedReader(
-                                        inputStreamReader);
-                                String line = "";
-                                StringBuffer sb = new StringBuffer();
-                                while ((line = br.readLine()) != null) {
-                                    sb.append(line);
-                                }
-                                String regexDuration = "Duration: (.*?), start: (.*?), bitrate: (\\d*) kb\\/s";
-                                Pattern pattern = Pattern
-                                        .compile(regexDuration);
-                                Matcher m = pattern.matcher(sb.toString());
-                                System.out.println(sb.toString());
-                                br.close();
-                                inputStreamReader.close();
-                                errorStream.close();
-                            } catch (IOException e) {
-                                e.printStackTrace();
-                            }
-                        }
-                        List<String> dos = new ArrayList<>();
-                        StringBuffer tsPath = new StringBuffer();
-                        tsPath.append(ffmpegPath);
-                        tsPath.append(" -i ");
-                        tsPath.append("concat:");
-                        for (int t = 0; t < voidTS.size(); t++) {
-                            if (t != voidTS.size() - 1) {
-                                tsPath.append(voidTS.get(t) + "|");
-                            } else {
-                                tsPath.append(voidTS.get(t));
-                            }
-                        }
-                        tsPath.append(" -vcodec ");
-                        tsPath.append(" copy ");
-                        tsPath.append(" -bsf:a ");
-                        tsPath.append(" aac_adtstoasc ");
-                        tsPath.append(" -movflags ");
-                        tsPath.append(" +faststart ");
-                        tsPath.append(NewfilePath);
-                        Process pr = Runtime.getRuntime().exec(
-                                tsPath.toString());
-                        process.getInputStream();
-                        pr.getOutputStream().close();
-                        pr.getInputStream().close();
-                        pr.getErrorStream().close();
-                        try {
-                            pr.waitFor();
-                            Thread.sleep(1000);
-                            pr.destroy();
-                        } catch (InterruptedException e) {
-                            // TODO Auto-generated catch block
-                            e.printStackTrace();
-                        }
-                        //删除生成的ts文件
-                        for (String filePath : voidTS) {
-                            File file = new File(filePath);
-                            file.delete();
-                            pr.destroy();
-                        }
-                    } catch (Exception e) {
-                        e.printStackTrace();
+
+        try {
+            List<String> voidTS = new ArrayList<>();
+            Process process = null;
+            ProcessBuilder builder = null;
+            List<String> command = null;
+            for (int i = 0; i < fromVideoFileList.size(); i++) {
+                String fromVideoFile = fromVideoFileList.get(i);
+                command = new ArrayList<String>();
+                command.add(ffmpegPath);
+                command.add("-y");
+                command.add("-i");
+                command.add(fromVideoFile);
+                command.add("-vcodec");
+                command.add("copy");
+                command.add("-bsf:v");
+                command.add("h264_mp4toannexb");
+                command.add("-f");
+                command.add("mpegts");
+                command.add(fromVideoFile.substring(0,
+                        fromVideoFile.lastIndexOf(".")) + ".ts");
+                builder = new ProcessBuilder(command);
+                voidTS.add(fromVideoFile.substring(0,
+                        fromVideoFile.lastIndexOf("."))
+                        + ".ts");
+                try {
+                    process = builder.start();
+                    InputStream errorStream = process
+                            .getErrorStream();
+                    InputStreamReader inputStreamReader = new InputStreamReader(
+                            errorStream);
+                    BufferedReader br = new BufferedReader(
+                            inputStreamReader);
+                    String line = "";
+                    StringBuffer sb = new StringBuffer();
+                    while ((line = br.readLine()) != null) {
+                        sb.append(line);
                     }
-                }).start();
+                    String regexDuration = "Duration: (.*?), start: (.*?), bitrate: (\\d*) kb\\/s";
+                    Pattern pattern = Pattern
+                            .compile(regexDuration);
+                    Matcher m = pattern.matcher(sb.toString());
+                    System.out.println(sb.toString());
+                    br.close();
+                    inputStreamReader.close();
+                    errorStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            List<String> dos = new ArrayList<>();
+            StringBuffer tsPath = new StringBuffer();
+            tsPath.append(ffmpegPath);
+            tsPath.append(" -i ");
+            tsPath.append("concat:");
+            for (int t = 0; t < voidTS.size(); t++) {
+                if (t != voidTS.size() - 1) {
+                    tsPath.append(voidTS.get(t) + "|");
+                } else {
+                    tsPath.append(voidTS.get(t));
+                }
+            }
+            tsPath.append(" -vcodec ");
+            tsPath.append(" copy ");
+            tsPath.append(" -bsf:a ");
+            tsPath.append(" aac_adtstoasc ");
+            tsPath.append(" -movflags ");
+            tsPath.append(" +faststart ");
+            tsPath.append(NewfilePath);
+            Process pr = Runtime.getRuntime().exec(
+                    tsPath.toString());
+            process.getInputStream();
+            pr.getOutputStream().close();
+            pr.getInputStream().close();
+            pr.getErrorStream().close();
+            try {
+                pr.waitFor();
+                Thread.sleep(1000);
+                pr.destroy();
+            } catch (InterruptedException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            //删除生成的ts文件
+            for (String filePath : voidTS) {
+                File file = new File(filePath);
+                file.delete();
+                pr.destroy();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void main(String[] args) throws IOException {
+
+        List<String> fromVideoFileList = new ArrayList();
+        String p = "C:\\Users\\Administrator.DESKTOP-0NUUTMM\\Desktop\\work\\106\\流媒体\\";
+        String newfilePath = p + "hb.flv";
+        fromVideoFileList.add(p + "20230303_174931_175031-d6d56396-b9a8-11ed-aeb9-00163e06a5f3.flv");
+        fromVideoFileList.add(p + "20230303_175032_175132-fb32b9fe-b9a8-11ed-aeb9-00163e06a5f3.flv");
+        fromVideoFileList.add(p + "20230303_175133_175233-1f97af04-b9a9-11ed-aeb9-00163e06a5f3.flv");
+        fromVideoFileList.add(p + "20230303_175234_175334-43f4daf1-b9a9-11ed-aeb9-00163e06a5f3.flv");
+        fromVideoFileList.add(p + "m.flv");
+        fromVideoFileList.add(p + "m33.flv");
+        fromVideoFileList.add(p + "mv.flv");
+        fromVideoFileList.add(p + "mvido.flv");
+        convetor(fromVideoFileList, newfilePath);
     }
 
     //工具类
@@ -266,40 +293,13 @@ public class CameraUtil {
         System.out.println(s);
     }
 
-
-    /**
-     * 合并多个视频文件
-     */
-    public static void mergeFile(List<String> fromVideoFileList, String NewfilePath) {
-        // 合并命令
-        String commit = "$0 -f concat -safe 0 -i $1 -c copy $2";
-
-        String str = commit.replace("$0", ffmpegPath);
-        if (!ObjectUtils.isEmpty(fromVideoFileList)) {
-            for (String s : fromVideoFileList) {
-                str = str.replace("$1", s);
-            }
-        }
-        str = str.replace("$2", NewfilePath);
-        System.out.println(str);
-        Runtime runtime = Runtime.getRuntime();
-        try {
-            Process proce = runtime.exec(str);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-    }
-
-    public static void main(String[] args) throws IOException {
-
-        List<String> fromVideoFileList = new ArrayList();
-        String p = "C:\\Users\\Administrator.DESKTOP-0NUUTMM\\Desktop\\work\\106\\流媒体\\";
-        String NewfilePath = p + "mergevideo.flv";
-        fromVideoFileList.add(p + "20230303_174931_175031-d6d56396-b9a8-11ed-aeb9-00163e06a5f3.flv");
-        fromVideoFileList.add(p + "20230303_175032_175132-fb32b9fe-b9a8-11ed-aeb9-00163e06a5f3.flv");
-        fromVideoFileList.add(p + "20230303_175133_175233-1f97af04-b9a9-11ed-aeb9-00163e06a5f3.flv");
-        fromVideoFileList.add(p + "20230303_175234_175334-43f4daf1-b9a9-11ed-aeb9-00163e06a5f3.flv");
-        convetor(fromVideoFileList, NewfilePath);
-
+    @PostConstruct
+    public void init() {
+        url = caneraConfig.getUrl();
+        mappingUrl = caneraConfig.getMappingUrl();
+        historyUrl = caneraConfig.getHistoryUrl();
+        ffmpegPath = caneraConfig.getFfmpegPath();
+        flvPath = caneraConfig.getFlvPath();
+        filePath = caneraConfig.getFilePath();
     }
 }

+ 6 - 4
hazard-admin/src/main/resources/application.yml

@@ -9,8 +9,8 @@ base:
   # 实例演示开关
   demoEnabled: true
   # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
-  #  profile: /data/service/hazard-admin/uploadPath
-  profile: C:\base\uploadPath
+  profile: /data/service/hazard-admin/uploadPath
+  #  profile: C:\base\uploadPath
   # 获取ip地址开关
   addressEnabled: false
   # 验证码类型 math 数组计算 char 字符验证
@@ -18,6 +18,8 @@ base:
   #  path: http://47.106.159.135:8554
   path: http://47.106.159.135:8554
   ffmpegPath: /usr/local/ffmpeg/bin/ffmpeg
+  mappingUrl: http://47.106.159.135/
+  filePath: /opt/streams/
 
 # 开发环境配置
 server:
@@ -25,7 +27,7 @@ server:
   port: 18819
   servlet:
     # 应用的访问路径
-    context-path: /
+    context-path: /hazard
   tomcat:
     # tomcat的URI编码
     uri-encoding: UTF-8
@@ -157,4 +159,4 @@ file:
   #头像存储目录
   avatarUrl: /data/service/avatar/
   #文件访问前缀
-  filreUrl: http://124.71.171.71:18878
+  filreUrl: http://124.71.171.71:18878

+ 9 - 9
hazard-admin/src/main/resources/logback.xml

@@ -1,18 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <configuration>
     <!-- 日志存放路径 -->
-	<property name="log.path" value="/home/base/logs" />
+    <property name="log.path" value="/data/service/hazard-admin/logs"/>
     <!-- 日志输出格式 -->
-	<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
+    <property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
 
-	<!-- 控制台输出 -->
-	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
-		<encoder>
-			<pattern>${log.pattern}</pattern>
-		</encoder>
-	</appender>
+    <!-- 控制台输出 -->
+    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+        </encoder>
+    </appender>
 
-	<!-- 系统日志输出 -->
+    <!-- 系统日志输出 -->
 	<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
 	    <file>${log.path}/sys-info.log</file>
         <!-- 循环政策:基于时间创建日志文件 -->