diff --git a/loadCmd.properties b/loadCmd.properties index ef52bbf..c089a05 100644 --- a/loadCmd.properties +++ b/loadCmd.properties @@ -4,7 +4,7 @@ pushUrl=rtmp://192.168.10.101:19350/rlive/stream_11?sign=rHtBg3sz #playUrl=http://192.168.10.101:18000/flv/live/34020000001110000001_34020000001320000099_0200000099.flv playUrl=http://192.168.10.101:18000/flv/live/stream_176.flv #固定通道 1 获取通道 2 多线程双路 3 单线程多路 4 -type=3 +type=0 mqttUrl=tcp://106.15.120.154 #主题 12345替换对应机场编号 004替换控制板id @@ -15,4 +15,8 @@ time=600000 #多路推流(选配) pushUrlMap=tee "[f=flv]rtmp://221.226.114.142:19350/rlive/stream_9?sign=f8a15b6n | [f=flv]rtmp://221.226.114.142:19350/rlive/stream_11?sign=rHtBg3sz" -pushUrl2=rtmp://192.168.10.101:19350/rlive/stream_17?sign=64FIaU8X \ No newline at end of file +pushUrl2=rtmp://192.168.10.101:19350/rlive/stream_17?sign=64FIaU8X +#cmd=ffmpeg -rtsp_transport tcp -i https://easycvr-local.t-aaron.com:1445/flv/live/34020000001110000002_34020000001320000072_0200000072.flv -vcodec copy -f flv -an rtmp://192.168.10.101:19350/rlive/stream_11?sign=rHtBg3sz +cmd=ffmpeg.exe -rtsp_transport tcp -re -i rtsp://192.168.144.25:554/main -vcodec copy -acodec aac -map 0 -f tee "[f=flv]rtmp://221.226.114.142:19350/rlive/stream_9?sign=f8a15b6n | [f=flv]rtmp://221.226.114.142:19350/rlive/stream_11?sign=rHtBg3sz" + + diff --git a/src/main/java/com/github/bluesbruce/spring/config/CmdParam.java b/src/main/java/com/github/bluesbruce/spring/config/CmdParam.java index c9b27a1..21df0b0 100644 --- a/src/main/java/com/github/bluesbruce/spring/config/CmdParam.java +++ b/src/main/java/com/github/bluesbruce/spring/config/CmdParam.java @@ -8,11 +8,21 @@ public class CmdParam { private int type;//1 鍥哄畾閫氶亾 2 閫氶亾鏈嶅姟 String mqttUrl; int time; + //ffmpeg 鎸囦护 + private String cmd; public int getTime() { return time; } + public String getCmd() { + return cmd; + } + + public void setCmd(String cmd) { + this.cmd = cmd; + } + public void setTime(int time) { this.time = time; } @@ -63,14 +73,19 @@ public class CmdParam { this.type = type; } - public CmdParam(String pushUrl, String playUrl, int type, String mqttUrl, String mqttTopic) { + public CmdParam(String pushUrl, String pushUrlMap, String pushUrl2, String playUrl, int type, String mqttUrl, int time, String cmd, String mqttTopic) { this.pushUrl = pushUrl; + this.pushUrlMap = pushUrlMap; + this.pushUrl2 = pushUrl2; this.playUrl = playUrl; this.type = type; this.mqttUrl = mqttUrl; + this.time = time; + this.cmd = cmd; this.mqttTopic = mqttTopic; } + public CmdParam() { } diff --git a/src/main/java/com/github/bluesbruce/spring/service/RtmpLiveService.java b/src/main/java/com/github/bluesbruce/spring/service/RtmpLiveService.java index 3a7a412..3dc9c55 100644 --- a/src/main/java/com/github/bluesbruce/spring/service/RtmpLiveService.java +++ b/src/main/java/com/github/bluesbruce/spring/service/RtmpLiveService.java @@ -68,6 +68,10 @@ public class RtmpLiveService { status=1; //Thread.sleep(5000); String pushUrl = ""; + if (cmdParam.getType() == 0){ + log.info("浣跨敤鎸囦护鎺ㄦ祦"); + runRtmpByCmd(cmdParam.getCmd()); + }else if (cmdParam.getType() == 2) { log.info("鑾峰彇娴佸獟浣撻氶亾"); //TODO 鑾峰彇閫氶亾鏈嶅姟鎺ㄦ媺娴佸湴鍧 @@ -441,4 +445,39 @@ public class RtmpLiveService { } return null; } + + + /** + * 鏍规嵁鎸囦护鐩存帹 + * @param cmd + */ + public void runRtmpByCmd(String cmd) { + try { + String taskId = manager.start("push0",cmd) ; + cmdParam.getMqttTopic(); + String reTopic = cmdParam.getMqttTopic().replace("live", "result"); + log.info(manager.queryAll().toString()); + JSONObject jsonObject = new JSONObject(); + if (StringUtils.isNullOrEmpty(taskId)) { + jsonObject.put("code", -1); + jsonObject.put("msg", "鎺ㄦ祦鏈嶅姟澶辫触"); //鎺ㄦ祦澶辫触 + mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString()); + // 鍋滄鍏ㄩ儴浠诲姟 + manager.stopAll(); + return; + } else { + jsonObject.put("code", 0); + jsonObject.put("msg", "鎺ㄦ祦鏈嶅姟鍚姩鎴愬姛"); + mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString()); + } + Thread.sleep(cmdParam.getTime()); + log.info(manager.queryAll().toString()); + // 鍋滄鍏ㄩ儴浠诲姟 + manager.stopAll(); + manager.destory(); + } catch (Exception e) { + log.error("", e); + } + //ds.close(); + } } diff --git a/src/main/java/com/github/bluesbruce/spring/web/IndexController.java b/src/main/java/com/github/bluesbruce/spring/web/IndexController.java new file mode 100644 index 0000000..dd794ad --- /dev/null +++ b/src/main/java/com/github/bluesbruce/spring/web/IndexController.java @@ -0,0 +1,120 @@ +package com.github.bluesbruce.spring.web; + + +import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.bluesbruce.ffch.data.CommandTasker; +import com.github.bluesbruce.ffch.handler.DefaultOutHandlerMethod; +import com.github.bluesbruce.spring.config.CmdParam; +import com.github.bluesbruce.spring.service.RtmpLiveService; +import lombok.extern.slf4j.Slf4j; +import org.h2.util.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; + +@Controller +@Slf4j +public class IndexController { + + @Resource + private ObjectMapper objectMapper; + @Autowired + RtmpLiveService rtmpLiveService; + @RequestMapping("/status") + @ResponseBody + public String index() { + JSONObject jsonObject = new JSONObject(); + try { + int status = rtmpLiveService.status; + if(rtmpLiveService.manager.queryAll().size()>0){ + Collection list = rtmpLiveService.manager.queryAll(); + Iterator commandTaskerIterator = list.iterator(); + CommandTasker s = commandTaskerIterator.next(); + jsonObject.put("name",s.getId()); + jsonObject.put("cmd",s.getCommand().split("bin/")[1]); + }; + jsonObject.put("msg",status==0?"绌洪棽":"鎺ㄦ祦涓"); + jsonObject.put("status",status); + return objectMapper.writeValueAsString(jsonObject); + } catch (Exception e) { + e.printStackTrace(); + return "澶辫触"; + } + } + + + @RequestMapping("/config") + @ResponseBody + public String config() { + JSONObject jsonObject = new JSONObject(); + try { + CmdParam cmdParam = rtmpLiveService.cmdParam; + jsonObject.put("pushUrl",cmdParam.getPlayUrl()); + jsonObject.put("playUrl",cmdParam.getPlayUrl()); + return objectMapper.writeValueAsString(jsonObject); + } catch (Exception e) { + e.printStackTrace(); + return "澶辫触"; + } + } + + @RequestMapping("/start") + @ResponseBody + public String start() { + try { + if(rtmpLiveService.manager.queryAll().size()>0){ + rtmpLiveService.status=0; + DefaultOutHandlerMethod.outIdMap= new HashMap(); + rtmpLiveService.manager.stopAll(); + }; + //鍚姩绾跨▼ + Thread thread = new Thread(new Runnable() { + public void run() { + try { + startPush(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + thread.start(); + return objectMapper.writeValueAsString("success"); + } catch (Exception e) { + e.printStackTrace(); + return "澶辫触"; + } + } + + private void startPush() { + try { + rtmpLiveService.pushServer("restart"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @RequestMapping("/stop") + @ResponseBody + public String stop() { + try { + if(rtmpLiveService.manager.queryAll().size()>0){ + rtmpLiveService.status=0; + DefaultOutHandlerMethod.outIdMap= new HashMap(); + rtmpLiveService.manager.stopAll(); + }; + return objectMapper.writeValueAsString("success"); + } catch (Exception e) { + e.printStackTrace(); + return "澶辫触"; + } + } +}