ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
@@ -501,6 +501,7 @@ //region 处理通用光电报警 ArdAlarmCamera ardAlarmCamera = JSONObject.parseObject(message, ArdAlarmCamera.class); ardAlarmCamera.setId(IdUtils.simpleUUID()); ardAlarmCamera.setCreateTime(new Date()); int aac = ardAlarmCameraMapper.insertArdAlarmCamera(ardAlarmCamera); if (aac > 0) { log.debug("camera入库成功:" + ardAlarmCamera); ard-work/src/main/java/com/ruoyi/media/controller/MediaController.java
@@ -7,6 +7,7 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.device.camera.domain.ArdCameras; import com.ruoyi.media.domain.StreamInfo; import com.ruoyi.media.service.IMediaService; @@ -37,7 +38,15 @@ @PreAuthorize("@ss.hasPermi('media:stream:add')") @ApiOperationSupport(includeParameters = {"streamInfo.name", "streamInfo.rtspSource", "streamInfo.mode"}) public AjaxResult addPath(@RequestBody StreamInfo streamInfo) { String rtsp = mediaService.addPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode()); if(StringUtils.isEmpty(streamInfo.getName())) { return AjaxResult.error("通道名称不能为空"); } if(StringUtils.isEmpty(streamInfo.getRtspSource())) { return AjaxResult.error("rtsp地址不能为空"); } String rtsp = mediaService.addPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode(),streamInfo.getIsCode()); return AjaxResult.success(rtsp); } /** @@ -56,7 +65,7 @@ @PutMapping public AjaxResult edit(@RequestBody StreamInfo streamInfo) { mediaService.removePath(new String[]{streamInfo.getName()}); String rtsp = mediaService.addPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode()); String rtsp = mediaService.addPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode(),streamInfo.getIsCode()); return AjaxResult.success(rtsp); } ard-work/src/main/java/com/ruoyi/media/domain/StreamInfo.java
@@ -59,7 +59,13 @@ String remoteAddr; /** * 转码模式 * 模式 */ String mode; /** * 是否转码 */ String isCode; } ard-work/src/main/java/com/ruoyi/media/service/IMediaService.java
@@ -1,4 +1,5 @@ package com.ruoyi.media.service; import com.ruoyi.media.domain.Items; import com.ruoyi.media.domain.RtspSession; import com.ruoyi.media.domain.StreamInfo; @@ -6,20 +7,35 @@ import java.util.List; public interface IMediaService { /** * 增加路径 * name 名称 * rtspPath rtsp地址 * mode 模式:实时/按需 * isCode 是否转码 * 刘苏义 * 2023/8/12 13:56:52 */ public String addPath(String name, String rtspPath, String mode, String isCode); public String addPath(String name, String rtspPath,String mode); StreamInfo getPathInfo(String name); public void removePath(String[] names); public List<StreamInfo>paths(); public List<Items> rtspconns(); public List<Items> rtspsessions(); RtspSession getRtspSessionById(String sessionId); List<RtspSession>getPushStreams(); List<RtspSession>getPullStreams(); List<StreamInfo>getPushStreamList(); List<StreamInfo>getPullStreamList(); Boolean kickRtspSession(String sessionId); ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
@@ -81,8 +81,8 @@ } @Override public String addPath(String name, String rtspPath, String mode) { String rtspUrl = "rtsp://" + mediamtxHost + ":7554/"; public String addPath(String name, String rtspPath, String mode, String isCode) { String rtspUrl = "rtsp://" + mediamtxHost + ":7554/" + name; Conf mediaInfo = new Conf(); //-vcodec libx264 //指定视频编码器为 libx264,使用 H.264 编码格式进行视频压缩 //-preset ultrafast //--preset的参数主要调节编码速度和质量的平衡,有ultrafast(转码速度最快,视频往往也最模糊)、superfast、veryfast、faster、fast、medium、slow、slower、veryslow、placebo这10个选项,从快到慢 @@ -95,7 +95,7 @@ String cmd = "ffmpeg -rtsp_transport tcp -i \"" + rtspPath + "\" -vcodec libx264 -preset:v ultrafast -r 25 -threads 4 -b:v 4096k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH"; //GPU硬解码编码 -hwaccel cuvid -c:v h264_cuvid 使用cuda解码 -c:v h264_nvenc 使用cuda编码 //String cmd = "ffmpeg -hwaccel cuvid -c:v h264_cuvid -rtsp_transport udp -i \"" + rtspPath + "\" -c:v h264_nvenc -r 25 -threads 4 -b:v 4096k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH"; if (isCode.equals("1")) { if (mode.equals("1")) { mediaInfo.setRunondemand(cmd); mediaInfo.setRunondemandrestart(true); @@ -103,8 +103,12 @@ mediaInfo.setRunoninit(cmd); mediaInfo.setRunoninitrestart(true); } } else { mediaInfo.setSource(rtspPath); } mediaClient.addPath(name, mediaInfo); return rtspUrl + name; return rtspUrl; } @Override @@ -128,6 +132,12 @@ Matcher matcher = pattern.matcher(runoninit); if (matcher.find()) { info.setRtspSource(matcher.group()); info.setIsCode("1"); } else { info.setRtspSource(item.getConf().getSource()); info.setIsCode("0"); } return info; } @@ -141,7 +151,6 @@ @Override public List<StreamInfo> paths() { String list = mediaClient.paths(); JsonsRoot jsonsRoot = JSONObject.parseObject(list, JsonsRoot.class); List<Items> items = jsonsRoot.getItems(); @@ -166,6 +175,10 @@ Matcher matcher = pattern.matcher(runoninit); if (matcher.find()) { info.setRtspSource(matcher.group()); info.setIsCode("1"); } else { info.setRtspSource(item.getConf().getSource()); info.setIsCode("0"); } //传输协议 regex = "-rtsp_transport\\s+(\\w+)"; @@ -249,9 +262,14 @@ String rtspUrl = "rtsp://" + mediamtxHost + ":7554/" + name; info.setRtspUrl(rtspUrl); Source source = item.getSource(); if (source == null) { continue; } if (source.getId().equals("")) { //会话ID info.setId("0"); //上行流量 long bytesReceived = item.getBytesReceived(); String formatReceivedSize = ArdTool.formatFileSize(bytesReceived); info.setUpTraffic(formatReceivedSize); } else { RtspSession rtspSession = getRtspSessionById(source.getId()); //会话ID info.setId(rtspSession.getId()); @@ -265,6 +283,9 @@ long bytesSent = rtspSession.getBytesSent(); String formatSentSize = ArdTool.formatFileSize(bytesSent); info.setDownTraffic(formatSentSize); //推流服务器 info.setRemoteAddr(rtspSession.getRemoteAddr()); } //RTSP源地址 String runondemand = item.getConf().getRunondemand(); String runoninit; @@ -279,6 +300,10 @@ if (matcher.find()) { info.setRtspSource(matcher.group()); } else { info.setRtspSource(item.getConf().getSource()); } //传输协议 regex = "-rtsp_transport\\s+(\\w+)"; pattern = Pattern.compile(regex); @@ -289,8 +314,7 @@ //拉流数量 List<Readers> readers = item.getReaders(); info.setNum(readers.size()); //推流服务器 info.setRemoteAddr(rtspSession.getRemoteAddr()); PushStreamInfoList.add(info); }