hexiao 2 年之前
父节点
当前提交
6778565466

+ 0 - 11
hazard-admin/src/main/java/com/ozs/web/controller/tool/TestController.java

@@ -6,8 +6,6 @@ import java.util.List;
 import java.util.Map;
 
 import com.ozs.common.utils.SecurityUtils;
-import com.ozs.web.core.util.TestCameraUtil;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -36,15 +34,6 @@ import io.swagger.annotations.ApiOperation;
 @RequestMapping("/test")
 public class TestController extends BaseController {
 
-    @Autowired
-    private TestCameraUtil testCameraUtil;
-
-    @ApiOperation("camera")
-    @GetMapping("/camera")
-    public R<String> camera() {
-        testCameraUtil.test();
-        return R.ok();
-    }
 
 
     private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>();

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

@@ -47,9 +47,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
@@ -74,7 +79,15 @@ public class CameraUtil {
         }
         new Thread(() -> {
             try {
-                myConvetor(fromVideoFileList, NewfilePath, uuid);
+                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();
@@ -239,9 +252,9 @@ public class CameraUtil {
      * @param newfilePath       生产新的视频文件路径
      * @throws IOException
      */
-    public static void myConvetor(List<String> fromVideoFileList,
-                                  String newfilePath,
-                                  String uuid) 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
@@ -287,7 +300,7 @@ 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<>();
@@ -298,8 +311,9 @@ public class CameraUtil {
             commands.add("cd " + pathStr);
             // 合并成一个临时文件
             commands.add(commit);
+
             // 临时文件转化为 flv
-            commands.add(commit1);
+//            commands.add(commit1);
             log.info("录像视频命令:{}", commands);
             for (String line : commands) {
                 log.info("命令:{}", line);
@@ -312,13 +326,12 @@ public class CameraUtil {
                 log.info("*****:{}", rspLine);
             }
             proc.waitFor();
+            Map<String, String> map = new HashMap<>();
+            map.put("cmd", commit1);
+            map.put("path", pathStr + "/" + substring);
+            return map;
 
 
-            //删除生成的ts文件
-            File file1 = new File(pathStr + "/" + substring);
-            if (file1.exists()) {
-                file1.delete();
-            }
         } catch (InterruptedException e) {
             log.error(e.getMessage());
             e.printStackTrace();
@@ -327,6 +340,7 @@ public class CameraUtil {
             out.close();
             proc.destroy();
         }
+        return null;
     }
 
 
@@ -338,6 +352,7 @@ public class CameraUtil {
         transcribeFilePath = caneraConfig.getTranscribeFilePath();
         webUrl = caneraConfig.getWebUrl();
         bakUrl = caneraConfig.getBakUrl();
+        cUtil = cmdCameraUtil;
     }
 
     /**

+ 8 - 5
hazard-admin/src/main/java/com/ozs/web/core/util/TestCameraUtil.java

@@ -10,13 +10,16 @@ import java.io.InputStreamReader;
 
 @Slf4j
 @Component
-public class TestCameraUtil {
+public class CmdCameraUtil {
 
 
-    public void test() {
+    public void cmd(String cmd) {
+        long l = System.currentTimeMillis();
         Process exec = null;
         try {
-            exec = Runtime.getRuntime().exec(new String[]{"sh", "-c", "/usr/local/ffmpeg/bin/ffmpeg -f concat -safe 0 -i /opt/streams/record/flv/42010001541320001116/85e3a21d-88f1-453e-a38e-3a6097ae81f8.txt -c copy /data/service/hazard-admin/uploadPath/flv/2023-04-03/42010001541320001116/85e3a21d-88f1-453e-a38e-3a6097ae81f8.flv"});
+            exec = Runtime.getRuntime().exec(new String[]{"sh", "-c", cmd});
+            long l1 = System.currentTimeMillis();
+            log.info("cmd-time:{}", l1 - l);
         } catch (IOException e) {
             log.error(e.getMessage());
             e.printStackTrace();
@@ -56,7 +59,7 @@ public class TestCameraUtil {
             while ((line = br.readLine()) != null) {
                 result.append(line + "\n");
             }
-            log.info("FFMPEG视频转换进程错误信息:" + result.toString());
+            log.info("FFMPEG视频合成进程错误信息:" + result.toString());
 
             result = new StringBuffer();
             line = null;
@@ -64,7 +67,7 @@ public class TestCameraUtil {
             while ((line = br2.readLine()) != null) {
                 result.append(line + "\n");
             }
-            log.info("FFMPEG视频转换进程输出内容为:" + result.toString());
+            log.info("FFMPEG视频合成进程输出内容为:" + result.toString());
         } catch (IOException e2) {
             e2.printStackTrace();
         } finally {