From a5fd6d81380fb87b220a441e915be10b90e30425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B0=8F=E4=BA=91?= Date: Wed, 12 Feb 2025 15:05:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=93=E6=9D=9F=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 3 +++ .../com/tuoheng/steam/dos/StreamTask.java | 10 +++++++ .../tuoheng/steam/service/TaskService.java | 27 +++++++++++++++++++ src/main/resources/application.properties | 2 +- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b298f22..8a34a1a 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,9 @@ 2.0.53 + + + diff --git a/src/main/java/com/tuoheng/steam/dos/StreamTask.java b/src/main/java/com/tuoheng/steam/dos/StreamTask.java index b3410da..f964ff9 100644 --- a/src/main/java/com/tuoheng/steam/dos/StreamTask.java +++ b/src/main/java/com/tuoheng/steam/dos/StreamTask.java @@ -12,6 +12,16 @@ public class StreamTask implements Serializable { Long taskId; Date startTime; String strStartTime; + + public String getDuration() { + return duration; + } + + public void setDuration(String duration) { + this.duration = duration; + } + + String duration; /** * 接收到结束命令的时间 */ diff --git a/src/main/java/com/tuoheng/steam/service/TaskService.java b/src/main/java/com/tuoheng/steam/service/TaskService.java index 5b8ec56..0fb5a64 100644 --- a/src/main/java/com/tuoheng/steam/service/TaskService.java +++ b/src/main/java/com/tuoheng/steam/service/TaskService.java @@ -16,8 +16,10 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import javax.annotation.PostConstruct; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.util.*; import java.util.concurrent.*; @@ -198,6 +200,31 @@ public class TaskService implements ITaskService{ historyTasks.get(streamUrl).offerLast(currentStreamTask); } + if(Objects.nonNull(currentStreamTask.getMergeProcess())){ + if(Objects.nonNull(currentStreamTask.getMergeProcess().getFileName()) && + !currentStreamTask.getMergeProcess().getFileName().isEmpty()){ + try { + Process process = Runtime.getRuntime().exec("/data/ffmpeg/bin/ffmpeg -i " + + currentStreamTask.getMergeProcess().getFileName()); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream())); + String line; + while ((line = reader.readLine()) != null) { + if (line.contains("Duration")) { + System.out.println("line: " + line); + String duration = line.split("Duration: ")[1].split(",")[0]; + System.out.println("Duration: " + duration.substring(0, 8)); + currentStreamTask.setDuration(duration.substring(0, 8)); + break; + } + } + reader.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + } + return currentStreamTask; } catch (Exception e) { logger.info("taskId {} Stop exceptionally", streamUrl,e); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index bacaf35..df25245 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ spring.application.name=demo -server.port = 9011 +server.port = 8989 srs.splitPath=/data/java/srs/stream_server/temp srs.targetPath=/data/java/srs/srs/trunk/objs/nginx/html #srs.splitPath=/Users/sunpeng/workspace/stream/temp