Browse Source

控制台支持

master
wangwei 11 months ago
parent
commit
7dc9992bd8
4 changed files with 181 additions and 3 deletions
  1. +6
    -2
      loadCmd.properties
  2. +16
    -1
      src/main/java/com/github/bluesbruce/spring/config/CmdParam.java
  3. +39
    -0
      src/main/java/com/github/bluesbruce/spring/service/RtmpLiveService.java
  4. +120
    -0
      src/main/java/com/github/bluesbruce/spring/web/IndexController.java

+ 6
- 2
loadCmd.properties View File

@@ -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
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"



+ 16
- 1
src/main/java/com/github/bluesbruce/spring/config/CmdParam.java View File

@@ -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() {

}

+ 39
- 0
src/main/java/com/github/bluesbruce/spring/service/RtmpLiveService.java View File

@@ -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();
}
}

+ 120
- 0
src/main/java/com/github/bluesbruce/spring/web/IndexController.java View File

@@ -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<CommandTasker> list = rtmpLiveService.manager.queryAll();
Iterator<CommandTasker> 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 "失败";
}
}
}

Loading…
Cancel
Save