From 34abda15de2d61c948d9f89c25bf0c2138ce4073 Mon Sep 17 00:00:00 2001 From: Ender <33337309+e3ndr@users.noreply.github.com> Date: Fri, 22 Sep 2023 19:42:43 -0500 Subject: [PATCH] Server: Ah ha! I knew I had a built-in ingest API. --- .../main/java/xyz/e3ndr/athena/Athena.java | 6 +++ .../java/xyz/e3ndr/athena/webui/UIRoutes.java | 43 +------------------ 2 files changed, 7 insertions(+), 42 deletions(-) diff --git a/server/src/main/java/xyz/e3ndr/athena/Athena.java b/server/src/main/java/xyz/e3ndr/athena/Athena.java index 0bcdb8f..77b0c60 100644 --- a/server/src/main/java/xyz/e3ndr/athena/Athena.java +++ b/server/src/main/java/xyz/e3ndr/athena/Athena.java @@ -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) { diff --git a/server/src/main/java/xyz/e3ndr/athena/webui/UIRoutes.java b/server/src/main/java/xyz/e3ndr/athena/webui/UIRoutes.java index 44a53f6..8a187e7 100644 --- a/server/src/main/java/xyz/e3ndr/athena/webui/UIRoutes.java +++ b/server/src/main/java/xyz/e3ndr/athena/webui/UIRoutes.java @@ -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; @@ -28,7 +24,6 @@ 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; @@ -36,7 +31,6 @@ 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; @@ -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());