Commit 20a47729fc3349df5f08f17d1f8fd5b8db8dcb57
Merge branch '2.6.8' into wvp-28181-2.0
# Conflicts: # src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
Showing
1 changed file
with
55 additions
and
2 deletions
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
| ... | ... | @@ -111,9 +111,43 @@ public class StreamProxyServiceImpl implements IStreamProxyService { |
| 111 | 111 | logger.warn("保存代理未找到在线的ZLM..."); |
| 112 | 112 | throw new ControllerException(ErrorCode.ERROR100.getCode(), "保存代理未找到在线的ZLM"); |
| 113 | 113 | } |
| 114 | - String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(), | |
| 115 | - param.getStream() ); | |
| 114 | + String dstUrl; | |
| 115 | + if ("ffmpeg".equalsIgnoreCase(param.getType())) { | |
| 116 | + JSONObject jsonObject = zlmresTfulUtils.getMediaServerConfig(mediaInfo); | |
| 117 | + if (jsonObject.getInteger("code") != 0) { | |
| 118 | + throw new ControllerException(ErrorCode.ERROR100.getCode(), "获取流媒体配置失败"); | |
| 119 | + } | |
| 120 | + JSONArray dataArray = jsonObject.getJSONArray("data"); | |
| 121 | + JSONObject mediaServerConfig = dataArray.getJSONObject(0); | |
| 122 | + String ffmpegCmd = mediaServerConfig.getString(param.getFfmpegCmdKey()); | |
| 123 | + String schema = getSchemaFromFFmpegCmd(ffmpegCmd); | |
| 124 | + if (schema == null) { | |
| 125 | + throw new ControllerException(ErrorCode.ERROR100.getCode(), "ffmpeg拉流代理无法从ffmpeg cmd中获取到输出格式"); | |
| 126 | + } | |
| 127 | + int port; | |
| 128 | + String schemaForUri; | |
| 129 | + if (schema.equalsIgnoreCase("rtsp")) { | |
| 130 | + port = mediaInfo.getRtspPort(); | |
| 131 | + schemaForUri = schema; | |
| 132 | + }else if (schema.equalsIgnoreCase("flv")) { | |
| 133 | + port = mediaInfo.getHttpPort(); | |
| 134 | + schemaForUri = "http"; | |
| 135 | + }else if (schema.equalsIgnoreCase("rtmp")) { | |
| 136 | + port = mediaInfo.getRtmpPort(); | |
| 137 | + schemaForUri = schema; | |
| 138 | + }else { | |
| 139 | + port = mediaInfo.getRtmpPort(); | |
| 140 | + schemaForUri = schema; | |
| 141 | + } | |
| 142 | + | |
| 143 | + dstUrl = String.format("%s://%s:%s/%s/%s", schemaForUri, "127.0.0.1", port, param.getApp(), | |
| 144 | + param.getStream()); | |
| 145 | + }else { | |
| 146 | + dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(), | |
| 147 | + param.getStream()); | |
| 148 | + } | |
| 116 | 149 | param.setDstUrl(dstUrl); |
| 150 | + logger.info("[拉流代理] 输出地址为:{}", dstUrl); | |
| 117 | 151 | param.setMediaServerId(mediaInfo.getId()); |
| 118 | 152 | boolean saveResult; |
| 119 | 153 | // 更新 |
| ... | ... | @@ -160,6 +194,25 @@ public class StreamProxyServiceImpl implements IStreamProxyService { |
| 160 | 194 | } |
| 161 | 195 | } |
| 162 | 196 | |
| 197 | + private String getSchemaFromFFmpegCmd(String ffmpegCmd) { | |
| 198 | + ffmpegCmd = ffmpegCmd.replaceAll(" + ", " "); | |
| 199 | + String[] paramArray = ffmpegCmd.split(" "); | |
| 200 | + if (paramArray.length == 0) { | |
| 201 | + return null; | |
| 202 | + } | |
| 203 | + for (int i = 0; i < paramArray.length; i++) { | |
| 204 | + if (paramArray[i].equalsIgnoreCase("-f")) { | |
| 205 | + if (i + 1 < paramArray.length - 1) { | |
| 206 | + return paramArray[i+1]; | |
| 207 | + }else { | |
| 208 | + return null; | |
| 209 | + } | |
| 210 | + | |
| 211 | + } | |
| 212 | + } | |
| 213 | + return null; | |
| 214 | + } | |
| 215 | + | |
| 163 | 216 | /** |
| 164 | 217 | * 新增代理流 |
| 165 | 218 | * @param streamProxyItem | ... | ... |