From 2af5cf496c811fd302564c7edb29d4e5f6cf31e2 Mon Sep 17 00:00:00 2001 From: 64850858 <648540858@qq.com> Date: Fri, 4 Jun 2021 19:22:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E6=8B=89=E6=B5=81?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E7=9A=84ffmpeg=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/media/zlm/ZLMRESTfulUtils.java | 6 ++++- .../iot/vmp/media/zlm/ZLMRunner.java | 2 +- .../iot/vmp/service/IStreamProxyService.java | 6 +++++ .../service/impl/StreamProxyServiceImpl.java | 21 +++++++++++++++- .../vmanager/gb28181/play/PlayController.java | 2 +- .../streamProxy/StreamProxyController.java | 13 ++++++++++ web_src/src/components/CloudRecord.vue | 2 -- .../src/components/dialog/StreamProxyEdit.vue | 25 +++++++++++++++++-- 8 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java index c8aa2455..d0c88b08 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java @@ -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 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); } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java index e255bd3f..d622101e 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java @@ -115,7 +115,7 @@ public class ZLMRunner implements CommandLineRunner { } Map 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)); diff --git a/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java b/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java index cddc21c7..2f7388a9 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java @@ -56,4 +56,10 @@ public interface IStreamProxyService { * @return */ boolean stop(String app, String stream); + + /** + * 获取ffmpeg.cmd模板 + * @return + */ + JSONObject getFFmpegCMDs(); } 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 a77371f3..2eb99b82 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 @@ -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; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java index 5f44e76f..783542de 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java @@ -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) { diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java index 2baa9999..fd53ceaa 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java @@ -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 result = new WVPResult<>(); + result.setCode(0); + result.setMsg("success"); + result.setData(data); + return result; + } + @ApiOperation("移除代理") @ApiImplicitParams({ @ApiImplicitParam(name = "app", value = "应用名", dataTypeClass = String.class), diff --git a/web_src/src/components/CloudRecord.vue b/web_src/src/components/CloudRecord.vue index 2e6d34c9..c2692700 100644 --- a/web_src/src/components/CloudRecord.vue +++ b/web_src/src/components/CloudRecord.vue @@ -14,8 +14,6 @@
- - 节点选择: - + - + + + + + @@ -159,6 +171,7 @@ export default { enable_mp4: false, platformGbId: null, }, + ffmpegCmdList:{}, rules: { name: [{ required: true, message: "请输入名称", trigger: "blur" }], @@ -189,6 +202,14 @@ export default { }).catch(function (error) { console.log(error); }); + this.$axios({ + method: 'get', + url:`/api/proxy/ffmpeg_cmd/list` + }).then(function (res) { + that.ffmpegCmdList = res.data.data; + }).catch(function (error) { + console.log(error); + }); }, onSubmit: function () { console.log("onSubmit");