Adds a MKV to h264 MKV converter
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
This commit is contained in:
parent
a9ea1f796a
commit
5d94cabca0
@ -1,8 +1,9 @@
|
||||
package net.knarcraft.ffmpegconverter;
|
||||
|
||||
import net.knarcraft.ffmpegconverter.converter.AbstractConverter;
|
||||
import net.knarcraft.ffmpegconverter.converter.AnimeConverter;
|
||||
import net.knarcraft.ffmpegconverter.converter.AudioConverter;
|
||||
import net.knarcraft.ffmpegconverter.converter.Converter;
|
||||
import net.knarcraft.ffmpegconverter.converter.MkvH264Converter;
|
||||
import net.knarcraft.ffmpegconverter.converter.VideoConverter;
|
||||
import net.knarcraft.ffmpegconverter.converter.WebVideoConverter;
|
||||
import net.knarcraft.ffmpegconverter.utility.FileUtil;
|
||||
@ -24,10 +25,14 @@ class Main {
|
||||
private static final String FFPROBE_PATH = "ffprobe"; //Can be just ffprobe if it's in the path
|
||||
private static final String FFMPEG_PATH = "ffmpeg"; //Can be just ffmpeg if it's in the path
|
||||
private static final Scanner READER = new Scanner(System.in, "UTF-8");
|
||||
private static AbstractConverter converter = null;
|
||||
private static Converter converter = null;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
loadConverter();
|
||||
converter = loadConverter();
|
||||
if (converter == null) {
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> input;
|
||||
do {
|
||||
@ -54,27 +59,23 @@ class Main {
|
||||
*
|
||||
* @throws IOException <p>If there's a problem getting user input.</p>
|
||||
*/
|
||||
private static void loadConverter() throws IOException {
|
||||
private static Converter loadConverter() throws IOException {
|
||||
int choice = getChoice("Which converter do you want do use?\n1. Anime to web mp4\n2. Audio converter\n" +
|
||||
"3. Video converter\n4. Web video converter", 1, 4);
|
||||
"3. Video converter\n4. Web video converter\n5. MKV to h264 converter", 1, 5);
|
||||
|
||||
OutputUtil.println("Input for this converter:");
|
||||
switch (choice) {
|
||||
case 1:
|
||||
animeConverter();
|
||||
break;
|
||||
return animeConverter();
|
||||
case 2:
|
||||
converter = new AudioConverter(FFPROBE_PATH, FFMPEG_PATH, getChoice("<output extension>"));
|
||||
break;
|
||||
return new AudioConverter(FFPROBE_PATH, FFMPEG_PATH, getChoice("<output extension>"));
|
||||
case 3:
|
||||
converter = new VideoConverter(FFPROBE_PATH, FFMPEG_PATH, getChoice("<output extension>"));
|
||||
break;
|
||||
return new VideoConverter(FFPROBE_PATH, FFMPEG_PATH, getChoice("<output extension>"));
|
||||
case 4:
|
||||
converter = new WebVideoConverter(FFPROBE_PATH, FFMPEG_PATH, getChoice("<output extension>"));
|
||||
break;
|
||||
default:
|
||||
System.exit(1);
|
||||
return new WebVideoConverter(FFPROBE_PATH, FFMPEG_PATH, getChoice("<output extension>"));
|
||||
case 5:
|
||||
return new MkvH264Converter(FFPROBE_PATH, FFMPEG_PATH);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,7 +107,7 @@ class Main {
|
||||
*
|
||||
* @throws IOException <p>If reading or writing fails.</p>
|
||||
*/
|
||||
private static void animeConverter() throws IOException {
|
||||
private static Converter animeConverter() throws IOException {
|
||||
OutputUtil.println("[Audio languages jpn,eng,ger,fre] [Subtitle languages eng,ger,fre] [Convert to stereo if " +
|
||||
"necessary true/false] [Prevent signs&songs subtitles true/false] [Forced audio index 0-n] " +
|
||||
"[Forced subtitle index 0-n] [Subtitle name filter]\nYour input: ");
|
||||
@ -140,12 +141,12 @@ class Main {
|
||||
}
|
||||
} catch (NumberFormatException exception) {
|
||||
OutputUtil.println("Forced audio or subtitle index is not a number");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (input.size() > 6) {
|
||||
subtitleNameFilter = input.get(6);
|
||||
}
|
||||
converter = new AnimeConverter(FFPROBE_PATH, FFMPEG_PATH, audioLanguage, subtitleLanguage, toStereo,
|
||||
return new AnimeConverter(FFPROBE_PATH, FFMPEG_PATH, audioLanguage, subtitleLanguage, toStereo,
|
||||
preventSigns, forcedAudioIndex, forcedSubtitleIndex, subtitleNameFilter);
|
||||
}
|
||||
|
||||
|
@ -113,13 +113,6 @@ public abstract class AbstractConverter implements Converter {
|
||||
return sorted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all valid input formats for the converter
|
||||
*
|
||||
* @return <p>A list of valid input formats</p>
|
||||
*/
|
||||
public abstract String[] getValidFormats();
|
||||
|
||||
/**
|
||||
* Reads streams from a file, and converts it to a mp4 file
|
||||
*
|
||||
|
@ -9,7 +9,14 @@ import java.util.List;
|
||||
/**
|
||||
* This interface describes a file converter
|
||||
*/
|
||||
interface Converter {
|
||||
public interface Converter {
|
||||
|
||||
/**
|
||||
* Gets all valid input formats for the converter
|
||||
*
|
||||
* @return <p>A list of valid input formats</p>
|
||||
*/
|
||||
String[] getValidFormats();
|
||||
|
||||
/**
|
||||
* Converts the given file
|
||||
|
@ -0,0 +1,75 @@
|
||||
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.util.List;
|
||||
|
||||
/**
|
||||
* A converter solely for the purpose of converting video streams of MKV files into h264
|
||||
*/
|
||||
public class MkvH264Converter extends AbstractConverter {
|
||||
|
||||
/**
|
||||
* Initializes variables used by the abstract converter
|
||||
*
|
||||
* @param ffprobePath <p>Path/command to ffprobe.</p>
|
||||
* @param ffmpegPath <p>Path/command to ffmpeg.</p>
|
||||
*/
|
||||
public MkvH264Converter(String ffprobePath, String ffmpegPath) {
|
||||
super("mkv");
|
||||
this.ffprobePath = ffprobePath;
|
||||
this.ffmpegPath = ffmpegPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getValidFormats() {
|
||||
return new String[]{"mkv"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] generateConversionCommand(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);
|
||||
}
|
||||
|
||||
// Map video if present
|
||||
if (!filterStreamsByType(streams, VideoStream.class).isEmpty()) {
|
||||
command.add("-map");
|
||||
command.add("0:v");
|
||||
command.add("-vcodec");
|
||||
command.add("h264");
|
||||
}
|
||||
|
||||
// Map audio if present
|
||||
if (!filterStreamsByType(streams, AudioStream.class).isEmpty()) {
|
||||
command.add("-map");
|
||||
command.add("0:a");
|
||||
command.add("-c:a");
|
||||
command.add("copy");
|
||||
}
|
||||
|
||||
// Map subtitles if present
|
||||
if (!filterStreamsByType(streams, SubtitleStream.class).isEmpty()) {
|
||||
command.add("-map");
|
||||
command.add("0:s");
|
||||
command.add("-c:s");
|
||||
command.add("copy");
|
||||
}
|
||||
|
||||
command.add("-map_metadata");
|
||||
command.add("0");
|
||||
command.add("-movflags");
|
||||
command.add("use_metadata_tags");
|
||||
|
||||
command.add(outFile);
|
||||
return command.toArray(new String[0]);
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,7 @@ import java.io.InputStreamReader;
|
||||
public final class FileUtil {
|
||||
|
||||
private FileUtil() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,5 +78,5 @@ public final class ListUtil {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public final class OutputUtil {
|
||||
private static boolean debug;
|
||||
|
||||
private OutputUtil() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,5 +195,5 @@ public final class Parser {
|
||||
private static boolean isNotEmpty(StringBuilder builder) {
|
||||
return !builder.toString().trim().equals("");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -30,5 +30,5 @@ final class StringUtil {
|
||||
//Add other occurrences recursively
|
||||
return ListUtil.concatenate(new String[]{outString}, stringBetween(nextString, start, end));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user