feign 代理 zlm 视频流

This commit is contained in:
shikong 2023-09-05 17:28:22 +08:00
parent 04c1cfb2a9
commit af0229ac55
3 changed files with 38 additions and 12 deletions

View File

@ -1,42 +1,56 @@
package cn.skcks.docking.gb28181.wvp.api;
import cn.hutool.core.io.IoUtil;
import cn.skcks.docking.gb28181.wvp.config.SwaggerConfig;
import cn.skcks.docking.gb28181.wvp.proxy.ZlmProxyClient;
import feign.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@Tag(name = "视频api")
@Controller
@RequestMapping("/video")
@RequiredArgsConstructor
public class VideoController {
private final ZlmProxyClient zlmProxyClient;
@Bean
public GroupedOpenApi videoApi() {
return SwaggerConfig.api("VideoApi", "/video");
}
@Operation(summary = "获取视频")
@GetMapping(consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<FileSystemResource> video(HttpServletResponse response) {
@GetMapping(produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
public void video(HttpServletResponse response) {
response.reset();
// response.setHeader("Content-Type","video/mp4");
File f = new File("E:\\#Camera\\DCIM\\100MEDIA\\20230818\\NORM0003.MP4");
// File f = new File("E:\\#Camera\\DCIM\\100MEDIA\\20230818\\NORM0003.MP4");
// try (
// BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(f));
// BufferedOutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
// IoUtil.copy(inputStream, outputStream);
// }
FileSystemResource fileSystemResource = new FileSystemResource(f);
return ResponseEntity.ok().body(fileSystemResource);
try (Response live = zlmProxyClient.live("live", "test.live.mp4")) {
InputStream inputStream = live.body().asInputStream();
OutputStream outputStream = response.getOutputStream();
IoUtil.copy(inputStream, outputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,12 @@
package cn.skcks.docking.gb28181.wvp.proxy;
import feign.Response;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@FeignClient(name="zlmProxyClient", url = "${media.url}")
public interface ZlmProxyClient {
@GetMapping("/{app}/{streamId}")
Response live(@PathVariable String app,@PathVariable String streamId);
}

View File

@ -26,12 +26,12 @@ spring:
url: jdbc:mysql://192.168.1.241:3306/gb28181_docking_platform?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
media:
ip: 192.168.3.12
url: 'http://192.168.3.12:5081'
ip: 192.168.1.241
url: 'http://192.168.1.241:5080'
# url: 'http://10.10.10.200:12580/anything/'
id: amrWMKmbKqoBjRQ9
# secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
secret: 4155cca6-2f9f-11ee-85e6-8de4ce2e7333
secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
# secret: 4155cca6-2f9f-11ee-85e6-8de4ce2e7333
proxy:
wvp: