diff --git a/loadCmd.properties b/loadCmd.properties
index c089a05..defc5d6 100644
--- a/loadCmd.properties
+++ b/loadCmd.properties
@@ -1,22 +1,24 @@
#推流地址(eg:阿里云地址)
pushUrl=rtmp://192.168.10.101:19350/rlive/stream_11?sign=rHtBg3sz
#拉流地址(eg:吊舱拉流的地址)
-#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
+#playUrl=http://192.168.10.101:18000/flv/live/34020000001110000002_34020000001320000071_0200000071.flv
+playUrl=rtsp://admin:HuaWei123@218.94.150.122:554/LiveMedia/ch1/Media10
#固定通道 1 获取通道 2 多线程双路 3 单线程多路 4
-type=0
+type=1
mqttUrl=tcp://106.15.120.154
#主题 12345替换对应机场编号 004替换控制板id
mqttTopic=/v1/12345936/rtmp/live,v1/004/confirm/DroneBMS
#推流时长(毫秒)1000表示1秒
-time=600000
+time=30000
#多路推流(选配)
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
#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"
-
-
+#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"
+# ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
+cmd=ffmpeg -i http://192.168.10.101:18000/flv/live/34020000001110000002_34020000001320000071_0200000071.flv -c:a copy -flags:v +global_header -bsf:v dump_extra -f flv rtmp://192.168.10.101:19350/rlive/stream_11?sign=rHtBg3sz
+vlc=on
+vlcUrl=Z:\\soft\\vlc
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 9bb2ded..7dbe7ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -199,6 +199,12 @@
true
+
+
+ uk.co.caprica
+ vlcj
+ 4.7.0
+
org.springframework.boot
@@ -206,6 +212,11 @@
true
true
+
+ uk.co.caprica
+ vlcj
+ 3.7.0
+
diff --git a/src/main/java/com/github/bluesbruce/spring/Application.java b/src/main/java/com/github/bluesbruce/spring/Application.java
index 1fb0a91..077bffc 100644
--- a/src/main/java/com/github/bluesbruce/spring/Application.java
+++ b/src/main/java/com/github/bluesbruce/spring/Application.java
@@ -23,7 +23,8 @@ import static com.github.bluesbruce.ffch.util.PropertiesUtil.load;
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
- SpringApplication.run(Application.class, args);
+ SpringApplicationBuilder builder = new SpringApplicationBuilder(Application.class);
+ builder.headless(false).run(args);
}
@Profile(value = {"war"})
@Override
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 21df0b0..30ba1e9 100644
--- a/src/main/java/com/github/bluesbruce/spring/config/CmdParam.java
+++ b/src/main/java/com/github/bluesbruce/spring/config/CmdParam.java
@@ -8,6 +8,25 @@ public class CmdParam {
private int type;//1 鍥哄畾閫氶亾 2 閫氶亾鏈嶅姟
String mqttUrl;
int time;
+ String vlc;
+ String vlcUrl;
+
+ public String getVlcUrl() {
+ return vlcUrl;
+ }
+
+ public void setVlcUrl(String vlcUrl) {
+ this.vlcUrl = vlcUrl;
+ }
+
+ public String getVlc() {
+ return vlc;
+ }
+
+ public void setVlc(String vlc) {
+ this.vlc = vlc;
+ }
+
//ffmpeg 鎸囦护
private String cmd;
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 9d804f7..40a5c76 100644
--- a/src/main/java/com/github/bluesbruce/spring/service/RtmpLiveService.java
+++ b/src/main/java/com/github/bluesbruce/spring/service/RtmpLiveService.java
@@ -66,13 +66,16 @@ public class RtmpLiveService {
});
thread.start();
status=1;
+ String pushUrl = cmdParam.getPushUrl();
+ String playUrl=cmdParam.getPlayUrl();
+ if (cmdParam.getVlc()!=null&&cmdParam.getVlc().equals("on")) {
+ playUrl = VLCJ.startVlcj(playUrl,cmdParam.getVlcUrl());
+ }
//Thread.sleep(5000);
- String pushUrl = "";
if (cmdParam.getType() == 0){
log.info("浣跨敤鎸囦护鎺ㄦ祦");
runRtmpByCmd(cmdParam.getCmd());
- }else
- if (cmdParam.getType() == 2) {
+ }else if (cmdParam.getType() == 2) {
log.info("鑾峰彇娴佸獟浣撻氶亾");
//TODO 鑾峰彇閫氶亾鏈嶅姟鎺ㄦ媺娴佸湴鍧
JSONObject object = getChenl();
@@ -88,21 +91,22 @@ public class RtmpLiveService {
mqttProviderConfig.publish(2, false, reTopic, object.toJSONString());
return;
}
- runRtmp(pushUrl, cmdParam.getPlayUrl(), code);
+ runRtmp(pushUrl, playUrl, code);
//TODO end
} else if (cmdParam.getType() == 1) {
log.info("浣跨敤鍥哄畾娴佸獟浣撻氶亾");
pushUrl = cmdParam.getPushUrl();
- runRtmp(pushUrl, cmdParam.getPlayUrl(), code);
+ runRtmp(pushUrl, playUrl, code);
} else if (cmdParam.getType() == 3) {
- runRtmp2to2(cmdParam.getPlayUrl());
+ runRtmp2to2(playUrl);
} else if (cmdParam.getType() == 4) {
- runRtmp1to2(cmdParam.getPlayUrl());
+ runRtmp1to2(playUrl);
}
/*status=0;
DefaultOutHandlerMethod.outIdMap=new HashMap();*/
}
+
private void runRtmp2to2(String playUrl) throws InterruptedException {
try {
String reTopic = cmdParam.getMqttTopic().replace("live", "result");
@@ -238,7 +242,7 @@ public class RtmpLiveService {
log.info("鑾峰彇鎾祦鍦板潃锛歿}");
//CommandManager manager = new CommandManagerImpl();
String taskId = manager.start("push1", CommandBuidlerFactory.createBuidler()
- .add("ffmpeg").add("-rtsp_transport", "tcp")
+ .add("ffmpeg -re")/*.add("-rtsp_transport", "tcp")*/
.add("-i", playUrl)
.add("-vcodec", "copy")
/*.add("-acodec", "copy")*/
@@ -277,41 +281,10 @@ public class RtmpLiveService {
//ds.close();
}
- /*private void checkMsg1() throws InterruptedException {
- long oldtime = System.currentTimeMillis();
- String oldMsg = "";
- while (true) {
- String msg = OutHandler.outMsg==null?"":OutHandler.outMsg;
- if (!msg.equals(oldMsg)) {
- oldMsg=msg;
- oldtime=System.currentTimeMillis();
- }
- log.info("娑堟伅杈撳嚭{},鐘舵亄}",msg,status);
- if (System.currentTimeMillis()-oldtime>15000&&msg.equals(oldMsg)&&status==1){
- //log.info("娑堟伅鏈緭鍑簕}",msg);
- if(manager.queryAll().size()>0){
- Collection list = manager.queryAll();
- Iterator commandTaskerIterator = list.iterator();
- CommandTasker s = commandTaskerIterator.next();
- log.info("0000{},{}",s.getId(),s.getCommand());
- log.info("浠诲姟娑堟伅鏈緭鍑",s);
- manager.stop(s.getId());
- Thread.sleep(2000);
- String result= manager.start(s.getId(),s.getCommand().split("bin/")[1]);
- if (!StringUtils.isNullOrEmpty(result)){
- oldtime= System.currentTimeMillis();
- }else{
- log.info("鎺ㄦ祦澶辫触锛岄噸鏂版帹娴");
- }
- };
- }
- if (status==0){
- break;
- }
- Thread.sleep(200);
- }
- }*/
private void checkMsg() throws InterruptedException {
+ //鎺ㄦ祦璧峰鏃堕棿
+ long cmdtime = System.currentTimeMillis();
+ //娑堟伅鏇存柊鏃堕棿
long oldtime = System.currentTimeMillis();
String oldMsg = "";
long oldtime2 = System.currentTimeMillis();
@@ -353,7 +326,7 @@ public class RtmpLiveService {
log.info("鏃犱换鍔★紝鍋滄鐩戝惉1");
break;
}
- if (status==0&&manager.queryAll().size()==0){
+ if ((status==0&&manager.queryAll().size()==0)){
log.info("鏃犱换鍔★紝鍋滄鐩戝惉2");
Thread.sleep(5000);
if (manager.queryAll().size()>0){
@@ -363,6 +336,15 @@ public class RtmpLiveService {
}
break;
}
+ /*if (System.currentTimeMillis()-cmdtime>cmdParam.getTime()){
+ log.info("鎺ㄦ祦鏃堕棿瓒呮椂");
+ if (manager.queryAll().size()>0){
+ log.info("寤惰繜妫娴嬫帹娴佸叧闂");
+ manager.stopAll();
+ manager.destory();
+ break;
+ }
+ }*/
Thread.sleep(400);
}
}
@@ -379,6 +361,7 @@ public class RtmpLiveService {
Iterator commandTaskerIterator = list.iterator();*/
CommandTasker s = manager.query(id);
if (!ObjectUtils.isEmpty(s)) {
+ checkVlc(cmdParam.getPlayUrl());
log.info("0000{},{}", s.getId(), s.getCommand());
log.info("浠诲姟娑堟伅鏈緭鍑,閲嶆柊鎺ㄦ祦", s);
manager.stop(s.getId());
@@ -397,6 +380,20 @@ public class RtmpLiveService {
return map;
}
+ private void checkVlc(String playUrl) {
+ if (cmdParam.getVlc().equals("on")) {
+ if (VLCJ.vlcStatus!=3||VLCJ.buffstatus<0){
+ try {
+ VLCJ.startVlcj(playUrl,cmdParam.getVlcUrl());
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ //System.out.println(VLCJ.mediaPlayerComponent.getMediaPlayer().getMediaMeta().getTrackNumber());
+ //VLCJ.mediaPlayerComponent.getMediaPlayer().getMediaState();
+ }
+ }
+
public void stopRtmp() {
try {
status=0;
@@ -421,6 +418,9 @@ public class RtmpLiveService {
returnChenl();
mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString());
}
+ if (!ObjectUtils.isEmpty(VLCJ.mediaPlayerComponent)){
+ VLCJ.stopVlcj();
+ }
} catch (Exception e) {
log.error("", e);
}