From 2ceec9ce94cc540db3d57e94582492a8c0c8164f Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Sat, 8 Apr 2023 13:06:32 +0200 Subject: [PATCH] Code cleanup --- .../download/VideoLengthDetector.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/ctbrec/recorder/download/VideoLengthDetector.java b/common/src/main/java/ctbrec/recorder/download/VideoLengthDetector.java index 450c3574..a6d356bb 100644 --- a/common/src/main/java/ctbrec/recorder/download/VideoLengthDetector.java +++ b/common/src/main/java/ctbrec/recorder/download/VideoLengthDetector.java @@ -1,5 +1,11 @@ package ctbrec.recorder.download; +import ctbrec.OS; +import ctbrec.io.DevNull; +import ctbrec.io.StreamRedirector; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -8,20 +14,16 @@ import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import ctbrec.OS; -import ctbrec.io.DevNull; -import ctbrec.io.StreamRedirector; - public class VideoLengthDetector { private static final Logger LOG = LoggerFactory.getLogger(VideoLengthDetector.class); + private VideoLengthDetector() { + } + /** * Tries to determine the length of a video file by calling FFmpeg and parsing it's output * - * @param videoFile + * @param videoFile the video file to analyze * @return the length as Duration object. The duration is negative, if the length couldn't be determined */ public static Duration getLength(File videoFile) { @@ -37,7 +39,7 @@ public class VideoLengthDetector { String[] cmdline = OS.getFFmpegCommand(args); LOG.debug("Command line: {}", Arrays.toString(cmdline)); Process ffmpeg = Runtime.getRuntime().exec(cmdline, new String[0], videoFile.getParentFile()); - int exitCode = 1; + int exitCode; ByteArrayOutputStream stdErrBuffer = new ByteArrayOutputStream(); Thread stdout = new Thread(new StreamRedirector(ffmpeg.getInputStream(), new DevNull())); Thread stderr = new Thread(new StreamRedirector(ffmpeg.getErrorStream(), stdErrBuffer)); @@ -47,7 +49,7 @@ public class VideoLengthDetector { LOG.debug("FFmpeg exited with code {}", exitCode); stdout.join(); stderr.join(); - String ffmpegStderr = new String(stdErrBuffer.toByteArray()); + String ffmpegStderr = stdErrBuffer.toString(); return parseDuration(ffmpegStderr); } catch (IOException | ProcessExitedUncleanException e) { LOG.error("Error in FFMpeg thread", e);