feat(streaming): add backend streaming support with nginx-rtmp #1

Merged
dylan merged 31 commits from feat/rtmp-streaming into master 2026-06-20 01:33:56 +01:00
3 changed files with 11 additions and 16 deletions
Showing only changes of commit 37e9b6c1e7 - Show all commits

View File

@@ -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());
}
createDirectory(file.getParent());
return file;
}

View 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);
}
/**

View File

@@ -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",