Makes video filters automatically combine to allow de-interlacing when filters are executed
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2024-12-27 15:02:05 +01:00
parent 506273cbcd
commit 5db760d1a1
2 changed files with 21 additions and 1 deletions

View File

@ -18,6 +18,7 @@ public class FFMpegCommand implements Cloneable {
private @NotNull List<String> 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 <p>The output file option(s) to add</p>
*/
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);
}

View File

@ -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 {