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);