package net.knarcraft.ffmpegconverter.converter; import net.knarcraft.ffmpegconverter.container.FFMpegCommand; import net.knarcraft.ffmpegconverter.container.StreamProbeResult; import net.knarcraft.ffmpegconverter.converter.module.ConverterModule; import net.knarcraft.ffmpegconverter.converter.module.DebugModule; import net.knarcraft.ffmpegconverter.converter.module.ModuleExecutor; import net.knarcraft.ffmpegconverter.converter.module.mapping.NthAudioStreamModule; import net.knarcraft.ffmpegconverter.converter.module.output.SetOutputFileModule; import net.knarcraft.ffmpegconverter.utility.FFMpegHelper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; /** * A converter for converting audio files */ public class AudioConverter extends AbstractConverter { /** * Instantiates a new audio converter * * @param ffprobePath

Path/command to ffprobe.

* @param ffmpegPath

Path/command to ffmpeg.

* @param newExtension

The extension of the new file.

*/ public AudioConverter(@NotNull String ffprobePath, @NotNull String ffmpegPath, @NotNull String newExtension) { super(newExtension); this.ffprobePath = ffprobePath; this.ffmpegPath = ffmpegPath; } @Override @Nullable public FFMpegCommand generateConversionCommand(@NotNull String executable, @NotNull StreamProbeResult probeResult, @NotNull String outFile) { FFMpegCommand command = FFMpegHelper.getFFMpegGeneralFileCommand(executable, probeResult.parsedFiles()); List modules = new ArrayList<>(); if (this.debug) { modules.add(new DebugModule(0, 0)); } //Gets the first audio stream from the file and adds it to the output file modules.add(new NthAudioStreamModule(probeResult.getAudioStreams(), 0)); modules.add(new SetOutputFileModule(outFile)); new ModuleExecutor(command, modules).execute(); return command; } @Override @NotNull public List getValidFormats() { return audioFormats; } }