From a2d93fce811acc83ad5ff0b4a93403db22795a10 Mon Sep 17 00:00:00 2001
From: winfed <chinesezwf@gmail.com>
Date: 星期五, 09 六月 2023 15:19:18 +0800
Subject: [PATCH] fix:修复拉流代理配置展示问题:音频、录制、无人观看
---
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 55 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..9ac6ab9 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,43 @@
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.getHttpPort();
+ schemaForUri = "http";
+ }else if (schema.equalsIgnoreCase("rtmp")) {
+ 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 +194,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