refactor(directory): propagate dir creation error to caller
This commit is contained in:
@@ -59,15 +59,10 @@ public class DirectoryService {
|
||||
return file;
|
||||
}
|
||||
|
||||
public File getVodFile(String filename) {
|
||||
public File getVodFile(String filename) throws IOException {
|
||||
String dir = outputDir + File.separator + "vods" + File.separator + filename;
|
||||
File file = new File(dir);
|
||||
|
||||
try {
|
||||
createDirectory(file.getParent());
|
||||
} catch (IOException e) {
|
||||
logger.error("Error creating vods directory: {}", e.getMessage());
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@ import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -36,16 +33,19 @@ public class StreamService {
|
||||
private final StreamRepository streamRepository;
|
||||
private final UserService userService;
|
||||
private final StreamActionsService streamActionsService;
|
||||
private final DirectoryService directoryService;
|
||||
|
||||
@Value("${storage.stream}")
|
||||
private String streamDataPath;
|
||||
|
||||
public StreamService(StreamRepository streamRepository,
|
||||
UserService userService,
|
||||
StreamActionsService streamActionsService) {
|
||||
StreamActionsService streamActionsService,
|
||||
DirectoryService directoryService) {
|
||||
this.streamRepository = streamRepository;
|
||||
this.userService = userService;
|
||||
this.streamActionsService = streamActionsService;
|
||||
this.directoryService = directoryService;
|
||||
}
|
||||
|
||||
public Stream startStream(String streamKey) {
|
||||
@@ -141,7 +141,8 @@ public class StreamService {
|
||||
float trimOffset = Math.max(0f, (startTime.toEpochMilli() - firstSegmentMs) / 1000f);
|
||||
float duration = (endTime.toEpochMilli() - startTime.toEpochMilli()) / 1000f;
|
||||
|
||||
streamActionsService.saveSection(fileSegments, trimOffset, duration);
|
||||
File outputFile = directoryService.getVodFile(UUID.randomUUID() + ".mp4");
|
||||
streamActionsService.saveSection(fileSegments, trimOffset, duration, outputFile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,14 +27,13 @@ public class StreamActionsService {
|
||||
public CompletableFuture<File> saveSection(
|
||||
List<File> segments,
|
||||
float trimOffset,
|
||||
float duration
|
||||
float duration,
|
||||
File outputFile
|
||||
) throws IOException, InterruptedException {
|
||||
String concatInput = segments.stream()
|
||||
.map(File::getAbsolutePath)
|
||||
.collect(Collectors.joining("|"));
|
||||
|
||||
File outputFile = directoryService.getVodFile(UUID.randomUUID() + ".mp4");
|
||||
|
||||
List<String> command = List.of(
|
||||
"ffmpeg",
|
||||
"-y",
|
||||
|
||||
Reference in New Issue
Block a user