Browse Source

相机回放视频过滤排序

hexiao 2 years ago
parent
commit
14f9f5dbc1

+ 5 - 2
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;
@@ -82,6 +83,8 @@ public class BaseCameraManagementController extends BaseController {
     private BaseRailwayManagementService baseRailwayManagementService;
     @Autowired
     private ServerConfig serverConfig;
+    @Autowired
+    private CaneraConfig caneraConfig;
 
     /**
      * 相机台账管理分页
@@ -335,7 +338,7 @@ public class BaseCameraManagementController extends BaseController {
         if (ObjectUtils.isEmpty(one)) {
             throw new BaseException("相机编号【" + vo.getCameraCode() + "】不存在");
         }
-        return success(CameraUtil.historyPlayList(one.getChannel(), vo.getStartTime(), vo.getEntTime(), "http://47.106.159.135/"));
+        return success(CameraUtil.historyPlayList(one.getChannel(), vo.getStartTime(), vo.getEntTime(), caneraConfig.getMappingUrl()));
     }
 
     @ApiOperation("播放回放")
@@ -347,7 +350,7 @@ public class BaseCameraManagementController extends BaseController {
         if (ObjectUtils.isEmpty(one)) {
             throw new BaseException("相机编号【" + vo.getCameraCode() + "】不存在");
         }
-        return new AjaxResult(200, "ok", serverConfig.getUrl() + CameraUtil.historyPlayListStr(one.getChannel(), vo.getStartTime(), vo.getEntTime()));
+        return new AjaxResult(200, "ok", CameraUtil.historyPlayListStr(one.getChannel(), vo.getStartTime(), vo.getEntTime()));
 //        return success(CameraUtil.historyPlayList(one.getChannel(), vo.getStartTime(), vo.getEntTime()));
     }
 

+ 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;
 
 }

+ 123 - 154
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,11 +47,11 @@ 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;
     }
 
     /**
@@ -80,9 +82,9 @@ public class CameraUtil {
 
 
     public static String historyPlayListStr(String channel, Date startTm, Date endTm) {
-        List<String> list = historyPlayList(channel, startTm, endTm, mappingUrl);
-        String ph = "/flv/" + DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date())
-                + "/" + channel + "/"
+        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);
@@ -158,15 +160,6 @@ public class CameraUtil {
         return null;
     }
 
-
-    @PostConstruct
-    public void init() {
-        url = caneraConfig.getUrl();
-        mappingUrl = caneraConfig.getMappingUrl();
-        historyUrl = caneraConfig.getHistoryUrl();
-        ffmpegPath = caneraConfig.getFfmpegPath();
-    }
-
     /**
      * * 参数:
      * **List<String> fromVideoFileList 需要合并的多视频url地址以List存放**
@@ -176,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);
     }
 
     //工具类
@@ -286,51 +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 + "mvideo.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);
-        List<String> list = Arrays.asList("http://47.106.159.135/record/flv/34020000001320000002/20230304_185950_190050-d3f3d9c2-ba7b-11ed-aeb9-00163e06a5f3.flv",
-                "http://47.106.159.135/record/flv/34020000001320000002/20230304_190051_190151-f859029a-ba7b-11ed-aeb9-00163e06a5f3.flv",
-                "http://47.106.159.135/record/flv/34020000001320000002/20230304_190152_190252-1cb977bd-ba7c-11ed-aeb9-00163e06a5f3.flv",
-                "http://47.106.159.135/record/flv/34020000001320000002/20230304_190253_190353-4117245a-ba7c-11ed-aeb9-00163e06a5f3.flv",
-                "http://47.106.159.135/record/flv/34020000001320000002/20230304_190354_190454-6575b56e-ba7c-11ed-aeb9-00163e06a5f3.flv",
-                "http://47.106.159.135/record/flv/34020000001320000002/20230304_190455_190555-89d6e4b7-ba7c-11ed-aeb9-00163e06a5f3.flv",
-                "http://47.106.159.135/record/flv/34020000001320000002/20230304_190556_190657-ae3bc3a9-ba7c-11ed-aeb9-00163e06a5f3.flv",
-                "http://47.106.159.135/record/flv/34020000001320000002/20230304_190658_190758-d29cd834-ba7c-11ed-aeb9-00163e06a5f3.flv",
-                "http://47.106.159.135/record/flv/34020000001320000002/20230304_190759_190859-f6fdc454-ba7c-11ed-aeb9-00163e06a5f3.flv",
-                "http://47.106.159.135/record/flv/34020000001320000002/20230304_190900_191000-1b5ac0ee-ba7d-11ed-aeb9-00163e06a5f3.flv");
-        mergeFile(list, newfilePath);
-
+    @PostConstruct
+    public void init() {
+        url = caneraConfig.getUrl();
+        mappingUrl = caneraConfig.getMappingUrl();
+        historyUrl = caneraConfig.getHistoryUrl();
+        ffmpegPath = caneraConfig.getFfmpegPath();
+        flvPath = caneraConfig.getFlvPath();
+        filePath = caneraConfig.getFilePath();
     }
 }

+ 2 - 1
hazard-admin/src/main/resources/application.yml

@@ -18,7 +18,8 @@ base:
   #  path: http://47.106.159.135:8554
   path: http://47.106.159.135:8554
   ffmpegPath: /usr/local/ffmpeg/bin/ffmpeg
-  mappingUrl: /opt/streams/
+  mappingUrl: http://47.106.159.135/
+  filePath: /opt/streams/
 
 # 开发环境配置
 server: