From 468e2b2ffbbb4e15dea11d1f9c7451a8097a3ab8 Mon Sep 17 00:00:00 2001
From: xiaoQQya <xiaoQQya@126.com>
Date: 星期日, 09 七月 2023 20:22:40 +0800
Subject: [PATCH] fix(play): 修复作为上级平台点播截取快照问题

---
 src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
index 195f035..7171138 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
@@ -111,9 +111,40 @@
             logger.warn("淇濆瓨浠g悊鏈壘鍒板湪绾跨殑ZLM...");
             throw new ControllerException(ErrorCode.ERROR100.getCode(), "淇濆瓨浠g悊鏈壘鍒板湪绾跨殑ZLM");
         }
-        String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(),
-                param.getStream() );
+        String dstUrl;
+        if ("ffmpeg".equalsIgnoreCase(param.getType())) {
+            JSONObject jsonObject = zlmresTfulUtils.getMediaServerConfig(mediaInfo);
+            if (jsonObject.getInteger("code") != 0) {
+                throw new ControllerException(ErrorCode.ERROR100.getCode(), "鑾峰彇娴佸獟浣撻厤缃け璐�");
+            }
+            JSONArray dataArray = jsonObject.getJSONArray("data");
+            JSONObject mediaServerConfig = dataArray.getJSONObject(0);
+            String ffmpegCmd = mediaServerConfig.getString(param.getFfmpegCmdKey());
+            String schema = getSchemaFromFFmpegCmd(ffmpegCmd);
+            if (schema == null) {
+                throw new ControllerException(ErrorCode.ERROR100.getCode(), "ffmpeg鎷夋祦浠g悊鏃犳硶浠巉fmpeg cmd涓幏鍙栧埌杈撳嚭鏍煎紡");
+            }
+            int port;
+            String schemaForUri;
+            if (schema.equalsIgnoreCase("rtsp")) {
+                port = mediaInfo.getRtspPort();
+                schemaForUri = schema;
+            }else if (schema.equalsIgnoreCase("flv")) {
+                port = mediaInfo.getRtmpPort();
+                schemaForUri = schema;
+            }else {
+                port = mediaInfo.getRtmpPort();
+                schemaForUri = schema;
+            }
+
+            dstUrl = String.format("%s://%s:%s/%s/%s", schemaForUri, "127.0.0.1", port, param.getApp(),
+                    param.getStream());
+        }else {
+            dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(),
+                    param.getStream());
+        }
         param.setDstUrl(dstUrl);
+        logger.info("[鎷夋祦浠g悊] 杈撳嚭鍦板潃涓猴細{}", dstUrl);
         param.setMediaServerId(mediaInfo.getId());
         boolean saveResult;
         // 鏇存柊
@@ -160,6 +191,25 @@
         }
     }
 
+    private String getSchemaFromFFmpegCmd(String ffmpegCmd) {
+        ffmpegCmd = ffmpegCmd.replaceAll(" + ", " ");
+        String[] paramArray = ffmpegCmd.split(" ");
+        if (paramArray.length == 0) {
+            return null;
+        }
+        for (int i = 0; i < paramArray.length; i++) {
+            if (paramArray[i].equalsIgnoreCase("-f")) {
+                if (i + 1 < paramArray.length - 1) {
+                    return paramArray[i+1];
+                }else {
+                    return null;
+                }
+
+            }
+        }
+        return null;
+    }
+
     /**
      * 鏂板浠g悊娴�
      * @param streamProxyItem

--
Gitblit v1.8.0