Kaynağa Gözat

报警回放测试

gao.qiang 1 yıl önce
ebeveyn
işleme
3f5972dc2f

+ 25 - 7
business-service/src/main/java/com/ozs/utils/CameraUtil.java

@@ -8,6 +8,7 @@ import com.hikvision.artemis.sdk.ArtemisHttpUtil;
 import com.hikvision.artemis.sdk.config.ArtemisConfig;
 import com.ozs.common.config.BaseConfig;
 import com.ozs.common.constant.Constants;
+import com.ozs.common.core.domain.AjaxResult;
 import com.ozs.common.core.domain.entity.SysDictData;
 import com.ozs.common.core.redis.RedisCache;
 import com.ozs.common.exception.base.BaseException;
@@ -107,6 +108,10 @@ public class CameraUtil {
     private MsgHeartbeatAlarmMessageService msgHeartbeatAlarmMessageService;
     @Autowired
     private ISysDictTypeService dictTypeService;
+    @Autowired
+    private RtspToMP4 rtspToMP4;
+
+    private Map<String, Process> map = new HashMap<>();
 
     public final static String tsFilekey = "mergeVideoTsFile";
 
@@ -955,19 +960,32 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
 //                    JSONObject data = outJson.getJSONObject("data");
 //                    String urls = data.getString("url");
 //                log.info("--------------->code::" + code);
-                FfmpegUtil recordVideoThread = new FfmpegUtil();
-                recordVideoThread.stream_url="rtsp://124.70.58.209:8554/"+code+"/"+code;
-                recordVideoThread.out_file_path = "/opt/streams/map/"+code+".mp4";
-                recordVideoThread.times_sec = 300L;// 最好设置结束时长 如直接停止程序会造成输出文件的损坏无法正常播放
-                recordVideoThread.is_audio = true;
-                new Thread(recordVideoThread).start();
-//                }
+                
+                String streamUrl = "rtsp://124.70.58.209:8554/"+code+"/"+code;;
+                String FilePath = "/opt/streams/map/"+code+".mp4";
+                Process process = rtspToMP4.StartRecord(ffmpegPath, streamUrl, FilePath);
+                log.info("------playbackURLs----->>>>:"+process);
+                if (null != process) {
+                    map.put(code, process);
+                }
             }
             return 1;
         });
         future.join();
     }
 
+    public AjaxResult stop(String id) {
+        if (map.containsKey(id)) {
+            Process process = map.get(id);
+            log.info("-----stop------>>>"+process);
+            if (null != process) {
+                rtspToMP4.stopRecord(process);
+                return AjaxResult.success();
+            }
+        }
+        return AjaxResult.error();
+    }
+
     public static void main(String[] args) throws InterruptedException, ParseException, IOException {
 //        CameraUtil cameraUtil = new CameraUtil();
 //        cameraUtil.closeRecording();

+ 0 - 93
business-service/src/main/java/com/ozs/utils/FfmpegUtil.java

@@ -1,93 +0,0 @@
-package com.ozs.utils;
-
-import lombok.extern.slf4j.Slf4j;
-import org.bytedeco.javacpp.avcodec;
-import org.bytedeco.javacv.FFmpegFrameGrabber;
-import org.bytedeco.javacv.FFmpegFrameRecorder;
-import org.bytedeco.javacv.Frame;
-import org.bytedeco.javacv.FrameGrabber;
-import org.bytedeco.javacv.FrameRecorder;
-import org.springframework.context.annotation.Configuration;
-
-import java.io.File;
-import java.io.IOException;
-
-
-@Configuration
-@Slf4j
-public class FfmpegUtil implements Runnable {
-
-    public String stream_url;// 流地址 例如:rtmp://58.200.131.2:1935/livetv/hunantv 湖南卫视
-    public Long times_sec = 0L;// 停止录制时长 0为不限制时长
-    public String out_file_path;//输出路径
-    public String file_format = "mp4";//录制的文件格式
-    public boolean is_audio = false;//是否录制声音
-
-    @Override
-    public void run() {
-// 获取视频源
-        FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(stream_url);
-        FFmpegFrameRecorder recorder = null;
-        try {
-            grabber.start();
-            Frame frame = grabber.grabFrame();
-            if (frame != null) {
-//保存到本地的文件
-                File outFile = new File(out_file_path);
-// 如果文件不存在或者不是一个文件 则根据文件的路径创建一个文件
-                if (out_file_path.isEmpty() || !outFile.exists() || outFile.isFile()) {
-                    outFile.createNewFile();
-                } else {
-                    log.info("输出文件无法创建");
-                    return;
-                }
-// 流媒体输出地址,分辨率(长,高),是否录制音频(0:不录制/1:录制)
-                recorder = new FFmpegFrameRecorder(out_file_path, 800, 480, is_audio ? 1 : 0);
-                recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);//直播流格式
-                recorder.setFormat(file_format);//录制的视频格式
-                recorder.setFrameRate(200);//帧数
-                recorder.start();//开始录制
-// 计算结束时间
-                long endTime = System.currentTimeMillis() + times_sec * 1000;
-// 如果没有到录制结束时间并且获取到了下一帧则继续录制
-                while ((System.currentTimeMillis() < endTime) && (frame != null)) {
-                    recorder.record(frame);//录制
-                    frame = grabber.grabFrame();//获取下一帧
-                }
-                recorder.record(frame);
-            }
-        } catch (FrameGrabber.Exception e) {
-            e.printStackTrace();
-        } catch (FrameRecorder.Exception e) {
-            e.printStackTrace();
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-//停止录制
-            if (null != grabber) {
-                try {
-                    grabber.stop();
-                } catch (FrameGrabber.Exception e) {
-                    e.printStackTrace();
-                }
-            }
-            if (recorder != null) {
-                try {
-                    recorder.stop();
-                } catch (FrameRecorder.Exception e) {
-                    e.printStackTrace();
-                }
-            }
-            log.info("录制完成,录制时长:" + times_sec + "秒(0为没有限制录制时长)");
-        }
-    }
-
-    public static void main(String[] args) {
-        FfmpegUtil recordVideoThread = new FfmpegUtil();
-        recordVideoThread.out_file_path = "/opt/streams/map/42010001541320000024.mp4";
-        recordVideoThread.times_sec = 10L;// 最好设置结束时长 如直接停止程序会造成输出文件的损坏无法正常播放
-        recordVideoThread.is_audio = true;
-        new Thread(recordVideoThread).start();
-    }
-}
-

+ 7 - 22
vehicle-admin/src/main/java/com/ozs/web/controller/accountmanagment/BaseCameraManagementController.java

@@ -29,7 +29,6 @@ import com.ozs.utils.CameraUtil;
 import com.ozs.utils.CaneraConfig;
 import com.ozs.utils.RtspToMP4;
 import com.ozs.web.core.config.GetCameraPreviewURL;
-import io.minio.Result;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
@@ -77,8 +76,6 @@ public class BaseCameraManagementController extends BaseController {
     @Autowired
     private BaseRailwayManagementService baseRailwayManagementService;
     @Autowired
-    private RtspToMP4 rtspToMP4;
-    @Autowired
     private IdempotenceUtils idempotenceUtils;
     @Autowired
     private DataScoreUtil dataScoreUtil;
@@ -88,7 +85,6 @@ public class BaseCameraManagementController extends BaseController {
     @Autowired
     private CameraUtil cameraUtil;
 
-    private Map<String, Process> map = new HashMap<>();
 
     /**
      * 所有相机列表+权限
@@ -1036,29 +1032,18 @@ public class BaseCameraManagementController extends BaseController {
     @GetMapping(value = "/getAlarmRecord")
     @ApiOperation("报警回放本地测试")
     @Log(title = "相机台账管理", businessType = BusinessType.MESSAGE)
-    public AjaxResult getAlarmRecord(){
-        String ffmpegPath = "/usr/bin/ffmpeg";
-        String streamUrl = "rtsp://124.70.58.209:8554/42010001541320000024/42010001541320000024";
-        String FilePath = "/opt/streams/map/42010001541320000024.mp4";
-        Process process = rtspToMP4.StartRecord(ffmpegPath, streamUrl, FilePath);
-        if (null != process) {
-            map.put("42010001541320000024", process);
-            return AjaxResult.success();
-        }
-        return AjaxResult.error();
+    public AjaxResult getAlarmRecord() {
+        List<BaseCameraManagement> list = baseCameraManagementService.list(new QueryWrapper<BaseCameraManagement>().eq("line_dir",2));
+        List<String> collect = list.stream().map(BaseCameraManagement::getCameraCode).collect(Collectors.toList());
+        CompletableFuture.runAsync(() -> cameraUtil.playbackURLs(collect));
+        return AjaxResult.success("ok");
     }
 
+
     @ApiOperation(value = "结束录制")
     @GetMapping(value = "/stop")
     public AjaxResult stop(String id) {
-        if (map.containsKey(id)) {
-            Process process = map.get(id);
-            if (null != process) {
-                rtspToMP4.stopRecord(process);
-                return AjaxResult.success();
-            }
-        }
-        return AjaxResult.error();
+      return cameraUtil.stop(id);
     }
 }