|
@@ -0,0 +1,281 @@
|
|
|
+package com.supervision.web.videoManage.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.supervision.web.videoManage.domain.Video;
|
|
|
+import com.supervision.web.videoManage.other.*;
|
|
|
+import com.supervision.web.videoManage.service.VideoService;
|
|
|
+import com.supervision.web.videoManage.vo.VideoVo;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+@Api(tags = "v2")
|
|
|
+@RestController
|
|
|
+//@RequestMapping("rest/v2/video/videos")
|
|
|
+@RequestMapping("/video")
|
|
|
+@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
+public class VideoController {
|
|
|
+
|
|
|
+ private VideoService videoService;
|
|
|
+
|
|
|
+// @Autowired
|
|
|
+// private TaskServiceV2 taskServiceV2;
|
|
|
+
|
|
|
+ /** Windows系统* */
|
|
|
+ private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase().contains("win");
|
|
|
+ /** Linux系统* */
|
|
|
+ private static final boolean IS_LINUX = System.getProperty("os.name").toLowerCase().contains("Linux");
|
|
|
+
|
|
|
+
|
|
|
+ /** 视频播放指令执行 rtsp地址【源播放地址】通过ffmpeg程序进行转化成m3u8,将地址传给video.js进行播放 */
|
|
|
+// @PostMapping("/videoStart")
|
|
|
+// public ResponseResult<VideoVo> videoPreview(@MyRequestBody String videoPath) {
|
|
|
+// CommandUtil commandUtil = new CommandUtil();
|
|
|
+//// String begin = "cmd /k start ffmpeg -f dshow -i video='Integrated Webcam' -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -rtsp_transport tcp -f rtsp rtsp://127.0.0.1/test";
|
|
|
+////
|
|
|
+//// commandUtil.winExec(begin);
|
|
|
+// String url = "http://localhost:8080/test.m3u8";
|
|
|
+// VideoVo videoVo = new VideoVo(url);
|
|
|
+// /*如果是winodws系统**/
|
|
|
+// //将rtsp流转码为m3u8文件交与nginx代理
|
|
|
+// if (IS_WINDOWS) {
|
|
|
+// System.out.println("开始执行"+videoPath);
|
|
|
+//
|
|
|
+//
|
|
|
+// String cmd ="cmd /k start ffmpeg -rtsp_transport tcp -i"
|
|
|
+// + " "
|
|
|
+// + videoPath
|
|
|
+// + " "
|
|
|
+// + "-c:v libx264 -c:a aac -f hls -hls_time 5 -hls_list_size 10 F://nginx-1.8.1/nginx-rtmp-win32-dev/html/test.m3u8";
|
|
|
+// commandUtil.winExec(cmd);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /*如果是Linux系统**/
|
|
|
+// if (IS_LINUX){
|
|
|
+// System.out.println("linux");
|
|
|
+// String cmd = "ffmpeg -f rtsp -rtsp_transport tcp -i '"
|
|
|
+// + ""
|
|
|
+// + videoPath
|
|
|
+// + "'"
|
|
|
+// + ""
|
|
|
+// + " -codec copy -f flv -an 'rtmp://xxx.xxx.xxx.xxx:1935/myapp/room'";
|
|
|
+// commandUtil.linuxExec(cmd);
|
|
|
+// }
|
|
|
+// return ResponseResult.success(videoVo);
|
|
|
+// }
|
|
|
+ /** 关闭ffmpeg.exe程序 */
|
|
|
+ @GetMapping("/videoClose")
|
|
|
+ public ResponseResult<Void> close() {
|
|
|
+ closeHistoryProgram("ffmpeg.exe");
|
|
|
+ if (videoService.deleteTsFile()) {
|
|
|
+ return ResponseResult.success();
|
|
|
+ } else {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取某个课目下的所有视频地址。
|
|
|
+ *
|
|
|
+ * @return 查询结果。
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "获取视频地址")
|
|
|
+ @NoAuthInterface
|
|
|
+ @PostMapping("/getUnitUrl")
|
|
|
+ public List<VideoVo> getUnitUrl(@MyRequestBody String subjectName) {
|
|
|
+ List<VideoVo> videoVoList = videoService.getSubjectVideo(subjectName);
|
|
|
+ return videoVoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取某个类别下的所有视频地址。
|
|
|
+ *
|
|
|
+ * @return 查询结果。
|
|
|
+ */
|
|
|
+// @PostMapping("/getSubjectUrls")
|
|
|
+// public ResponseResult<List<VideoVo>> getSubjectUrls(@RequestBody VideoVo requestBody) {
|
|
|
+// return ResponseResult.success(videoService.listVideos(VideoVo));
|
|
|
+// }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 查询所有视频
|
|
|
+// * @return 视频列表
|
|
|
+// */
|
|
|
+// @ApiOperation("查询所有视频")
|
|
|
+// @GetMapping("/list")
|
|
|
+// public List<Video> listAll() {
|
|
|
+// return videoService.listAll();
|
|
|
+// }
|
|
|
+
|
|
|
+ @ApiOperation("分页查询视频列表(支持视频名称模糊查询)")
|
|
|
+ @PostMapping("/list")
|
|
|
+ public Map<String, Object> listAllPaged(@RequestBody Map<String, Object> params) {
|
|
|
+ int page = (int) params.getOrDefault("page", 1);
|
|
|
+ int size = (int) params.getOrDefault("size", 10);
|
|
|
+ String name = (String) params.getOrDefault("name", ""); // 视频名称模糊查询
|
|
|
+
|
|
|
+ List<Video> list = videoService.listAllPaged(page, size, name);
|
|
|
+
|
|
|
+ PageInfo<Video> pageInfo = new PageInfo<>(list);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("total", pageInfo.getTotal());
|
|
|
+ result.put("list", list);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("分页查询视频列表(支持视频名称模糊查询)")
|
|
|
+ @PostMapping("/listVideo")
|
|
|
+ public Map<String, Object> listVideoAllPaged(@RequestBody Map<String, Object> params) {
|
|
|
+ int page = (int) params.getOrDefault("page", 1);
|
|
|
+ int size = (int) params.getOrDefault("size", 10);
|
|
|
+ String name = (String) params.getOrDefault("name", ""); // 视频名称模糊查询
|
|
|
+
|
|
|
+ List<Video> list = videoService.listVideoAllPaged(page, size, name);
|
|
|
+
|
|
|
+ PageInfo<Video> pageInfo = new PageInfo<>(list);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("total", pageInfo.getTotal());
|
|
|
+ result.put("list", list);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据ID查询单个视频
|
|
|
+ * @param id 视频ID
|
|
|
+ * @return 视频对象
|
|
|
+ */
|
|
|
+ @ApiOperation("根据ID查询视频")
|
|
|
+ @GetMapping("/{id}")
|
|
|
+ public Video getById(@PathVariable Long id) {
|
|
|
+ return videoService.getById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增视频
|
|
|
+ * @param video 视频对象
|
|
|
+ * @return 操作结果
|
|
|
+ */
|
|
|
+ @ApiOperation("新增视频")
|
|
|
+ @PostMapping
|
|
|
+ public String add(@RequestBody Video video) {
|
|
|
+ videoService.add(video);
|
|
|
+ return "新增成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新视频
|
|
|
+ * @param video 视频对象
|
|
|
+ * @return 操作结果
|
|
|
+ */
|
|
|
+ @ApiOperation("更新视频")
|
|
|
+ @PutMapping
|
|
|
+ public String update(@RequestBody Video video) {
|
|
|
+ videoService.update(video);
|
|
|
+ return "更新成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除视频
|
|
|
+ * @param id 视频ID
|
|
|
+ * @return 操作结果
|
|
|
+ */
|
|
|
+ @ApiOperation("删除视频")
|
|
|
+ @DeleteMapping("/{id}")
|
|
|
+ public String delete(@PathVariable Long id) {
|
|
|
+ videoService.delete(id);
|
|
|
+ return "删除成功";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取某个课目下的所有视频地址。
|
|
|
+ *
|
|
|
+ * @return 查询结果。
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "获取课目的监控视频地址")
|
|
|
+ @NoAuthInterface
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "taskId"),
|
|
|
+ @ApiImplicitParam(name = "subjectName"),
|
|
|
+ })
|
|
|
+ @PostMapping("/getSubjectCardUrls")
|
|
|
+ public ResponseResult<List<VideoVo>> getSubjectCardUrls(@MyRequestBody String taskId, @MyRequestBody String subjectName) {
|
|
|
+// return ResponseResult.success(taskServiceV2.listCardOfSubject(taskId, subjectName));
|
|
|
+ return ResponseResult.success(new ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取某个系统下的所有采集卡地址。
|
|
|
+ *
|
|
|
+ * @return 查询结果。
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "获取采集卡地址")
|
|
|
+ @NoAuthInterface
|
|
|
+ @PostMapping("/getSystemUrl")
|
|
|
+ public List<VideoVo> getSystemUrl(String systemId) {
|
|
|
+// List<VideoVo> videoVoList = videoService.getSystemVideo(systemId);
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteTsFile() {
|
|
|
+ File file = new File("F://nginx-1.8.1/nginx-rtmp-win32-dev/html");
|
|
|
+ String[] filelist = file.list();
|
|
|
+ for (int i = 0; i < filelist.length; i++) {
|
|
|
+ File delfile = new File("F://nginx-1.8.1/nginx-rtmp-win32-dev/html" + "/" + filelist[i]);
|
|
|
+ if (!delfile.isDirectory()) {
|
|
|
+ if (delfile.getName().endsWith("ts")) {
|
|
|
+ delfile.delete();
|
|
|
+ System.out.println(delfile.getAbsolutePath() + "删除文件成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void closeHistoryProgram(String processName) {
|
|
|
+ String cmd = "taskkill /f /t /im " + processName;
|
|
|
+// try {
|
|
|
+ CommandUtil commandUtil = new CommandUtil();
|
|
|
+ commandUtil.winExec(cmd);
|
|
|
+// // exec执行cmd命令
|
|
|
+// Process process = Runtime.getRuntime().exec(cmd);
|
|
|
+// // 获取CMD命令结果的输出流
|
|
|
+// InputStream fis = process.getInputStream();
|
|
|
+// InputStreamReader isr = new InputStreamReader(fis, "GBK");
|
|
|
+// // 使用缓冲器读取
|
|
|
+// BufferedReader br = new BufferedReader(isr);
|
|
|
+// String line = null;
|
|
|
+// // 全部读取完成为止,一行一行读取
|
|
|
+// while ((line = br.readLine()) != null) {
|
|
|
+// // 输出读取的内容
|
|
|
+//// System.out.println(line);
|
|
|
+// }
|
|
|
+// } catch (IOException e) {
|
|
|
+//
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|