Improves FFMpeg command generation

Adds an object for storing FFmpeg variables. This allows any argument type to be added at any time, removing the limitation of having to add to the command in a specific order.
Makes stream objects store the index of the input file they belong to.
Saves the result of probes to a record that's easy to pass around.
Always passes all probed files to the input files of ffmpeg.
Makes it easier to enable h26x encoding/decoding when necessary.
Removes the hard-coded behavior for external subtitles, and allows any stream to be an external stream.
This commit is contained in:
2024-04-08 20:00:09 +02:00
parent be88845731
commit 376d5655f2
20 changed files with 537 additions and 450 deletions

View File

@ -1,12 +1,14 @@
package net.knarcraft.ffmpegconverter.converter;
import net.knarcraft.ffmpegconverter.container.FFMpegCommand;
import net.knarcraft.ffmpegconverter.container.StreamProbeResult;
import net.knarcraft.ffmpegconverter.streams.AudioStream;
import net.knarcraft.ffmpegconverter.streams.StreamObject;
import net.knarcraft.ffmpegconverter.streams.SubtitleStream;
import net.knarcraft.ffmpegconverter.streams.VideoStream;
import net.knarcraft.ffmpegconverter.utility.FFMpegHelper;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.List;
/**
@ -33,8 +35,10 @@ public class WebVideoConverter extends AbstractConverter {
}
@Override
public String[] generateConversionCommand(String executable, File file, List<StreamObject> streams, String outFile) {
List<String> command = FFMpegHelper.getFFMpegWebVideoCommand(executable, file.getName());
public String[] generateConversionCommand(@NotNull String executable, @NotNull StreamProbeResult probeResult,
@NotNull String outFile) {
FFMpegCommand command = FFMpegHelper.getFFMpegWebVideoCommand(executable, probeResult.parsedFiles());
List<StreamObject> streams = probeResult.parsedStreams();
if (this.debug) {
FFMpegHelper.addDebugArguments(command, 50, 120);
}
@ -44,13 +48,17 @@ public class WebVideoConverter extends AbstractConverter {
VideoStream videoStream = getNthVideoStream(streams, 0);
AudioStream audioStream = getNthAudioSteam(streams, 0);
if (videoStream == null) {
throw new IllegalArgumentException("The selected video stream does not exist.");
}
//Add streams to output
FFMpegHelper.addSubtitleAndVideoStream(command, subtitleStream, videoStream, file);
FFMpegHelper.addSubtitleAndVideoStream(command, subtitleStream, videoStream);
if (audioStream != null) {
FFMpegHelper.addAudioStream(command, audioStream, true);
}
command.add(outFile);
return command.toArray(new String[0]);
command.setOutputFile(outFile);
return command.getResult();
}
}