This commit is contained in:
parent
e692d319c3
commit
4cb2c1c468
|
|
@ -16,6 +16,7 @@ import org.apache.logging.log4j.util.Strings;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -39,7 +40,7 @@ public class StreamRecordController {
|
|||
public Response<String> startPic(@RequestParam String streamUrl) {
|
||||
logger.info("启动视频拍照 :"+streamUrl);
|
||||
streamUrl = streamSwitch(streamUrl);
|
||||
logger.info("启动视频拍照 :"+streamUrl);
|
||||
logger.info("启动视频拍照_ :"+streamUrl);
|
||||
if(Objects.isNull(streamUrl)) {
|
||||
return Response.fail(-1);
|
||||
}
|
||||
|
|
@ -59,7 +60,7 @@ public class StreamRecordController {
|
|||
public Response<StreamTask> startRecording(@RequestParam String streamUrl) {
|
||||
logger.info("启动录制 :"+streamUrl);
|
||||
streamUrl = streamSwitch(streamUrl);
|
||||
logger.info("启动录制 :"+streamUrl);
|
||||
logger.info("启动录制_ :"+streamUrl);
|
||||
if(Objects.isNull(streamUrl)) {
|
||||
return Response.fail(-1);
|
||||
}
|
||||
|
|
@ -74,7 +75,7 @@ public class StreamRecordController {
|
|||
|
||||
logger.info("关闭录制 :"+streamUrl);
|
||||
streamUrl = streamSwitch(streamUrl);
|
||||
logger.info("关闭录制 :"+streamUrl);
|
||||
logger.info("关闭录制_ :"+streamUrl);
|
||||
if(Objects.isNull(streamUrl)) {
|
||||
return Response.fail(-1);
|
||||
}
|
||||
|
|
@ -94,7 +95,7 @@ public class StreamRecordController {
|
|||
public Response<StreamTask> getLastTask(@RequestParam String streamUrl){
|
||||
logger.info("查看录制 :"+streamUrl);
|
||||
streamUrl = streamSwitch(streamUrl);
|
||||
logger.info("查看录制 :"+streamUrl);
|
||||
logger.info("查看录制_ :"+streamUrl);
|
||||
if(Objects.isNull(streamUrl)) {
|
||||
return Response.fail(-1);
|
||||
}
|
||||
|
|
@ -142,19 +143,6 @@ public class StreamRecordController {
|
|||
return Response.success(pageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 废弃
|
||||
* @param streamUrl
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("history")
|
||||
public Response<List<Mp4Info>> streamView(@RequestParam String streamUrl){
|
||||
logger.info("查看录像历史返回 :"+ streamUrl);
|
||||
List<Mp4Info> dayMp4 = searchAll(streamUrl);
|
||||
dayMp4.sort((o1, o2) -> o2.getStartTime().compareTo(o1.getStartTime()));
|
||||
logger.info("查看录像历史返回 :"+ JSON.toJSONString(dayMp4));
|
||||
return Response.success(dayMp4) ;
|
||||
}
|
||||
|
||||
public List<Mp4Info> searchAll(String streamUrl){
|
||||
|
||||
|
|
@ -181,31 +169,25 @@ public class StreamRecordController {
|
|||
}
|
||||
|
||||
|
||||
@Value("${srs.domain}")
|
||||
private String srsdomain;
|
||||
|
||||
|
||||
/**
|
||||
* 方便测试时候使用
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("exit")
|
||||
public String exit(){
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
taskService.stopAllTask();
|
||||
Thread.sleep(10000L);
|
||||
}catch (Exception e){
|
||||
}
|
||||
System.exit(0);
|
||||
});
|
||||
return "OK";
|
||||
}
|
||||
@Value("${srs.name}")
|
||||
private String srsname;
|
||||
|
||||
public String streamSwitch(String source){
|
||||
|
||||
if(Objects.nonNull(srsdomain) && !srsdomain.isEmpty()){
|
||||
if(Objects.nonNull(source) && !source.isEmpty()){
|
||||
return dockerFix(source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(source.contains("stream.t-aaron.com")){
|
||||
return source;
|
||||
} else if (source.contains("rtmp://live.push.t-aaron.com")){
|
||||
source = source.replace("rtmp://live.push.t-aaron.com","https://live.play.t-aaron.com") ;
|
||||
source = source.replace("rtmp://live.push.t-aaron.com","http://live.play.t-aaron.com") ;
|
||||
if(source.endsWith("_")){
|
||||
source = source.substring(0,source.length()-1) + ".flv" + "_";
|
||||
}else {
|
||||
|
|
@ -213,8 +195,34 @@ public class StreamRecordController {
|
|||
}
|
||||
return source;
|
||||
}else {
|
||||
if(source.contains("https://live.play.t-aaron.com")){
|
||||
source = source.replace("https://live.play.t-aaron.com","http://live.play.t-aaron.com");
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String dockerFix(String url) {
|
||||
if (url == null || url.isEmpty()) {
|
||||
return url;
|
||||
}
|
||||
url = url.replaceFirst("^https?://", "rtmp://");
|
||||
// 删除末尾的 .flv
|
||||
url = url.replaceFirst("\\.flv$", "");
|
||||
|
||||
// 处理 RTMP URL
|
||||
if (url.startsWith("rtmp://")) {
|
||||
// 先删除端口号
|
||||
String withoutPort = url.replaceFirst("(rtmp://[^:/]+):\\d+", "$1");
|
||||
// 替换域名为 aaa
|
||||
String withNewDomain = withoutPort.replaceFirst("rtmp://[^/]+", "rtmp://"+srsname);
|
||||
// 删除 .flv 后缀
|
||||
return withNewDomain.replaceFirst("\\.flv$", "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
|
@ -60,6 +57,7 @@ public class ProcessService {
|
|||
loggingService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
logger.info("mergeMp4 process Start {}",command);
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()))) {
|
||||
String line;
|
||||
|
|
@ -79,16 +77,40 @@ public class ProcessService {
|
|||
|
||||
CompletableFuture<Process> future = process.onExit();
|
||||
// 阻塞等待进程结束
|
||||
Process completedProcess = future.get();
|
||||
Process completedProcess = null;
|
||||
try {
|
||||
completedProcess = future.get(4, TimeUnit.SECONDS);
|
||||
logger.info("mergeMp4正常完成-------- Over");
|
||||
}catch (Exception e) {
|
||||
String fileName = recordPath+ File.separator +
|
||||
flvRecord.getStream().getDayRecord().getDay() + File.separator +
|
||||
flvRecord.getStream().getStreamId() + File.separator +flvRecord.getStartTime() + ".mp4";
|
||||
File file = new File(fileName);
|
||||
if(file.exists()){
|
||||
logger.info("mergeMp4超时4S完成-------- Over",e);
|
||||
process.destroy();
|
||||
} else {
|
||||
try {
|
||||
completedProcess = future.get(4, TimeUnit.SECONDS);
|
||||
}catch (Exception e1) {
|
||||
if(file.exists()){
|
||||
logger.info("mergeMp4超时8S完成-------- Over",e);
|
||||
process.destroy();
|
||||
}else {
|
||||
logger.info("mergeMp4超时8S未完成-------- Over",e);
|
||||
process.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查进程是否成功结束
|
||||
if (completedProcess.exitValue() == 0) {
|
||||
logger.info("进程成功结束!");
|
||||
/**
|
||||
* 删除数据
|
||||
*/
|
||||
} else {
|
||||
logger.info("进程失败,退出码 {} " ,completedProcess.exitValue());
|
||||
if(Objects.nonNull(completedProcess)) {
|
||||
// 检查进程是否成功结束
|
||||
if (completedProcess.exitValue() == 0) {
|
||||
logger.info("进程成功结束!");
|
||||
} else {
|
||||
logger.info("进程失败,退出码 {} " ,completedProcess.exitValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
#公司环境
|
||||
spring.application.name=stream_server
|
||||
server.port = 9011
|
||||
srs.splitPath=/data/java/srs/stream_server/temp
|
||||
srs.targetPath=/data/java/srs/srs/trunk/objs/nginx/html/recording
|
||||
ffmpeg=ffmpeg
|
||||
recordPath=/data/java/srs/srs/trunk/objs/nginx/html/record
|
||||
livedates=8
|
||||
cangneiwai=false
|
||||
#spring.application.name=stream_server
|
||||
#server.port = 9011
|
||||
#srs.splitPath=/data/java/srs/stream_server/temp
|
||||
#srs.targetPath=/data/java/srs/srs/trunk/objs/nginx/html/recording
|
||||
#ffmpeg=ffmpeg
|
||||
#recordPath=/data/java/srs/srs/trunk/objs/nginx/html/record
|
||||
#livedates=8
|
||||
#cangneiwai=false
|
||||
#srs.domain = ""
|
||||
#srs.name = ""
|
||||
|
||||
#大数据局
|
||||
#spring.application.name=stream_server
|
||||
|
|
@ -17,6 +19,8 @@ cangneiwai=false
|
|||
#recordPath=/data/java/srs/srs/trunk/objs/nginx/html/record
|
||||
#livedates=8
|
||||
#cangneiwai=true
|
||||
#srs.domain = ""
|
||||
#srs.name = ""
|
||||
|
||||
#本地测试
|
||||
#spring.application.name=stream_server
|
||||
|
|
@ -26,4 +30,23 @@ cangneiwai=false
|
|||
#ffmpeg=ffmpeg
|
||||
#recordPath=/Users/sunpeng/workspace/stream/record
|
||||
#livedates=7
|
||||
#cangneiwai=false
|
||||
#cangneiwai=false
|
||||
#srs.domain = ""
|
||||
#srs.name = ""
|
||||
|
||||
#容器化部署
|
||||
#通过注入
|
||||
srs.domain = STREAM.t-aaron.com
|
||||
#通过注入
|
||||
srs.name = STREAM
|
||||
spring.application.name=stream_server
|
||||
server.port = 8080
|
||||
#零时文件
|
||||
srs.splitPath=/data/temp
|
||||
#拍照 + 录像
|
||||
srs.targetPath=/data/recording
|
||||
ffmpeg=ffmpeg
|
||||
#
|
||||
recordPath=/data/record
|
||||
livedates=8
|
||||
cangneiwai=false
|
||||
Loading…
Reference in New Issue