Browse Source

代码修改

gao.qiang 1 year ago
parent
commit
1da17ed349

+ 24 - 0
vehicle-admin/src/main/java/com/ozs/web/controller/accountmanagment/BaseCameraManagementController.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.ozs.common.annotation.Log;
 import com.ozs.common.core.controller.BaseController;
 import com.ozs.common.core.domain.AjaxResult;
+import com.ozs.common.core.domain.R;
 import com.ozs.common.core.domain.entity.SysDept;
 import com.ozs.common.enums.BusinessType;
 import com.ozs.common.exception.base.BaseException;
@@ -79,6 +80,9 @@ public class BaseCameraManagementController extends BaseController {
     @Resource
     private BaseUserService baseUserService;
 
+    @Autowired
+    private CameraUtil cameraUtil;
+
     /**
      * 所有相机列表+权限
      */
@@ -289,6 +293,26 @@ public class BaseCameraManagementController extends BaseController {
         return AjaxResult.success();
     }
 
+
+    /**
+     * HTTP流转RTSP流
+     *
+     * @param 
+     * @return
+     */
+    @GetMapping("/streamConversion")
+    @ApiOperation("HTTP流转RTSP流")
+    @Transactional
+    @Log(title = "相机台账管理", businessType = BusinessType.INSERT)
+    public AjaxResult streamConversion(String code) {
+        try {
+            cameraUtil.streamConversion(code);
+        } catch (Exception e) {
+            return AjaxResult.error(e.getMessage().toString());
+        }
+        return AjaxResult.success();
+    }
+
     /**
      * 新增相机台账管理信息
      *

+ 42 - 0
vehicle-admin/src/main/java/com/ozs/web/core/util/CameraUtil.java

@@ -702,6 +702,48 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
         return filterRecordList(channel, startTm, endTm, filePath, recordUrl + "profile/");
     }
 
+
+    /**
+     * HTTP流转RTSP流
+     */
+    public   void streamConversion(String code) {
+        log.info("ffmpeg -re -i /opt/streams/file/"+code+".mp4  -c:v copy -c:a copy -f rtsp rtsp://124.70.58.209:8554/live/"+code+"s");
+//        cmdCameraUtil.cmd("find /opt/streams/record/flv/*/*/ -mmin +5 -name *.flv -exec rm -rf {} \\;");
+
+        try {
+            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);
+            String commit = "ffmpeg -re -i /opt/streams/file/"+code+"s.mp4  -c:v copy -c:a copy -f rtsp rtsp://124.70.58.209:8554/live/"+code+"s";
+            List<String> commands = new ArrayList<>();
+
+            // 删除
+            commands.add(commit);
+            log.info("HTTP流转RTSP流:{}", commands);
+            for (String line : commands) {
+                out.println(line);
+            }
+            out.println("exit");// 这个命令必须执行,否则in流不结束。
+            String rspLine = "";
+            while ((rspLine = in.readLine()) != null) {
+                System.out.println(rspLine);
+
+            }
+            int i = proc.waitFor();
+            log.info("执行结果:{}", i);
+
+            in.close();
+            out.close();
+            proc.destroy();
+        } catch (IOException e) {
+            log.error(e.getMessage());
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+
+    }
+    
+
     public static List<Map<String, Object>> filterRecordList(String channel,
                                                              Date startTm,
                                                              Date endTm,