Bläddra i källkod

feat(visualization): 添加 HLS、FLV、RTMP 实时预览功能

- 新增 getHFRUrl 方法,实现 HLS、FLV、RTMP 实时预览接口
- 添加 VideoPlayRequest 类,用于定义实时预览请求参数- 优化代码结构,提高可读性和可维护性
林仔 1 år sedan
förälder
incheckning
527613faf3

+ 53 - 0
visualization-service/src/main/java/com/zksy/visualization/controller/RealTimePreviewVideoController.java

@@ -99,6 +99,59 @@ public class RealTimePreviewVideoController {
         }
         return Result.error("请求失败");
     }
+    @ApiOperation(value = "HLS、FLV、RTMP实时预览接口方式")
+    @PostMapping("/getHFRUrl")
+    public Result getHFRUrl(VideoPlayRequest request){
+        ObjectMapper objectMapper = new ObjectMapper();
+        String jsonParams = null;
+        try {
+            jsonParams = objectMapper.writeValueAsString(request);
+        } catch (JsonProcessingException e) {
+            log.error("JSON序列化失败: {}", e);
+            return Result.error("请求失败");
+        }
+        String authorization = redisTemplate
+                .opsForValue()
+                .get("Authorization:" + iccConfigProperty.getUsername());
+        // 创建请求体
+        RequestBody body = RequestBody.create(jsonParams, JSON);
+        // 构建请求
+        Request requestHttp = new Request.Builder()
+                .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/admin/API/video/stream/realtime")
+                .addHeader("Authorization", authorization)
+                .post(body)
+                .build();
+        // 发送请求
+        try (Response response = httpClient.newCall(requestHttp).execute()) {
+            if (!response.isSuccessful()) {
+                return Result.error("请求失败");
+            }
+            ResponseBody responseBody = response.body();
+            if (responseBody != null) {
+                String responseString = responseBody.string();
+                JsonNode rootNode = objectMapper.readTree(responseString);
+                JsonNode success = rootNode.path("success");
+                if("true".equals(success.asText())) {
+                    JsonNode dataNode = rootNode.path("data");
+                    if (dataNode != null) {
+                        return Result.ok(dataNode);
+                    } else {
+                        return Result.ok(null);
+                    }
+                }else {
+                    JsonNode code = rootNode.path("code");
+                    if("1001".equals(code.asText())){
+                        return Result.error("未查询到视频信息");
+                    }else {
+                        return Result.error("HLS、FLV、RTMP实时预览失败");
+                    }
+                }
+            }
+        } catch (IOException e) {
+            log.error("请求失败: {}", e);
+        }
+        return Result.error("请求失败");
+    }
 
     @ApiOperation(value = "查询普通录像信息列表")
     @PostMapping("/queryOrdinaryList")

+ 27 - 0
visualization-service/src/main/java/com/zksy/visualization/domain/request/VideoPlayRequest.java

@@ -0,0 +1,27 @@
+package com.zksy.visualization.domain.request;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(description = "HLS、FLV、RTMP实时预览请求参数")
+public class VideoPlayRequest {
+
+    @ApiModelProperty(value = "Json串", required = true)
+    private Data data;
+
+    @lombok.Data
+    @ApiModel(description = "数据详情")
+    public static class Data {
+        @ApiModelProperty(value = "视频通道编码", required = true)
+        private String channelId;
+
+        @ApiModelProperty(value = "码流类型:1=主码流, 2=辅码流,3=辅码流2", required = true)
+        private String streamType;
+
+        @ApiModelProperty(value = "协议类型:hls, hlss, flv, flvs, ws_flv, wss_flv, rtmp", required = true)
+        private String type;
+
+    }
+}