root há 2 anos atrás
pai
commit
eb91674e6f

+ 2 - 2
src/main/java/com/zhiqiyun/open/camera/rtsp/RtspPushSrs.java

@@ -1,5 +1,6 @@
 package com.zhiqiyun.open.camera.rtsp;
 
+import cn.hutool.crypto.SecureUtil;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import lombok.extern.slf4j.Slf4j;
 import org.bytedeco.ffmpeg.avcodec.AVCodecParameters;
@@ -39,7 +40,6 @@ public class RtspPushSrs {
      * @throws Exception
      */
     public static void grabberAndPush(String rtspId) throws Exception {
-
         String rtspUrl = RtspTransfer.PATH_MAP.get(rtspId);
 
         // ffmepg日志级别
@@ -105,7 +105,7 @@ public class RtspPushSrs {
         log.info("视频宽度[{}],视频高度[{}],音频通道数[{}],封装格式{{}]", frameWidth, frameHeight, audioChannels, format);
 
         // 实例化FFmpegFrameRecorder,将SRS的推送地址传入
-        String rtmpUrl = String.format(INTRANET_SRS_PUSH_ADDRESS, rtspId);
+        String rtmpUrl = String.format(INTRANET_SRS_PUSH_ADDRESS, SecureUtil.md5(rtspId));
         log.info("流媒体服务地址:{}", rtmpUrl);
         FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(rtmpUrl, frameWidth, frameHeight, audioChannels);
 //        recorder.setInterleaved(true);

+ 4 - 1
src/main/java/com/zhiqiyun/open/router/apis/HwVideoApi.java

@@ -1,5 +1,6 @@
 package com.zhiqiyun.open.router.apis;
 
+import cn.hutool.crypto.SecureUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.dliyun.oap.framework.annotation.ServiceMethod;
@@ -77,10 +78,12 @@ public class HwVideoApi {
         if (StringUtils.isNotBlank(RtspTransfer.STREAM_MAP.get(rtspId))) {
             response.setRtspUri(RtspTransfer.STREAM_MAP.get(rtspId));
         } else {
-            rtspUri = String.format(RtspPushSrs.SRS_PUSH_ADDRESS, rtspId);
+            rtspUri = String.format(RtspPushSrs.SRS_PUSH_ADDRESS, SecureUtil.md5(rtspId));
             log.info("重新进行流推送:{}", rtspUri);
             taskExecutor.execute(() -> {
                 try {
+                    //停顿1秒在进行推流,已缓解频繁开启或关闭推流造成的问题
+                    Thread.sleep(1000);
                     RtspTransfer.startPushRtmp(rtspId);
                 } catch (Exception e) {
                     log.info("============停止推流=======================");