All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
62 lines
2.0 KiB
Java
62 lines
2.0 KiB
Java
package net.knarcraft.ffmpegconverter.converter;
|
|
|
|
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 java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* A converter for converting video files
|
|
*/
|
|
public class VideoConverter extends AbstractConverter {
|
|
|
|
/**
|
|
* Instantiates a new video 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 VideoConverter(String ffprobePath, String ffmpegPath, String newExtension) {
|
|
super(newExtension);
|
|
this.ffprobePath = ffprobePath;
|
|
this.ffmpegPath = ffmpegPath;
|
|
}
|
|
|
|
@Override
|
|
public String[] builderCommand(String executable, File file, List<StreamObject> streams, String outFile) {
|
|
List<String> command = FFMpegHelper.getFFMpegGeneralFileCommand(executable, file.getName());
|
|
if (this.DEBUG) {
|
|
FFMpegHelper.addDebugArguments(command, 50, 120);
|
|
}
|
|
|
|
//Get first streams from the file
|
|
SubtitleStream subtitleStream = getFirstSubtitleStream(streams);
|
|
VideoStream videoStream = getFirstVideoStream(streams);
|
|
AudioStream audioStream = getFirstAudioSteam(streams);
|
|
|
|
//Add streams to output
|
|
addSubtitlesAndVideo(command, subtitleStream, videoStream, file);
|
|
if (audioStream != null) {
|
|
addAudioStreams(command, audioStream, true);
|
|
}
|
|
|
|
command.add(outFile);
|
|
return command.toArray(new String[0]);
|
|
}
|
|
|
|
@Override
|
|
public String[] getValidFormats() {
|
|
return videoFormats;
|
|
}
|
|
|
|
@Override
|
|
public void convert(File file) throws IOException {
|
|
processFile(file.getParentFile(), file);
|
|
}
|
|
} |