hexiao 2 年之前
父节点
当前提交
1c4569b737

+ 42 - 51
hazard-admin/src/main/java/com/ozs/web/controller/tool/TestController.java

@@ -6,6 +6,8 @@ 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;
@@ -31,10 +33,22 @@ import io.swagger.annotations.ApiOperation;
  */
 @Api("用户信息管理")
 @RestController
-@RequestMapping("/test/user")
-public class TestController extends BaseController
-{
+@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>();
+
     {
         users.put(1, new UserEntity(1, "admin", "admin123", "15888888888"));
         users.put(2, new UserEntity(2, "ry", "admin123", "15666666666"));
@@ -42,8 +56,7 @@ public class TestController extends BaseController
 
     @ApiOperation("获取用户列表")
     @GetMapping("/list")
-    public R<List<UserEntity>> userList()
-    {
+    public R<List<UserEntity>> userList() {
         List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
         return R.ok(userList);
     }
@@ -51,30 +64,24 @@ public class TestController extends BaseController
     @ApiOperation("获取用户详细")
     @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
     @GetMapping("/{userId}")
-    public R<UserEntity> getUser(@PathVariable Integer userId)
-    {
-        if (!users.isEmpty() && users.containsKey(userId))
-        {
+    public R<UserEntity> getUser(@PathVariable Integer userId) {
+        if (!users.isEmpty() && users.containsKey(userId)) {
             return R.ok(users.get(userId));
-        }
-        else
-        {
+        } else {
             return R.fail("用户不存在");
         }
     }
 
     @ApiOperation("新增用户")
     @ApiImplicitParams({
-        @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", dataTypeClass = Integer.class),
-        @ApiImplicitParam(name = "username", value = "用户名称", dataType = "String", dataTypeClass = String.class),
-        @ApiImplicitParam(name = "password", value = "用户密码", dataType = "String", dataTypeClass = String.class),
-        @ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String", dataTypeClass = String.class)
+            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", dataTypeClass = Integer.class),
+            @ApiImplicitParam(name = "username", value = "用户名称", dataType = "String", dataTypeClass = String.class),
+            @ApiImplicitParam(name = "password", value = "用户密码", dataType = "String", dataTypeClass = String.class),
+            @ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String", dataTypeClass = String.class)
     })
     @PostMapping("/save")
-    public R<String> save(UserEntity user)
-    {
-        if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
-        {
+    public R<String> save(UserEntity user) {
+        if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) {
             return R.fail("用户ID不能为空");
         }
         users.put(user.getUserId(), user);
@@ -83,14 +90,11 @@ public class TestController extends BaseController
 
     @ApiOperation("更新用户")
     @PutMapping("/update")
-    public R<String> update(@RequestBody UserEntity user)
-    {
-        if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
-        {
+    public R<String> update(@RequestBody UserEntity user) {
+        if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) {
             return R.fail("用户ID不能为空");
         }
-        if (users.isEmpty() || !users.containsKey(user.getUserId()))
-        {
+        if (users.isEmpty() || !users.containsKey(user.getUserId())) {
             return R.fail("用户不存在");
         }
         users.remove(user.getUserId());
@@ -101,23 +105,18 @@ public class TestController extends BaseController
     @ApiOperation("删除用户信息")
     @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
     @DeleteMapping("/{userId}")
-    public R<String> delete(@PathVariable Integer userId)
-    {
-        if (!users.isEmpty() && users.containsKey(userId))
-        {
+    public R<String> delete(@PathVariable Integer userId) {
+        if (!users.isEmpty() && users.containsKey(userId)) {
             users.remove(userId);
             return R.ok();
-        }
-        else
-        {
+        } else {
             return R.fail("用户不存在");
         }
     }
 }
 
 @ApiModel(value = "UserEntity", description = "用户实体")
-class UserEntity
-{
+class UserEntity {
     @ApiModelProperty("用户ID")
     private Integer userId;
 
@@ -130,46 +129,38 @@ class UserEntity
     @ApiModelProperty("用户手机")
     private String mobile;
 
-    public UserEntity()
-    {
+    public UserEntity() {
 
     }
 
-    public UserEntity(Integer userId, String username, String password, String mobile)
-    {
+    public UserEntity(Integer userId, String username, String password, String mobile) {
         this.userId = userId;
         this.username = username;
         this.password = password;
         this.mobile = mobile;
     }
 
-    public Integer getUserId()
-    {
+    public Integer getUserId() {
         return userId;
     }
 
-    public void setUserId(Integer userId)
-    {
+    public void setUserId(Integer userId) {
         this.userId = userId;
     }
 
-    public String getUsername()
-    {
+    public String getUsername() {
         return username;
     }
 
-    public void setUsername(String username)
-    {
+    public void setUsername(String username) {
         this.username = username;
     }
 
-    public String getPassword()
-    {
+    public String getPassword() {
         return password;
     }
 
-    public void setPassword(String password)
-    {
+    public void setPassword(String password) {
         this.password = password;
     }
 

+ 77 - 0
hazard-admin/src/main/java/com/ozs/web/core/util/TestCameraUtil.java

@@ -0,0 +1,77 @@
+package com.ozs.web.core.util;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+@Slf4j
+@Component
+public class TestCameraUtil {
+
+
+    public void test() {
+        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"});
+        } catch (IOException e) {
+            log.error(e.getMessage());
+            e.printStackTrace();
+        }
+        try {
+            printProcessMsg(exec);
+        } catch (IOException e) {
+            log.error(e.getMessage());
+            e.printStackTrace();
+        }
+        try {
+            int i = exec.waitFor();
+        } catch (InterruptedException e) {
+            log.error(e.getMessage());
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * 处理process输出流和错误流,防止进程阻塞,在process.waitFor();前调用
+     *
+     * @param exec
+     * @throws IOException
+     */
+    private void printProcessMsg(Process exec) throws IOException {
+        //防止ffmpeg进程塞满缓存造成死锁
+        InputStream error = exec.getErrorStream();
+        InputStream is = exec.getInputStream();
+
+        StringBuffer result = new StringBuffer();
+        String line = null;
+        try {
+            BufferedReader br = new BufferedReader(new InputStreamReader(error, "GBK"));
+            BufferedReader br2 = new BufferedReader(new InputStreamReader(is, "GBK"));
+
+            while ((line = br.readLine()) != null) {
+                result.append(line + "\n");
+            }
+            log.info("FFMPEG视频转换进程错误信息:" + result.toString());
+
+            result = new StringBuffer();
+            line = null;
+
+            while ((line = br2.readLine()) != null) {
+                result.append(line + "\n");
+            }
+            log.info("FFMPEG视频转换进程输出内容为:" + result.toString());
+        } catch (IOException e2) {
+            e2.printStackTrace();
+        } finally {
+            error.close();
+            is.close();
+        }
+
+    }
+
+}