Skip to content

Commit

Permalink
Server: Ah ha!
Browse files Browse the repository at this point in the history
I knew I had a built-in ingest API.
  • Loading branch information
e3ndr committed Sep 23, 2023
1 parent 8cb3559 commit 34abda1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 42 deletions.
6 changes: 6 additions & 0 deletions server/src/main/java/xyz/e3ndr/athena/Athena.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public static void ingest(String fileName, Media media) throws IOException, Inte
for (Process process : processes) {
process.waitFor();
}

new File(Athena.ingestDirectory, "completed/").mkdir();
Files.move(
mediaFile.toPath(),
new File(Athena.ingestDirectory, "completed/" + mediaFile.getName()).toPath()
);
}

public static void streamIngestable(String fileName, int streamId, OutputStream target) {
Expand Down
43 changes: 1 addition & 42 deletions server/src/main/java/xyz/e3ndr/athena/webui/UIRoutes.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package xyz.e3ndr.athena.webui;

import java.io.File;
import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -28,15 +24,13 @@
import co.casterlabs.sora.api.http.annotations.HttpEndpoint;
import lombok.SneakyThrows;
import xyz.e3ndr.athena.Athena;
import xyz.e3ndr.athena.transcoding.Transcoder;
import xyz.e3ndr.athena.types.AudioCodec;
import xyz.e3ndr.athena.types.ContainerFormat;
import xyz.e3ndr.athena.types.VideoCodec;
import xyz.e3ndr.athena.types.VideoQuality;
import xyz.e3ndr.athena.types.media.Media;
import xyz.e3ndr.athena.types.media.MediaFiles.Streams;
import xyz.e3ndr.athena.types.media.MediaFiles.Streams.AudioStream;
import xyz.e3ndr.athena.types.media.MediaFiles.Streams.Stream;
import xyz.e3ndr.athena.types.media.MediaFiles.Streams.VideoStream;
import xyz.e3ndr.fastloggingframework.logging.FastLogger;
import xyz.e3ndr.fastloggingframework.logging.LogLevel;
Expand Down Expand Up @@ -343,43 +337,8 @@ public HttpResponse onViewIngestFinalize(SoraHttpSession session) {
}
}

File mediaDirectory = new File(Athena.mediaDirectory, media.getId());
new File(mediaDirectory, "subtitles").mkdirs();
new File(mediaDirectory, "streams").mkdirs();

File ingestFile = new File(Athena.ingestDirectory, toIngest);

// Write the index file.
Files.write(
new File(mediaDirectory, "index.json").toPath(),
Rson.DEFAULT
.toJson(media)
.toString(true)
.getBytes(StandardCharsets.UTF_8)
);

// Rip the streams to their own files for later muxing.
for (Stream stream : media.getFiles().getStreams().getAll()) {
int exitCode = new ProcessBuilder()
.command(
Transcoder.FFMPEG_EXEC,
"-i", ingestFile.getAbsolutePath(),
"-map", String.format("0:%d", stream.getId()),
"-c", "copy",
new File(mediaDirectory, "streams/" + stream.getId() + ".mkv").getAbsolutePath()
)
.inheritIO()
.redirectInput(Redirect.PIPE)
.start()
.waitFor();
if (exitCode != 0) throw new IOException();
}

new File(Athena.ingestDirectory, "completed/").mkdir();
Files.move(
ingestFile.toPath(),
new File(Athena.ingestDirectory, "completed/" + toIngest).toPath()
);
Athena.ingest(toIngest, media);

return HttpResponse.newFixedLengthResponse(StandardHttpStatus.TEMPORARY_REDIRECT)
.putHeader("Location", "/media/" + media.getId());
Expand Down

0 comments on commit 34abda1

Please sign in to comment.