修复 拉流代理的ffmpeg模式

This commit is contained in:
64850858
2021-06-04 19:22:47 +08:00
parent a209ba77ea
commit 2af5cf496c
8 changed files with 69 additions and 8 deletions

View File

@@ -176,13 +176,17 @@ public class ZLMRESTfulUtils {
return sendPost("getRtpInfo",param, null);
}
public JSONObject addFFmpegSource(String src_url, String dst_url, String timeout_ms){
public JSONObject addFFmpegSource(String src_url, String dst_url, String timeout_ms,
boolean enable_hls, boolean enable_mp4, String ffmpeg_cmd_key){
logger.info(src_url);
logger.info(dst_url);
Map<String, Object> param = new HashMap<>();
param.put("src_url", src_url);
param.put("dst_url", dst_url);
param.put("timeout_ms", timeout_ms);
param.put("enable_hls", enable_hls);
param.put("enable_mp4", enable_mp4);
param.put("ffmpeg_cmd_key", ffmpeg_cmd_key);
return sendPost("addFFmpegSource",param, null);
}

View File

@@ -115,7 +115,7 @@ public class ZLMRunner implements CommandLineRunner {
}
Map<String, Object> param = new HashMap<>();
param.put("api.secret",mediaConfig.getSecret()); // -profile:v Baseline
// param.put("ffmpeg.cmd","%s -fflags nobuffer -rtsp_transport tcp -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s");
param.put("ffmpeg.cmd","%s -fflags nobuffer -rtsp_transport tcp -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s");
param.put("hook.enable","1");
param.put("hook.on_flow_report","");
param.put("hook.on_play",String.format("%s/on_play", hookPrex));

View File

@@ -56,4 +56,10 @@ public interface IStreamProxyService {
* @return
*/
boolean stop(String app, String stream);
/**
* 获取ffmpeg.cmd模板
* @return
*/
JSONObject getFFmpegCMDs();
}

View File

@@ -104,7 +104,8 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
param.isEnable_hls(), param.isEnable_mp4(), param.getRtp_type());
}else if ("ffmpeg".equals(param.getType())) {
result = zlmresTfulUtils.addFFmpegSource(param.getSrc_url(), param.getDst_url(),
param.getTimeout_ms() + "");
param.getTimeout_ms() + "", param.isEnable_hls(), param.isEnable_mp4(),
param.getFfmpeg_cmd_key());
}
return result;
}
@@ -165,4 +166,22 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
}
return result;
}
@Override
public JSONObject getFFmpegCMDs() {
JSONObject result = new JSONObject();
JSONObject mediaServerConfigResuly = zlmresTfulUtils.getMediaServerConfig();
if (mediaServerConfigResuly != null && mediaServerConfigResuly.getInteger("code") == 0
&& mediaServerConfigResuly.getJSONArray("data").size() > 0){
JSONObject mediaServerConfig = mediaServerConfigResuly.getJSONArray("data").getJSONObject(0);
for (String key : mediaServerConfig.keySet()) {
if (key.startsWith("ffmpeg.cmd")){
result.put(key, mediaServerConfig.getString(key));
}
}
}
return result;
}
}

View File

@@ -168,7 +168,7 @@ public class PlayController {
String dstUrl = String.format("rtmp://%s:%s/convert/%s", "127.0.0.1", mediaInfo.getRtmpPort(),
streamId );
String srcUrl = String.format("rtsp://%s:%s/rtp/%s", "127.0.0.1", mediaInfo.getRtspPort(), streamId);
JSONObject jsonObject = zlmresTfulUtils.addFFmpegSource(srcUrl, dstUrl, "1000000");
JSONObject jsonObject = zlmresTfulUtils.addFFmpegSource(srcUrl, dstUrl, "1000000", true, false, null);
logger.info(jsonObject.toJSONString());
JSONObject result = new JSONObject();
if (jsonObject != null && jsonObject.getInteger("code") == 0) {

View File

@@ -66,6 +66,19 @@ public class StreamProxyController {
return result;
}
@ApiOperation("获取ffmpeg.cmd模板")
@GetMapping(value = "/ffmpeg_cmd/list")
@ResponseBody
public WVPResult getFFmpegCMDs(){
logger.debug("获取ffmpeg.cmd模板" );
JSONObject data = streamProxyService.getFFmpegCMDs();
WVPResult<JSONObject> result = new WVPResult<>();
result.setCode(0);
result.setMsg("success");
result.setData(data);
return result;
}
@ApiOperation("移除代理")
@ApiImplicitParams({
@ApiImplicitParam(name = "app", value = "应用名", dataTypeClass = String.class),