Compare commits

...

3 Commits

Author SHA1 Message Date
孙小云 613d6d3dc5 大数据 2025-04-23 11:56:18 +08:00
孙小云 4ca3c73323 xx 2025-04-19 11:35:37 +08:00
孙小云 d65aaaf4b6 修改配置文件 2025-04-14 09:53:59 +08:00
11 changed files with 166 additions and 62 deletions

59
logs/app.log Normal file
View File

@ -0,0 +1,59 @@
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}}

View File

@ -0,0 +1 @@
13725=2025-04-19 14:06:11

16
pom.xml
View File

@ -35,11 +35,6 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.minio</groupId>
@ -51,7 +46,18 @@
<artifactId>fastjson2</artifactId>
<version>2.0.53</version>
</dependency>
<!-- SkyWalking 工具包Logback 支持) -->
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-logback-1.x</artifactId>
<version>8.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-trace</artifactId>
<version>8.6.0</version>
</dependency>

View File

@ -37,7 +37,7 @@ public class StreamRecordController {
@GetMapping("pic")
public Response<String> startPic(@RequestParam String streamUrl) {
System.out.println("启动视频拍照 :"+streamUrl);
logger.info("启动视频拍照 :"+streamUrl);
if(Objects.isNull(streamUrl)) {
return Response.fail(-1);
}
@ -55,20 +55,20 @@ public class StreamRecordController {
@GetMapping("start")
public Response<StreamTask> startRecording(@RequestParam String streamUrl) {
System.out.println("启动录制 :"+streamUrl);
logger.info("启动录制 :"+streamUrl);
if(Objects.isNull(streamUrl)) {
return Response.fail(-1);
}
Response<StreamTask> response = Response.success(taskService.startTask(streamUrl));
System.out.println("启动录制返回 :"+ JSON.toJSONString(response));
logger.info("启动录制返回 :"+ JSON.toJSONString(response));
return response;
}
@GetMapping("stop")
public Response<StreamTask> stopRecording(@RequestParam String streamUrl){
System.out.println("关闭录制 :"+streamUrl);
logger.info("关闭录制 :"+streamUrl);
if(Objects.isNull(streamUrl)) {
return Response.fail(-1);
}
@ -77,7 +77,7 @@ public class StreamRecordController {
if(Objects.isNull(response.getData()) || Objects.isNull(response.getData().getOutFileName()) || response.getData().getOutFileName().isEmpty()){
response.setCode(500);
}
System.out.println("关闭录制返回 :"+ JSON.toJSONString(response));
logger.info("关闭录制返回 :"+ JSON.toJSONString(response));
return response;
}catch (Exception e){
return Response.fail(-1);
@ -87,23 +87,23 @@ public class StreamRecordController {
@GetMapping("info")
public Response<StreamTask> getLastTask(@RequestParam String streamUrl){
System.out.println("查看录制 :"+streamUrl);
logger.info("查看录制 :"+streamUrl);
if(Objects.isNull(streamUrl)) {
return Response.fail(-1);
}
Response<StreamTask> response = Response.success(taskService.getLastTask(streamUrl));
System.out.println("查看录制返回 :"+ JSON.toJSONString(response));
logger.info("查看录制返回 :"+ JSON.toJSONString(response));
return response;
}
@PostMapping("search")
public Response<PageInfo<Mp4Info>> streamView(@RequestBody PageStreamRequest request){
System.out.println("查看录制 search :"+JSON.toJSONString(request));
logger.info("查看录制 search :"+JSON.toJSONString(request));
if(Objects.isNull(request.getPageIndex()) || Objects.isNull(request.getPageSize())
|| request.getPageIndex() <0 || request.getPageSize() <=0 ){
System.out.println("查看录制 search 入参错误!");
logger.error("查看录制 search 入参错误!");
return Response.fail(-100);
}
@ -127,16 +127,16 @@ public class StreamRecordController {
*/
mp4s.sort((o1, o2) -> o2.getStartTime().compareTo(o1.getStartTime()));
PageInfo<Mp4Info> pageInfo = new PageInfo<>(mp4s,request.getPageIndex(),request.getPageSize());
System.out.println("查看录制 search 返回:"+JSON.toJSONString(request));
logger.info("查看录制 search 返回:"+JSON.toJSONString(request));
return Response.success(pageInfo);
}
@GetMapping("history")
public Response<List<Mp4Info>> streamView(@RequestParam String streamUrl){
System.out.println("查看录像历史返回 :"+ streamUrl);
logger.info("查看录像历史返回 :"+ streamUrl);
List<Mp4Info> dayMp4 = searchAll(streamUrl);
dayMp4.sort((o1, o2) -> o2.getStartTime().compareTo(o1.getStartTime()));
System.out.println("查看录像历史返回 :"+ JSON.toJSONString(dayMp4));
logger.info("查看录像历史返回 :"+ JSON.toJSONString(dayMp4));
return Response.success(dayMp4) ;
}

View File

@ -27,13 +27,21 @@ public class Scheduler {
@Value("${livedates}")
private Integer livedates;
@Value("${cangneiwai}")
private Boolean cangneiwai;
/**
* 初次执行延迟6秒执行
* 每隔 60 分钟执行一次 60*60*1000
*/
@Scheduled(fixedRate = 3600000, initialDelay = 6000)
public void mergeTask() {
System.out.println("开始FLV到MP4的转换 - " + System.currentTimeMillis() / 1000);
if(!cangneiwai){
logger.info("舱内外无需录制");
return;
}
logger.info("开始FLV到MP4的转换 - " + System.currentTimeMillis() / 1000);
List<DayRecord> dayRecords = iRecordService.findDaysPath();
for (int index = 0; index < dayRecords.size(); index++) {

View File

@ -248,18 +248,18 @@ public class TaskService implements ITaskService{
@Override
public void run() {
try {
System.out.println("FileName :"+currentStreamTask.getMergeProcess().getFileName());
logger.info("FileName :"+currentStreamTask.getMergeProcess().getFileName());
Process process = Runtime.getRuntime().exec(ffmpeg + " -i " +
currentStreamTask.getMergeProcess().getFileName());
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println("Duration line: " + line);
logger.info("Duration line: " + line);
if (line.contains("Duration")) {
String duration = line.split("Duration: ")[1].split(",")[0];
System.out.println("Duration: " + duration.substring(0, 8));
logger.info("Duration: " + duration.substring(0, 8));
currentStreamTask.setDuration(duration.substring(0, 8));
System.out.println("-----------------放入缓存-----------------");
logger.info("-----------------放入缓存-----------------");
/**
* 放入缓存
*/
@ -274,7 +274,7 @@ public class TaskService implements ITaskService{
}
reader.close();
}catch (Exception e){
System.out.println(e.getMessage());
logger.info(e.getMessage());
}
}
},40, TimeUnit.SECONDS);

View File

@ -1,7 +1,10 @@
package com.tuoheng.steam.util;
import com.tuoheng.steam.controller.StreamRecordController;
import com.tuoheng.steam.service.dos.DayRecord;
import com.tuoheng.steam.service.dos.StreamType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
@ -14,6 +17,8 @@ import java.util.stream.Stream;
public class FileUtil {
private static final Logger logger = LoggerFactory.getLogger(FileUtil.class);
public static void deleteFolder(String stringPath) {
try {
@ -30,7 +35,7 @@ public class FileUtil {
});
}
} else {
System.out.println("文件夹不存在: " + path);
logger.info("文件夹不存在: " + path);
}
}catch (Exception e){
e.printStackTrace();

View File

@ -1,5 +1,8 @@
package com.tuoheng.steam.util;
import com.tuoheng.steam.controller.StreamRecordController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.io.*;
@ -8,6 +11,8 @@ import java.util.*;
@Service
public class ProcessManager {
private static final Logger logger = LoggerFactory.getLogger(ProcessManager.class);
private static final String DELIMITER = "=";
static Map<Long, String> runningProcessIds = new HashMap<>();
@ -96,9 +101,9 @@ public class ProcessManager {
int exitCode = process.waitFor();
if (exitCode == 0) {
System.out.println("Process with PID " + pid + " terminated successfully.");
logger.info("Process with PID " + pid + " terminated successfully.");
} else {
System.err.println("Failed to terminate process with PID " + pid + ". Exit code: " + exitCode);
logger.error("Failed to terminate process with PID " + pid + ". Exit code: " + exitCode);
}
}

View File

@ -1,12 +1,26 @@
spring.application.name=demo
#公司环境
#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 = 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
#server.port = 8080
#本地测试
#spring.application.name=stream_server
#server.port = 9011
#srs.splitPath=/Users/sunpeng/workspace/stream/temp
#srs.targetPath=/Users/sunpeng/workspace/stream/html
#ffmpeg=ffmpeg

View File

@ -0,0 +1,40 @@
<configuration>
<!-- 控制台输出 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- 文件输出(按日滚动) -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./logs/app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>./logs/app.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!--skywalking日志上报-->
<appender name="grpc-log" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.TraceIdMDCPatternLogbackLayout">
<Pattern>[th-airport] %d{yyyy-MM-dd HH:mm:ss.SSS} [%X{tid}] [%thread] %-5level %logger{36} -%msg%n</Pattern>
</layout>
</encoder>
</appender>
<!-- 日志级别设置 -->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
<appender-ref ref="grpc-log"/>
</root>
<!-- <root level="TRACE">-->
<!-- <appender-ref ref="CONSOLE"/>-->
<!-- <appender-ref ref="FILE"/>-->
<!-- <appender-ref ref="grpc-log"/>-->
<!-- </root>-->
</configuration>

View File

@ -1,34 +0,0 @@
package com.tuoheng.steam;
import com.tuoheng.steam.service.TaskService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class StreamApplicationTests {
@Autowired
TaskService taskService;
@Test
void contextLoads() {
taskService.startTask("rtmp://stream.t-aaron.com/live/123");
boolean stop = false;
while (!stop) {
try {
Thread.sleep(60000L);
}catch (Exception e){
}
}
taskService.stopAllTask();
}
}