Some checks failed
KnarCraft/FFmpegConvert/pipeline/head There was a failure building this commit
Debug mode is now enabled if the property `debug = true` is set in `conf/config.properties` Changes code for reading internal configurations Changes many primitive lists to List<> Adds some missing annotations Renames the main class
60 lines
2.2 KiB
Java
60 lines
2.2 KiB
Java
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 <p>Path/command to ffprobe.</p>
|
|
* @param ffmpegPath <p>Path/command to ffmpeg.</p>
|
|
* @param newExtension <p>The extension of the new file.</p>
|
|
*/
|
|
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<ConverterModule> 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<String> getValidFormats() {
|
|
return audioFormats;
|
|
}
|
|
|
|
} |