Browse Source

相机文件修改权限

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

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

@@ -168,6 +168,12 @@ public class CameraUtil {
      */
     public static void convetor(List<String> fromVideoFileList,
                                 String NewfilePath) throws IOException {
+        File file = new File(NewfilePath);
+        if (!file.getParentFile().exists()) {
+            file.getParentFile().mkdirs();
+            log.info("创建文件夹:{}", file.getParentFile().getPath());
+            Runtime.getRuntime().exec("chmod 777 " + file.getParentFile().getPath());
+        }
         List<String> voidTS = new ArrayList<>();
         Process process = null;
         ProcessBuilder builder = null;
@@ -177,45 +183,51 @@ public class CameraUtil {
         Runtime.getRuntime().exec("chmod 777 " + substr);
         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);
+            File file1 = new File(fromVideoFile);
+            if (file1.exists()) {
+                log.info("文件存在:{}", fromVideoFile);
+                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();
                 }
-                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();
+            } else {
+                log.info("文件不存在:{}", fromVideoFile);
             }
         }
         List<String> dos = new ArrayList<>();