From 6640f2d5c4ee859ad47ae6bcf3ed761ad5c47105 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Sun, 1 May 2022 13:49:41 -0400 Subject: [PATCH] Streamlined the ffmpeg ProcessBuilder to inherit IO streams; added printing out of the ffmpeg command to verify it's working as intended. --- .../java/tech/bitgoblin/video/Transcoder.java | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/main/java/tech/bitgoblin/video/Transcoder.java b/src/main/java/tech/bitgoblin/video/Transcoder.java index d48535d..5d89e02 100644 --- a/src/main/java/tech/bitgoblin/video/Transcoder.java +++ b/src/main/java/tech/bitgoblin/video/Transcoder.java @@ -45,9 +45,10 @@ public class Transcoder { String filename = Paths.get(filePath).getFileName().toString(); String outputPath = Paths.get(this.repo_dir, "output", String.format("%s.mov", filename)).toString(); - String cmd = String.format("%s -i %s -c:v %s -vf \"%s\" -profile:v %s -c:a %s %s", + String cmd = String.format("%s -i %s -y -f %s -c:v %s -vf %s -profile:v %s -c:a %s %s", this.ffmpeg_path, // FFMPEG binary path f.toString(), // input file + "mov", "dnxhd", // video codec "scale=1920x1080,fps=60,format=yuv422p", // video format "dnxhr_hq", // video profile @@ -56,12 +57,13 @@ public class Transcoder { ); ProcessBuilder pb = new ProcessBuilder(cmd.split("\\s+")); - pb.redirectErrorStream(true); - pb.redirectOutput(ProcessBuilder.Redirect.PIPE); + pb.inheritIO(); // use the java processes' input and output streams try { Process process = pb.start(); int ret = process.waitFor(); - System.out.printf("Program exited with code: %d", ret); + System.out.printf("Program exited with code: %d\n", ret); + System.out.println(String.join(" ", pb.command())); + System.out.println(); } catch (IOException | InterruptedException e) { throw new RuntimeException(e); } @@ -82,21 +84,4 @@ public class Transcoder { IOUtils.createDirectory(Paths.get(this.repo_dir, "output").toString()); } - - // Stream handler class for the Transcoder - private static class StreamGobbler implements Runnable { - private InputStream inputStream; - private Consumer consumer; - - public StreamGobbler(InputStream inputStream, Consumer consumer) { - this.inputStream = inputStream; - this.consumer = consumer; - } - - @Override - public void run() { - new BufferedReader(new InputStreamReader(inputStream)).lines().forEach(consumer); - } - } - }