瀏覽代碼

修改录像参数

hexiao 2 年之前
父節點
當前提交
94c5b0072d

+ 3 - 2
hazard-admin/src/main/java/com/ozs/web/controller/accountmanagment/BaseCameraManagementController.java

@@ -380,7 +380,7 @@ public class BaseCameraManagementController extends BaseController {
         return new AjaxResult(200, "ok", CameraUtil.getPlayFlv(cameraCode, one.getChannel()));
     }
 
-    @ApiOperation("播放回放")
+    @ApiOperation("播放回放-废弃")
     @PostMapping("/api/invite")
     public AjaxResult apiInvite(@Validated @RequestBody BaseCameraResVo vo) {
         LambdaQueryWrapper<BaseCameraManagement> lw = new LambdaQueryWrapper<BaseCameraManagement>();
@@ -389,7 +389,8 @@ public class BaseCameraManagementController extends BaseController {
         if (ObjectUtils.isEmpty(one)) {
             throw new BaseException("相机编号【" + vo.getCameraCode() + "】不存在");
         }
-        return success(CameraUtil.historyPlayList(one.getChannel(), vo.getStartTime(), vo.getEntTime(), caneraConfig.getMappingUrl()));
+        // CameraUtil.historyPlayList(one.getChannel(), vo.getStartTime(), vo.getEntTime(), caneraConfig.getMappingUrl())
+        return success();
     }
 
     @ApiOperation("播放回放")

+ 4 - 6
hazard-admin/src/main/java/com/ozs/web/core/config/CaneraConfig.java

@@ -8,12 +8,6 @@ import org.springframework.context.annotation.Configuration;
 @Data
 public class CaneraConfig {
 
-    /**
-     * 视频服务器访问路径
-     */
-    @Value("${base.url:http://47.106.159.135:8554}")
-    private String url;
-
     /**
      * 视频服务器访问路径
      */
@@ -32,4 +26,8 @@ public class CaneraConfig {
     private String filePath;
 
 
+    @Value("${base.webUrl:http://47.106.159.135/streams}")
+    private String webUrl;
+
+
 }

+ 29 - 159
hazard-admin/src/main/java/com/ozs/web/core/util/CameraUtil.java

@@ -29,10 +29,10 @@ import java.util.stream.Collectors;
 @Slf4j
 public class CameraUtil {
 
-    private static String url;
     private static String historyUrl;
     private static String ffmpegPath;
     private static String filePath;
+    private static String webUrl;
 
     @Autowired
     private CaneraConfig caneraConfig;
@@ -62,10 +62,7 @@ public class CameraUtil {
                 e.printStackTrace();
             }
         }).start();
-        // windows可以 linux不行
-//        convetor(fromVideoFileList, NewfilePath);
         return Constants.RESOURCE_PREFIX + "/" + ph;
-//        return mappingUrl + "record/flv/hazard/" + ph;
     }
 
     /**
@@ -76,7 +73,7 @@ public class CameraUtil {
      * @return
      */
     public static String getPlayFlv(String cameraCode, String channel) {
-        return historyUrl + "/hdl/" + channel + "/" + cameraCode + ".flv";
+        return webUrl + "/hdl/" + channel + "/" + cameraCode + ".flv";
     }
 
     /**
@@ -100,24 +97,17 @@ public class CameraUtil {
         return historyUrl + "/api/record/flv/stop?id=" + taskId;
     }
 
+
     /**
-     * 实时播放
+     * 历史回放流(获取)
      *
-     * @param cameraCode
-     * @param channel
+     * @param channel 相机通道
+     * @param startTm 开始时间
+     * @param endTm   结束时间
      * @return
      */
-    public static String play(String cameraCode, String channel) {
-        if (StringUtils.isBlank(cameraCode) || StringUtils.isBlank(channel)) {
-            return null;
-        }
-        String param = "id=" + cameraCode + "&channel=" + channel;
-        return HttpUtils.sendGet(url + "/gb28181/api/records", param);
-    }
-
-
     public static String historyPlayListStr(String channel, Date startTm, Date endTm) {
-        List<String> list = historyPlayList(channel, startTm, endTm, filePath);
+        List<String> list = filterPlayList(channel, startTm, endTm, filePath);
         String ph = "flv/" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, new Date())
                 + "/" + channel + "/"
                 + UUID.randomUUID().toString() + ".flv";
@@ -135,7 +125,16 @@ public class CameraUtil {
     }
 
 
-    public static List<String> historyPlayList(String channel, Date startTm, Date endTm, String mappingUrl) {
+    /**
+     * 过滤符合条件的视频
+     *
+     * @param channel
+     * @param startTm
+     * @param endTm
+     * @param mappingUrl
+     * @return
+     */
+    public static List<String> filterPlayList(String channel, Date startTm, Date endTm, String mappingUrl) {
         if (StringUtils.isBlank(channel)
                 || ObjectUtils.isEmpty(startTm)
                 || ObjectUtils.isEmpty(endTm)) {
@@ -203,133 +202,11 @@ public class CameraUtil {
     }
 
     /**
-     * * 参数:
-     * **List<String> fromVideoFileList 需要合并的多视频url地址以List存放**
-     * **String ffmpeg 此处是ffmpeg 配置地址,可写死如“E:/ffmpeg/bin/ffmpeg.exe”**
-     * **String NewfilePath 合并后的视频存放地址,如:E:/mergevideo.mp4***
+     * 合并视频(转化文件)
+     * @param fromVideoFileList 视频路径
+     * @param newfilePath 生产新的视频文件路径
+     * @throws IOException
      */
-    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());
-        }
-        log.info("newfilePath:{}", newfilePath);
-        Runtime.getRuntime().exec("chmod 777 " + file.getParentFile().getPath());
-        List<String> voidTS = new ArrayList<>();
-        Process process = null;
-        ProcessBuilder builder = null;
-        List<String> command = null;
-        String substr = fromVideoFileList.get(0).substring(0, fromVideoFileList.get(0).lastIndexOf("/"));
-        log.info("substr:{}", substr);
-        Runtime.getRuntime().exec("chmod 777 " + substr);
-        // 转化为临时文件 .ts  放入到 voidTS里面
-        for (int i = 0; i < fromVideoFileList.size(); i++) {
-            String fromVideoFile = fromVideoFileList.get(i);
-            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) {
-                    log.error(e.getMessage());
-                    e.printStackTrace();
-                }
-            } else {
-                log.info("文件不存在:{}", fromVideoFile);
-            }
-        }
-        for (String voidT : voidTS) {
-            Runtime.getRuntime().exec("chmod 777 " + voidT);
-        }
-        log.info("ffmpegPath:{}", ffmpegPath);
-        List<String> dos = new ArrayList<>();
-        StringBuffer tsPath = new StringBuffer();
-        tsPath.append(ffmpegPath);
-        tsPath.append(" -i ");
-        tsPath.append("concat:");
-        log.info("voidTS:{}", voidTS);
-        for (int t = 0; t < voidTS.size(); t++) {
-            if (t != voidTS.size() - 1) {
-                tsPath.append(voidTS.get(t) + "|");
-            } else {
-                tsPath.append(voidTS.get(t));
-            }
-        }
-        tsPath.append(" -vcodec ");
-        tsPath.append(" copy ");
-        tsPath.append(" -bsf:a ");
-        tsPath.append(" aac_adtstoasc ");
-        tsPath.append(" -movflags ");
-        tsPath.append(" +faststart ");
-        tsPath.append(newfilePath);
-        log.info("执行的命令:{}", tsPath.toString());
-        Process pr = Runtime.getRuntime().exec(
-                tsPath.toString());
-        process.getInputStream();
-        pr.getOutputStream().close();
-        pr.getInputStream().close();
-        pr.getErrorStream().close();
-        try {
-            int i = pr.waitFor();
-            System.out.println("********");
-            log.info("********");
-            System.out.println(i);
-            log.info(i + "");
-            log.info("********");
-            System.out.println("********");
-        } catch (InterruptedException e) {
-            log.error(e.getMessage());
-            e.printStackTrace();
-        } finally {
-            pr.destroy();
-        }
-
-        //删除生成的ts文件
-//        for (String filePath : voidTS) {
-//            File filet = new File(filePath);
-//            filet.delete();
-//            pr.destroy();
-//        }
-    }
-
-
     public static void myConvetor(List<String> fromVideoFileList,
                                   String newfilePath) throws IOException {
         /*
@@ -429,28 +306,21 @@ public class CameraUtil {
         String s = HttpUtils.sendGet("http://47.106.159.135/streams" + "/api/record/flv/list", param);
     }
 
-    //工具类
-
-    public static void queryRecords(String cameraCode, String channel, Date startTm, Date endTm) {
-        if (StringUtils.isBlank(cameraCode)
-                || StringUtils.isBlank(channel)
-                || ObjectUtils.isEmpty(startTm)
-                || ObjectUtils.isEmpty(endTm)) {
-            throw new BaseException("参数为空");
-        }
-        String param = "id=" + cameraCode + "&channel=" + channel + "&startTime=" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startTm) + "&endTm=" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, endTm);
-        String s = HttpUtils.sendGet(historyUrl + "/api/gb28181/query/records", param);
-        System.out.println(s);
-    }
 
     @PostConstruct
     public void init() {
-        url = caneraConfig.getUrl();
         historyUrl = caneraConfig.getHistoryUrl();
         ffmpegPath = caneraConfig.getFfmpegPath();
         filePath = caneraConfig.getFilePath();
+        webUrl = caneraConfig.getWebUrl();
     }
 
+    /**
+     * 定时任务参数flv文件
+     *
+     * @throws IOException
+     * @throws InterruptedException
+     */
     public void deleteFlv() throws IOException, InterruptedException {
         SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
         Date date = new Date();

+ 2 - 6
hazard-admin/src/main/resources/application.yml

@@ -15,15 +15,11 @@ base:
   addressEnabled: false
   # 验证码类型 math 数组计算 char 字符验证
   captchaType: math
-  #  path: http://47.106.159.135:8554
-  #  path: http://124.70.58.209:8554
-  path: http://127.0.0.1:8554
+  # 摄像头配置
   ffmpegPath: /usr/local/ffmpeg/bin/ffmpeg
-  #  mappingUrl: http://47.106.159.135/
   filePath: /opt/streams/
-  #  url: http://124.70.58.209:8554
-  url: http://127.0.0.1:8554
   historyUrl: http://127.0.0.1:9080
+  webUrl: http://124.70.58.209:9080
 
 # 开发环境配置
 server: