Updates converters to use the new utility classes

This commit is contained in:
2020-05-08 19:11:42 +02:00
parent 29437f1256
commit 857c8f29a4
5 changed files with 123 additions and 182 deletions

View File

@ -2,19 +2,25 @@ package net.knarcraft.ffmpegconverter.converter;
import net.knarcraft.ffmpegconverter.streams.AudioStream;
import net.knarcraft.ffmpegconverter.streams.StreamObject;
import net.knarcraft.ffmpegconverter.utility.FFMpegHelper;
import net.knarcraft.ffmpegconverter.utility.FileUtil;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class AudioConverter extends Converter {
private String newExt;
/**
* A converter for converting audio files
*/
public class AudioConverter extends AbstractConverter {
private final String newExt;
/**
* Instantiates a new audio converter
*
* @param ffprobePath <p>Path/command to ffprobe.</p>
* @param ffmpegPath <p>Path/command to ffmpeg.</p>
* @param newExt <p>The extension of the new file.</p>
* @param ffmpegPath <p>Path/command to ffmpeg.</p>
* @param newExt <p>The extension of the new file.</p>
*/
public AudioConverter(String ffprobePath, String ffmpegPath, String newExt) {
this.ffprobePath = ffprobePath;
@ -24,30 +30,32 @@ public class AudioConverter extends Converter {
/**
* Processes a file conversion
*
* @param folder <p>The work folder containing the file.</p>
* @param file <p>The file to convert.</p>
* @param file <p>The file to convert.</p>
* @param newExt <p>The extension of the new file.</p>
* @throws IOException <p>If the file cannot be converted.</p>
*/
private void processFile(File folder, File file, String newExt) throws IOException {
List<StreamObject> streams = probeFile(ffprobePath, file);
List<StreamObject> streams = FFMpegHelper.probeFile(ffprobePath, file);
if (streams.size() == 0) {
throw new IllegalArgumentException("The file has no streams");
}
String newPath = stripExtension(file) + "." + newExt;
convertProcess(new ProcessBuilder(builderCommand(ffmpegPath, file.getName(), streams, newPath)), folder);
String newPath = FileUtil.stripExtension(file) + "." + newExt;
FFMpegHelper.convertProcess(new ProcessBuilder(builderCommand(ffmpegPath, file.getName(), streams, newPath)), folder);
}
/**
* Generates a command for a ProcessBuilder.
*
* @param executable <p>The executable file for ffmpeg.</p>
* @param fileName <p>The input file.</p>
* @param streams <p>A list of ffprobe streams.</p>
* @param outFile <p>The output file.</p>
* @param fileName <p>The input file.</p>
* @param streams <p>A list of ffprobe streams.</p>
* @param outFile <p>The output file.</p>
* @return <p>A list of commands.</p>
*/
private String[] builderCommand(String executable, String fileName, List<StreamObject> streams, String outFile) {
List<String> command = generalFile(executable, fileName);
List<String> command = FFMpegHelper.getFFMpegGeneralFileCommand(executable, fileName);
List<AudioStream> audioStreams = filterStreamsByType(streams, "audio");
AudioStream audioStream = null;
if (audioStreams.size() > 0) {
@ -63,7 +71,7 @@ public class AudioConverter extends Converter {
@Override
public String[] getValidFormats() {
return AUDIO_FORMATS;
return audioFormats;
}
@Override