From e692d319c390fb50baf89a03fe3becca571bc136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B0=8F=E4=BA=91?= Date: Sat, 26 Apr 2025 16:50:35 +0800 Subject: [PATCH] xx --- logs/app.log | 59 ------------------- pid.txt | 1 - .../controller/StreamRecordController.java | 38 +++++++++++- .../tuoheng/steam/service/TaskService.java | 22 +++---- .../service/innerService/ProcessService.java | 5 +- .../java/com/tuoheng/steam/util/FileUtil.java | 19 ++++-- src/main/resources/application.properties | 27 +++++---- 7 files changed, 77 insertions(+), 94 deletions(-) delete mode 100644 logs/app.log diff --git a/logs/app.log b/logs/app.log deleted file mode 100644 index bb14502..0000000 --- a/logs/app.log +++ /dev/null @@ -1,59 +0,0 @@ -2025-04-19 13:21:49.922 [main] INFO com.tuoheng.steam.StreamApplication - Starting StreamApplication using Java 11.0.25 on sunpengdeMacBook-Pro.local with PID 12739 (/Users/sunpeng/workspace/ideaproject/stream_server/target/classes started by sunpeng in /Users/sunpeng/workspace/ideaproject/stream_server) -2025-04-19 13:21:49.923 [main] INFO com.tuoheng.steam.StreamApplication - No active profile set, falling back to 1 default profile: "default" -2025-04-19 13:21:50.252 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 9011 (http) -2025-04-19 13:21:50.255 [main] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-9011"] -2025-04-19 13:21:50.255 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat] -2025-04-19 13:21:50.255 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.83] -2025-04-19 13:21:50.290 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext -2025-04-19 13:21:50.291 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 350 ms -2025-04-19 13:21:50.447 [main] INFO o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-9011"] -2025-04-19 13:21:50.465 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 9011 (http) with context path '' -2025-04-19 13:21:50.472 [main] INFO com.tuoheng.steam.StreamApplication - Started StreamApplication in 0.757 seconds (JVM running for 1.236) -2025-04-19 13:21:56.475 [scheduling-1] INFO com.tuoheng.steam.schedule.Scheduler - 舱内外无需录制 -2025-04-19 13:22:21.580 [main] INFO com.tuoheng.steam.StreamApplication - Starting StreamApplication using Java 11.0.25 on sunpengdeMacBook-Pro.local with PID 12750 (/Users/sunpeng/workspace/ideaproject/stream_server/target/classes started by sunpeng in /Users/sunpeng/workspace/ideaproject/stream_server) -2025-04-19 13:22:21.581 [main] INFO com.tuoheng.steam.StreamApplication - No active profile set, falling back to 1 default profile: "default" -2025-04-19 13:22:21.909 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 9011 (http) -2025-04-19 13:22:21.912 [main] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-9011"] -2025-04-19 13:22:21.913 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat] -2025-04-19 13:22:21.913 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.83] -2025-04-19 13:22:21.953 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext -2025-04-19 13:22:21.953 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 354 ms -2025-04-19 13:22:22.115 [main] INFO o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-9011"] -2025-04-19 13:22:22.132 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 9011 (http) with context path '' -2025-04-19 13:22:22.140 [main] INFO com.tuoheng.steam.StreamApplication - Started StreamApplication in 0.767 seconds (JVM running for 1.254) -2025-04-19 13:22:28.140 [scheduling-1] INFO com.tuoheng.steam.schedule.Scheduler - 舱内外无需录制 -2025-04-19 13:30:19.451 [main] INFO com.tuoheng.steam.StreamApplication - Starting StreamApplication using Java 11.0.25 on sunpengdeMacBook-Pro.local with PID 12998 (/Users/sunpeng/workspace/ideaproject/stream_server/target/classes started by sunpeng in /Users/sunpeng/workspace/ideaproject/stream_server) -2025-04-19 13:30:19.452 [main] INFO com.tuoheng.steam.StreamApplication - No active profile set, falling back to 1 default profile: "default" -2025-04-19 13:30:19.790 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 9011 (http) -2025-04-19 13:30:19.794 [main] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-9011"] -2025-04-19 13:30:19.794 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat] -2025-04-19 13:30:19.794 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.83] -2025-04-19 13:30:19.832 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext -2025-04-19 13:30:19.832 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 361 ms -2025-04-19 13:30:19.990 [main] INFO o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-9011"] -2025-04-19 13:30:20.008 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 9011 (http) with context path '' -2025-04-19 13:30:20.015 [main] INFO com.tuoheng.steam.StreamApplication - Started StreamApplication in 0.768 seconds (JVM running for 1.252) -2025-04-19 13:30:26.018 [scheduling-1] INFO com.tuoheng.steam.schedule.Scheduler - 舱内外无需录制 -2025-04-19 14:05:16.707 [main] INFO com.tuoheng.steam.StreamApplication - Starting StreamApplication using Java 11.0.25 on sunpengdeMacBook-Pro.local with PID 13714 (/Users/sunpeng/workspace/ideaproject/stream_server/target/classes started by sunpeng in /Users/sunpeng/workspace/ideaproject/stream_server) -2025-04-19 14:05:16.709 [main] INFO com.tuoheng.steam.StreamApplication - No active profile set, falling back to 1 default profile: "default" -2025-04-19 14:05:17.074 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 9011 (http) -2025-04-19 14:05:17.078 [main] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-9011"] -2025-04-19 14:05:17.078 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat] -2025-04-19 14:05:17.078 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.83] -2025-04-19 14:05:17.118 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext -2025-04-19 14:05:17.118 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 389 ms -2025-04-19 14:05:17.284 [main] INFO o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-9011"] -2025-04-19 14:05:17.302 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 9011 (http) with context path '' -2025-04-19 14:05:17.310 [main] INFO com.tuoheng.steam.StreamApplication - Started StreamApplication in 0.831 seconds (JVM running for 1.34) -2025-04-19 14:05:23.309 [scheduling-1] INFO com.tuoheng.steam.schedule.Scheduler - 舱内外无需录制 -2025-04-19 14:06:08.792 [http-nio-9011-exec-1] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring DispatcherServlet 'dispatcherServlet' -2025-04-19 14:06:08.792 [http-nio-9011-exec-1] INFO o.s.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcherServlet' -2025-04-19 14:06:08.792 [http-nio-9011-exec-1] INFO o.s.web.servlet.DispatcherServlet - Completed initialization in 0 ms -2025-04-19 14:06:11.948 [http-nio-9011-exec-1] INFO c.t.s.c.StreamRecordController - 启动录制 :rtmp://stream.t-aaron.com/live/livestream -2025-04-19 14:06:11.949 [http-nio-9011-exec-1] INFO c.tuoheng.steam.service.TaskService - streamUrl rtmp://stream.t-aaron.com/live/livestream startTask 1 -2025-04-19 14:06:11.951 [http-nio-9011-exec-1] INFO c.t.s.s.innerService.ProcessService - recordStream ffmpeg -i rtmp://stream.t-aaron.com/live/livestream -c copy -f mpegts -reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 2 /data/java/srs/stream_server/temp/59795526-a0eb-44ff-9fab-e0919abbbe36.ts -2025-04-19 14:06:11.970 [http-nio-9011-exec-1] INFO c.tuoheng.steam.service.TaskService - streamUrl rtmp://stream.t-aaron.com/live/livestream taskId 1 startProcess 13724 -2025-04-19 14:06:11.995 [ForkJoinPool.commonPool-worker-19] INFO c.tuoheng.steam.service.TaskService - streamUrl rtmp://stream.t-aaron.com/live/livestream taskId 1 Process 13724 Over -2025-04-19 14:06:11.995 [ForkJoinPool.commonPool-worker-19] INFO c.t.s.s.innerService.ProcessService - recordStream ffmpeg -i rtmp://stream.t-aaron.com/live/livestream -c copy -f mpegts -reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 2 /data/java/srs/stream_server/temp/247afde2-70b3-4951-b3b0-85fd02d99045.ts -2025-04-19 14:06:12.000 [ForkJoinPool.commonPool-worker-19] INFO c.tuoheng.steam.service.TaskService - streamUrl rtmp://stream.t-aaron.com/live/livestream taskId 1 startProcess 13725 -2025-04-19 14:06:12.023 [http-nio-9011-exec-1] INFO c.t.s.c.StreamRecordController - 启动录制返回 :{"code":200,"data":{"startTime":"2025-04-19 14:06:11.948","strStartTime":"2025-04-19 14:06:11","streamProcesses":[{"createTime":"2025-04-19 14:06:11.969","fileName":"/data/java/srs/stream_server/temp/59795526-a0eb-44ff-9fab-e0919abbbe36.ts","innerProcessId":13724,"processType":"RECORD","stopTime":"2025-04-19 14:06:11"},{"createTime":"2025-04-19 14:06:11.999","fileName":"/data/java/srs/stream_server/temp/247afde2-70b3-4951-b3b0-85fd02d99045.ts","innerProcessId":13725,"processType":"RECORD"}],"streamUrl":"rtmp://stream.t-aaron.com/live/livestream","taskId":1}} diff --git a/pid.txt b/pid.txt index 49f1deb..e69de29 100644 --- a/pid.txt +++ b/pid.txt @@ -1 +0,0 @@ -13725=2025-04-19 14:06:11 diff --git a/src/main/java/com/tuoheng/steam/controller/StreamRecordController.java b/src/main/java/com/tuoheng/steam/controller/StreamRecordController.java index 36fa8cb..c983caa 100644 --- a/src/main/java/com/tuoheng/steam/controller/StreamRecordController.java +++ b/src/main/java/com/tuoheng/steam/controller/StreamRecordController.java @@ -37,6 +37,8 @@ public class StreamRecordController { @GetMapping("pic") public Response startPic(@RequestParam String streamUrl) { + logger.info("启动视频拍照 :"+streamUrl); + streamUrl = streamSwitch(streamUrl); logger.info("启动视频拍照 :"+streamUrl); if(Objects.isNull(streamUrl)) { return Response.fail(-1); @@ -55,6 +57,8 @@ public class StreamRecordController { @GetMapping("start") public Response startRecording(@RequestParam String streamUrl) { + logger.info("启动录制 :"+streamUrl); + streamUrl = streamSwitch(streamUrl); logger.info("启动录制 :"+streamUrl); if(Objects.isNull(streamUrl)) { return Response.fail(-1); @@ -68,6 +72,8 @@ public class StreamRecordController { @GetMapping("stop") public Response stopRecording(@RequestParam String streamUrl){ + logger.info("关闭录制 :"+streamUrl); + streamUrl = streamSwitch(streamUrl); logger.info("关闭录制 :"+streamUrl); if(Objects.isNull(streamUrl)) { return Response.fail(-1); @@ -86,7 +92,8 @@ public class StreamRecordController { @GetMapping("info") public Response getLastTask(@RequestParam String streamUrl){ - + logger.info("查看录制 :"+streamUrl); + streamUrl = streamSwitch(streamUrl); logger.info("查看录制 :"+streamUrl); if(Objects.isNull(streamUrl)) { return Response.fail(-1); @@ -97,10 +104,14 @@ public class StreamRecordController { } + /** + * 废弃 + * @param request + * @return + */ @PostMapping("search") public Response> streamView(@RequestBody PageStreamRequest request){ logger.info("查看录制 search :"+JSON.toJSONString(request)); - if(Objects.isNull(request.getPageIndex()) || Objects.isNull(request.getPageSize()) || request.getPageIndex() <0 || request.getPageSize() <=0 ){ logger.error("查看录制 search 入参错误!"); @@ -131,6 +142,11 @@ public class StreamRecordController { return Response.success(pageInfo); } + /** + * 废弃 + * @param streamUrl + * @return + */ @GetMapping("history") public Response> streamView(@RequestParam String streamUrl){ logger.info("查看录像历史返回 :"+ streamUrl); @@ -183,4 +199,22 @@ public class StreamRecordController { }); return "OK"; } + + public String streamSwitch(String 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") ; + if(source.endsWith("_")){ + source = source.substring(0,source.length()-1) + ".flv" + "_"; + }else { + source = source + ".flv"; + } + return source; + }else { + return source; + } + + } } diff --git a/src/main/java/com/tuoheng/steam/service/TaskService.java b/src/main/java/com/tuoheng/steam/service/TaskService.java index 69b303e..5c13eec 100644 --- a/src/main/java/com/tuoheng/steam/service/TaskService.java +++ b/src/main/java/com/tuoheng/steam/service/TaskService.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON; import com.tuoheng.steam.dos.StreamProcess; import com.tuoheng.steam.dos.StreamTask; import com.tuoheng.steam.service.innerService.ProcessService; +import com.tuoheng.steam.util.FileUtil; import com.tuoheng.steam.util.ProcessManager; import com.tuoheng.steam.util.TimeUtils; import org.slf4j.Logger; @@ -108,9 +109,8 @@ public class TaskService implements ITaskService{ for (StreamProcess process : streamProcesses) { process.destroy(); File file = new File(process.getFileName()); - if(file.exists()){ - file.delete(); - } + FileUtil.deleteFile(file); + } } @@ -220,9 +220,7 @@ public class TaskService implements ITaskService{ ProcessManager.unRegisterProcess(mergeProcess.getInnerProcessId()); for(StreamProcess streamProcess :currentStreamTask.getStreamProcesses()){ File file = new File(streamProcess.getFileName()); - if(file.exists()){ - file.delete(); - } + FileUtil.deleteFile(file); } }).exceptionally(ex -> { logger.error("streamUrl {} taskId {} MergeProcess {} exceptionally", streamUrl,currentStreamTask.getTaskId(), mergeProcess.getInnerProcessId(), ex); @@ -230,9 +228,7 @@ public class TaskService implements ITaskService{ ProcessManager.unRegisterProcess(mergeProcess.getInnerProcessId()); for(StreamProcess streamProcess :currentStreamTask.getStreamProcesses()){ File file = new File(streamProcess.getFileName()); - if(file.exists()){ - file.delete(); - } + FileUtil.deleteFile(file); } return null; }); @@ -338,8 +334,14 @@ public class TaskService implements ITaskService{ future.thenRun(() -> { logger.info("streamUrl {} taskId {} Process {} Over", streamUrl, streamTask.getTaskId(),streamProcess.getInnerProcessId()); streamProcess.setStopTime(TimeUtils.formatDateToString(new Date())); - startTask(streamUrl, streamTask); ProcessManager.unRegisterProcess(streamProcess.getInnerProcessId()); + try { + Thread.sleep(2000L); + } catch (Exception ignored){} + if(!new File(streamProcess.getFileName()).exists()){ + streamTask.getStreamProcesses().remove(streamProcess); + } + startTask(streamUrl, streamTask); }).exceptionally(ex -> { logger.info("streamUrl {} taskId {} Process {} Exceptionally", streamUrl, streamTask.getTaskId(),streamProcess.getInnerProcessId(),ex); streamProcess.setStopTime(TimeUtils.formatDateToString(new Date())); diff --git a/src/main/java/com/tuoheng/steam/service/innerService/ProcessService.java b/src/main/java/com/tuoheng/steam/service/innerService/ProcessService.java index fe04c50..c29eed7 100644 --- a/src/main/java/com/tuoheng/steam/service/innerService/ProcessService.java +++ b/src/main/java/com/tuoheng/steam/service/innerService/ProcessService.java @@ -3,6 +3,7 @@ package com.tuoheng.steam.service.innerService; import com.tuoheng.steam.dos.StreamProcess; import com.tuoheng.steam.dos.ProcessType; import com.tuoheng.steam.service.dos.FlvRecord; +import com.tuoheng.steam.util.FileUtil; import com.tuoheng.steam.util.ProcessManager; import com.tuoheng.steam.util.TimeUtils; import org.slf4j.Logger; @@ -72,9 +73,7 @@ public class ProcessService { File delete = new File(recordPath+ File.separator + flvRecord.getStream().getDayRecord().getDay() + File.separator + flvRecord.getStream().getStreamId() + File.separator + flvRecord.getFlv()); - if(delete.exists()){ - delete.delete(); - } + FileUtil.deleteFile(delete); } }); diff --git a/src/main/java/com/tuoheng/steam/util/FileUtil.java b/src/main/java/com/tuoheng/steam/util/FileUtil.java index 346e43c..c74c11c 100644 --- a/src/main/java/com/tuoheng/steam/util/FileUtil.java +++ b/src/main/java/com/tuoheng/steam/util/FileUtil.java @@ -13,12 +13,23 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import java.util.stream.Stream; public class FileUtil { private static final Logger logger = LoggerFactory.getLogger(FileUtil.class); + private static ScheduledExecutorService executor = Executors.newScheduledThreadPool(4); + + public static void deleteFile(File file) { + if(file.exists()) { + file.delete(); + } + } + public static void deleteFolder(String stringPath) { try { @@ -37,8 +48,8 @@ public class FileUtil { } else { logger.info("文件夹不存在: " + path); } - }catch (Exception e){ - e.printStackTrace(); + }catch (Exception e) { + logger.error("deleteFolder",e); } } @@ -58,11 +69,7 @@ public class FileUtil { for (File file : files) { list.add(file.getName()); } - } else { - } - } else { - } return list; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 39962c5..a4cb438 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,22 +1,22 @@ #公司环境 +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 +#server.port = 8989 #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 = 8989 -srs.splitPath=/data/java/srs/stream_server/temp -srs.targetPath=/data/java/srs/srs/trunk/objs/nginx/html -ffmpeg=ffmpeg -recordPath=/data/java/srs/srs/trunk/objs/nginx/html/record -livedates=8 -cangneiwai=true +#cangneiwai=true #本地测试 #spring.application.name=stream_server @@ -25,4 +25,5 @@ cangneiwai=true #srs.targetPath=/Users/sunpeng/workspace/stream/html #ffmpeg=ffmpeg #recordPath=/Users/sunpeng/workspace/stream/record -#livedates=7 \ No newline at end of file +#livedates=7 +#cangneiwai=false \ No newline at end of file