hexiao 2 years ago
parent
commit
c46394e262
1 changed files with 15 additions and 17 deletions
  1. 15 17
      hazard-admin/src/main/java/com/ozs/web/core/util/CameraUtil.java

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

@@ -282,10 +282,9 @@ public class CameraUtil {
         sm.append("; do echo \"file '$f'\" >> " + substring + "; done");
         String commit = sm.toString();
         log.info("合并转化文件的命令:{}", commit);
-//        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);
+        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);
 
         try {
             String commit1 = ffmpegPath + " -f concat -safe 0 -i " + substring + " -c copy " + newfilePath;
@@ -304,16 +303,15 @@ public class CameraUtil {
             log.info("录像视频命令:{}", commands);
             for (String line : commands) {
                 log.info("命令:{}", line);
-                Runtime.getRuntime().exec(new String[]{"sh", "-c", line});
-//                out.println(line);
+                out.println(line);
+            }
+            out.println("exit");// 这个命令必须执行,否则in流不结束。
+            log.info("命令:{}", "exit");
+            String rspLine = "";
+            while ((rspLine = in.readLine()) != null) {
+                log.info("*****:{}", rspLine);
             }
-//            out.println("exit");// 这个命令必须执行,否则in流不结束。
-//            log.info("命令:{}", "exit");
-//            String rspLine = "";
-//            while ((rspLine = in.readLine()) != null) {
-//                log.info("*****:{}", rspLine);
-//            }
-//            proc.waitFor();
+            proc.waitFor();
 
 
             //删除生成的ts文件
@@ -321,13 +319,13 @@ public class CameraUtil {
             if (file1.exists()) {
                 file1.delete();
             }
-        } catch (Exception e) {
+        } catch (InterruptedException e) {
             log.error(e.getMessage());
             e.printStackTrace();
         } finally {
-//            in.close();
-//            out.close();
-//            proc.destroy();
+            in.close();
+            out.close();
+            proc.destroy();
         }
     }