diff --git a/src/main/java/net/knarcraft/ffmpegconverter/container/FFMpegCommand.java b/src/main/java/net/knarcraft/ffmpegconverter/container/FFMpegCommand.java index 6a210ad..54166f5 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/container/FFMpegCommand.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/container/FFMpegCommand.java @@ -18,6 +18,7 @@ public class FFMpegCommand implements Cloneable { private @NotNull List outputFileOptions; private @Nullable String outputVideoCodec; private @NotNull String outputFile; + private @NotNull String videoFilter = ""; /** * Instantiates a new FFMPEG command @@ -83,6 +84,21 @@ public class FFMpegCommand implements Cloneable { * @param argument

The output file option(s) to add

*/ public void addOutputFileOption(@NotNull String... argument) { + StringBuilder filterBuilder = new StringBuilder(this.videoFilter); + for (int i = 0; i < argument.length; i++) { + if (argument[i].equals("-vf") || argument[i].equals("-filter:v")) { + if (!filterBuilder.toString().isBlank()) { + filterBuilder.append(", ").append(argument[i + 1]); + } else { + filterBuilder.append(argument[i + 1]); + } + } + } + if (!this.videoFilter.contentEquals(filterBuilder)) { + this.videoFilter = filterBuilder.toString(); + return; + } + this.outputFileOptions.addAll(List.of(argument)); // Detect when the output video codec is set @@ -129,6 +145,10 @@ public class FFMpegCommand implements Cloneable { result.add(inputFile); } result.addAll(outputFileOptions); + if (!videoFilter.isBlank()) { + result.add("-vf"); + result.add("\"" + videoFilter + "\""); + } if (!outputFile.isEmpty()) { result.add(outputFile); } diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/LetterboxCropper.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/LetterboxCropper.java index 173877c..a29bb25 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/converter/LetterboxCropper.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/LetterboxCropper.java @@ -151,7 +151,7 @@ public class LetterboxCropper extends AbstractConverter { probeCommand.addOutputFileOption("-vframes", "10"); probeCommand.addOutputFileOption("-vf", "cropdetect"); probeCommand.addOutputFileOption("-f", "null"); - probeCommand.addOutputFileOption("-"); + probeCommand.setOutputFile("-"); double duration; try {