Changes newExtension to outputExtension and requires streams to be filtered by type before calling getFirstTypeStream
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2021-01-25 22:08:52 +01:00
parent d349629574
commit 8b0c1ea815
5 changed files with 17 additions and 20 deletions

View File

@ -18,7 +18,7 @@ import java.util.List;
*/ */
public abstract class AbstractConverter implements Converter { public abstract class AbstractConverter implements Converter {
final boolean debug = false; final boolean debug = false;
private final String newExtension; private final String outputExtension;
String ffprobePath; String ffprobePath;
String ffmpegPath; String ffmpegPath;
String[] audioFormats; String[] audioFormats;
@ -27,8 +27,8 @@ public abstract class AbstractConverter implements Converter {
/** /**
* Initializes variables used by the abstract converter * Initializes variables used by the abstract converter
*/ */
AbstractConverter(String newExtension) { AbstractConverter(String outputExtension) {
this.newExtension = newExtension; this.outputExtension = outputExtension;
OutputUtil.setDebug(this.debug); OutputUtil.setDebug(this.debug);
try { try {
audioFormats = FileUtil.readFileLines("audio_formats.txt"); audioFormats = FileUtil.readFileLines("audio_formats.txt");
@ -127,7 +127,7 @@ public abstract class AbstractConverter implements Converter {
throw new IllegalArgumentException("The file has no valid streams. Please make sure the file exists and" + throw new IllegalArgumentException("The file has no valid streams. Please make sure the file exists and" +
" is not corrupt."); " is not corrupt.");
} }
String newPath = FileUtil.getNonCollidingPath(folder, file, newExtension); String newPath = FileUtil.getNonCollidingPath(folder, file, outputExtension);
OutputUtil.println(); OutputUtil.println();
OutputUtil.println("Preparing to start process..."); OutputUtil.println("Preparing to start process...");
OutputUtil.println("Converting " + file); OutputUtil.println("Converting " + file);
@ -138,11 +138,10 @@ public abstract class AbstractConverter implements Converter {
/** /**
* Gets the first audio stream from a list of streams * Gets the first audio stream from a list of streams
* *
* @param streams <p>A list of all streams.</p> * @param audioStreams <p>A list of all streams.</p>
* @return <p>The first audio stream found or null if no audio streams were found.</p> * @return <p>The first audio stream found or null if no audio streams were found.</p>
*/ */
AudioStream getFirstAudioSteam(List<StreamObject> streams) { AudioStream getFirstAudioStream(List<AudioStream> audioStreams) {
List<AudioStream> audioStreams = filterStreamsByType(streams, AudioStream.class);
AudioStream audioStream = null; AudioStream audioStream = null;
if (audioStreams.size() > 0) { if (audioStreams.size() > 0) {
audioStream = audioStreams.get(0); audioStream = audioStreams.get(0);
@ -153,11 +152,10 @@ public abstract class AbstractConverter implements Converter {
/** /**
* Gets the first subtitle stream from a list of streams * Gets the first subtitle stream from a list of streams
* *
* @param streams <p>A list of all streams.</p> * @param subtitleStreams <p>A list of all subtitle streams.</p>
* @return <p>The first subtitle stream found or null if no subtitle streams were found.</p> * @return <p>The first subtitle stream found or null if no subtitle streams were found.</p>
*/ */
SubtitleStream getFirstSubtitleStream(List<StreamObject> streams) { SubtitleStream getFirstSubtitleStream(List<SubtitleStream> subtitleStreams) {
List<SubtitleStream> subtitleStreams = filterStreamsByType(streams, SubtitleStream.class);
SubtitleStream subtitleStream = null; SubtitleStream subtitleStream = null;
if (subtitleStreams.size() > 0) { if (subtitleStreams.size() > 0) {
subtitleStream = subtitleStreams.get(0); subtitleStream = subtitleStreams.get(0);
@ -168,11 +166,10 @@ public abstract class AbstractConverter implements Converter {
/** /**
* Gets the first video stream from a list of streams * Gets the first video stream from a list of streams
* *
* @param streams <p>A list of all streams.</p> * @param videoStreams <p>A list of all streams.</p>
* @return <p>The first video stream found or null if no video streams were found.</p> * @return <p>The first video stream found or null if no video streams were found.</p>
*/ */
VideoStream getFirstVideoStream(List<StreamObject> streams) { VideoStream getFirstVideoStream(List<VideoStream> videoStreams) {
List<VideoStream> videoStreams = filterStreamsByType(streams, VideoStream.class);
VideoStream videoStream = null; VideoStream videoStream = null;
if (videoStreams.size() > 0) { if (videoStreams.size() > 0) {
videoStream = videoStreams.get(0); videoStream = videoStreams.get(0);

View File

@ -80,7 +80,7 @@ public class AdvancedConverter extends AbstractConverter {
//Get the first audio stream in accordance with chosen languages //Get the first audio stream in accordance with chosen languages
List<AudioStream> audioStreams = filterAudioStreams(filterStreamsByType(streams, AudioStream.class), audioLanguages); List<AudioStream> audioStreams = filterAudioStreams(filterStreamsByType(streams, AudioStream.class), audioLanguages);
AudioStream audioStream = getFirstAudioSteam(new ArrayList<>(audioStreams)); AudioStream audioStream = getFirstAudioStream(new ArrayList<>(audioStreams));
//Get the first subtitle stream in accordance with chosen languages and signs and songs prevention //Get the first subtitle stream in accordance with chosen languages and signs and songs prevention
List<SubtitleStream> subtitleStreams = filterSubtitleStreams(filterStreamsByType(streams, List<SubtitleStream> subtitleStreams = filterSubtitleStreams(filterStreamsByType(streams,

View File

@ -49,7 +49,7 @@ public class AnimeConverter extends AbstractConverter {
//Get the first audio stream in accordance with chosen languages //Get the first audio stream in accordance with chosen languages
List<AudioStream> audioStreams = filterAudioStreams(filterStreamsByType(streams, AudioStream.class), audioLanguages); List<AudioStream> audioStreams = filterAudioStreams(filterStreamsByType(streams, AudioStream.class), audioLanguages);
AudioStream audioStream = getFirstAudioSteam(new ArrayList<>(audioStreams)); AudioStream audioStream = getFirstAudioStream(new ArrayList<>(audioStreams));
//Get the first subtitle stream in accordance with chosen languages and signs and songs prevention //Get the first subtitle stream in accordance with chosen languages and signs and songs prevention
List<SubtitleStream> subtitleStreams = filterSubtitleStreams(filterStreamsByType(streams, List<SubtitleStream> subtitleStreams = filterSubtitleStreams(filterStreamsByType(streams,
@ -57,7 +57,7 @@ public class AnimeConverter extends AbstractConverter {
SubtitleStream subtitleStream = getFirstSubtitleStream(new ArrayList<>(subtitleStreams)); SubtitleStream subtitleStream = getFirstSubtitleStream(new ArrayList<>(subtitleStreams));
//Get the first video stream //Get the first video stream
VideoStream videoStream = getFirstVideoStream(streams); VideoStream videoStream = getFirstVideoStream(filterStreamsByType(streams, VideoStream.class));
//Add streams to output file //Add streams to output file
FFMpegHelper.addAudioStream(command, audioStream, toStereo); FFMpegHelper.addAudioStream(command, audioStream, toStereo);

View File

@ -33,7 +33,7 @@ public class AudioConverter extends AbstractConverter {
} }
//Gets the first audio stream from the file and adds it to the output file //Gets the first audio stream from the file and adds it to the output file
AudioStream audioStream = getFirstAudioSteam(streams); AudioStream audioStream = getFirstAudioStream(filterStreamsByType(streams, AudioStream.class));
FFMpegHelper.addAudioStream(command, audioStream, false); FFMpegHelper.addAudioStream(command, audioStream, false);
command.add(outFile); command.add(outFile);

View File

@ -37,9 +37,9 @@ public class WebVideoConverter extends AbstractConverter {
} }
//Get first streams from the file //Get first streams from the file
SubtitleStream subtitleStream = getFirstSubtitleStream(streams); SubtitleStream subtitleStream = getFirstSubtitleStream(filterStreamsByType(streams, SubtitleStream.class));
VideoStream videoStream = getFirstVideoStream(streams); VideoStream videoStream = getFirstVideoStream(filterStreamsByType(streams, VideoStream.class));
AudioStream audioStream = getFirstAudioSteam(streams); AudioStream audioStream = getFirstAudioStream(filterStreamsByType(streams, AudioStream.class));
//Add streams to output //Add streams to output
FFMpegHelper.addSubtitleAndVideoStream(command, subtitleStream, videoStream, file); FFMpegHelper.addSubtitleAndVideoStream(command, subtitleStream, videoStream, file);