瀏覽代碼

Merge branch 'usky-zyj' into server-165

james 2 周之前
父節點
當前提交
47d2f491f2

+ 13 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/VcDeviceController.java

@@ -5,10 +5,13 @@ import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.bean.CommonPage;
 import com.usky.iot.domain.BaseGgpFacility;
 import com.usky.iot.domain.VcDevice;
+import com.usky.iot.domain.VcStream;
 import com.usky.iot.service.VcDeviceService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import java.util.List;
 
 /**
@@ -56,6 +59,16 @@ public class VcDeviceController {
         return ApiResult.success(vcDeviceService.pageList(videoNumber, videoName, groupId, pageNum, pageSize));
     }
 
+    /**
+     * 实时拉取摄像头视频流
+     * @param deviceUuid
+     * @return
+     */
+    @GetMapping("getVcDeviceVideo")
+    public ApiResult<String> getVcDeviceVideo(@RequestParam(value = "deviceUuid") String deviceUuid) {
+        return ApiResult.success(vcDeviceService.getVcDeviceVideo(deviceUuid));
+    }
+
     /**
      * 新增
      * @param vcDevice

+ 3 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/VcDeviceService.java

@@ -4,6 +4,7 @@ import com.usky.common.core.bean.CommonPage;
 import com.usky.iot.domain.BaseGgpFacility;
 import com.usky.iot.domain.VcDevice;
 import com.usky.common.mybatis.core.CrudService;
+import org.springframework.web.bind.annotation.RequestBody;
 
 import java.util.List;
 
@@ -20,6 +21,8 @@ public interface VcDeviceService extends CrudService<VcDevice> {
 
     CommonPage<VcDevice> pageList(String videoNumber, String videoName, Integer groupId ,Integer pageNum, Integer pageSize);
 
+    String getVcDeviceVideo(String deviceUuid);
+
     boolean add(VcDevice vcDevice);
 
     void update(VcDevice vcDevice);

+ 46 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/config/VcVideo.java

@@ -0,0 +1,46 @@
+package com.usky.iot.service.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+@Slf4j
+@Configuration
+public class VcVideo {
+    @Async
+    public void processVcVideo(String command) {
+        try {
+            log.info("【begin】实时拉取摄像头数据流 "+command);
+            // 创建 ProcessBuilder 实例
+            ProcessBuilder processBuilder = new ProcessBuilder(command.split(" "));
+            // 启动进程
+            Process process = processBuilder.start();
+
+            // 获取进程的输入流
+            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+            String line;
+            while ((line = reader.readLine()) != null) {
+                System.out.println(line);
+            }
+
+            // 获取进程的错误流
+            BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+            while ((line = errorReader.readLine()) != null) {
+                System.err.println(line);
+            }
+
+            // 等待进程执行完成并获取退出码
+            int exitCode = process.waitFor();
+            System.out.println("命令执行完成,退出码: " + exitCode);
+            log.info("【end】实时拉取摄像头数据流 "+command+ "命令执行完成,退出码: " + exitCode);
+
+        } catch (IOException | InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
+}

+ 36 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/VcDeviceServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.usky.common.core.bean.CommonPage;
+import com.usky.common.core.exception.BusinessException;
 import com.usky.common.security.utils.SecurityUtils;
 import com.usky.iot.domain.BaseFacilityDevice;
 import com.usky.iot.domain.BaseGgpFacility;
@@ -13,9 +14,15 @@ import com.usky.iot.domain.VcDevice;
 import com.usky.iot.mapper.VcDeviceMapper;
 import com.usky.iot.service.VcDeviceService;
 import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.iot.service.config.VcVideo;
 import com.usky.iot.service.vo.BaseFacilityDeviceVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.time.LocalDateTime;
 import java.util.List;
 
@@ -29,6 +36,13 @@ import java.util.List;
  */
 @Service
 public class VcDeviceServiceImpl extends AbstractCrudService<VcDeviceMapper, VcDevice> implements VcDeviceService {
+
+    @Value("${vc.rtmp-ip}")
+    private String rtmpIp;
+
+    @Autowired
+    private VcVideo vcVideo;
+
     @Override
     public List<VcDevice> VcDeviceList(Integer groupId){
         LambdaQueryWrapper<VcDevice> queryWrapper = Wrappers.lambdaQuery();
@@ -51,6 +65,28 @@ public class VcDeviceServiceImpl extends AbstractCrudService<VcDeviceMapper, VcD
         return new CommonPage<>(page.getRecords(),page.getTotal(),page.getCurrent(),page.getSize());
     }
 
+    @Override
+    public String getVcDeviceVideo(String deviceUuid){
+        LambdaQueryWrapper<VcDevice> lambdaQuery = Wrappers.lambdaQuery();
+        lambdaQuery.like(StringUtils.isNotBlank(deviceUuid),VcDevice::getVideoNumber,deviceUuid)
+                .eq(VcDevice::getDelFlag,0);
+        VcDevice one = this.getOne(lambdaQuery);
+        if(one==null){
+            throw new BusinessException("未查询到设备信息");
+        }
+        String accountNumber = one.getAccountNumber();
+        String videoPassword = one.getVideoPassword();
+        String videoIp = one.getVideoIp();
+        String videoPort = one.getVideoPort().toString();
+        String command = "ffmpeg -i rtsp://"+accountNumber+":"+videoPassword+"@"+videoIp+":"+videoPort+" -vcodec copy -acodec aac -ar 44100 -c:v libx264 -strict -2 -ac 1 -f flv -r 30 -s 1920x1080 -q 10 -f flv rtmp://"+rtmpIp+":1935/hls/"+deviceUuid;
+        System.out.println(command);
+        vcVideo.processVcVideo(command);
+
+        String repDeviceVideo = rtmpIp+":80/hls/"+deviceUuid+".m3u8";
+
+        return repDeviceVideo;
+    }
+
     @Override
     public boolean add(VcDevice vcDevice){
         vcDevice.setCreateBy(SecurityUtils.getUsername());