对接vlc
This commit is contained in:
parent
ab34fa7113
commit
731171aa6b
|
|
@ -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
|
||||
11
pom.xml
11
pom.xml
|
|
@ -199,6 +199,12 @@
|
|||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!--vlc类库-->
|
||||
<dependency>
|
||||
<groupId>uk.co.caprica</groupId>
|
||||
<artifactId>vlcj</artifactId>
|
||||
<version>4.7.0</version>
|
||||
</dependency>
|
||||
<!--devtools热部署-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
@ -206,6 +212,11 @@
|
|||
<optional>true</optional>
|
||||
<scope>true</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>uk.co.caprica</groupId>
|
||||
<artifactId>vlcj</artifactId>
|
||||
<version>3.7.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<CommandTasker> list = manager.queryAll();
|
||||
Iterator<CommandTasker> 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<CommandTasker> 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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue