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.ArrayList; import java.util.List; /** * A converter mainly designed for converting anime to web-playable mp4 */ public class AnimeConverter extends AbstractConverter { private final String[] audioLanguages; private final String[] subtitleLanguages; private final boolean toStereo; private final boolean preventSignsAndSongs; /** * Instantiates a new anime converter * * @param ffprobePath

Path/command to ffprobe.

* @param ffmpegPath

Path/command to ffmpeg.

* @param audioLanguages

List of wanted audio languages in descending order.

* @param subtitleLanguages

List of wanted subtitle languages in descending order.

* @param toStereo

Convert video with several audio channels to stereo.

* @param preventSignsAndSongs

Prevent subtitles only converting signs and songs (not speech).

*/ public AnimeConverter(String ffprobePath, String ffmpegPath, String[] audioLanguages, String[] subtitleLanguages, boolean toStereo, boolean preventSignsAndSongs) { super("mp4"); this.ffprobePath = ffprobePath; this.ffmpegPath = ffmpegPath; this.audioLanguages = audioLanguages; this.subtitleLanguages = subtitleLanguages; this.toStereo = toStereo; this.preventSignsAndSongs = preventSignsAndSongs; } @Override public void convert(File file) throws IOException { processFile(file.getParentFile(), file); } @Override public String[] generateConversionCommand(String executable, File file, List streams, String outFile) { List command = FFMpegHelper.getFFMpegWebVideoCommand(executable, file.getName()); if (this.DEBUG) { FFMpegHelper.addDebugArguments(command, 50, 120); } //Get the first audio stream in accordance with chosen languages List audioStreams = filterAudioStreams(filterStreamsByType(streams, AudioStream.class), audioLanguages); AudioStream audioStream = getFirstAudioSteam(new ArrayList<>(audioStreams)); //Get the first subtitle stream in accordance with chosen languages and signs and songs prevention List subtitleStreams = filterSubtitleStreams(filterStreamsByType(streams, SubtitleStream.class), subtitleLanguages, preventSignsAndSongs); SubtitleStream subtitleStream = getFirstSubtitleStream(new ArrayList<>(subtitleStreams)); //Get the first video stream VideoStream videoStream = getFirstVideoStream(streams); //Add streams to output file FFMpegHelper.addAudioStreams(command, audioStream, toStereo); FFMpegHelper.addSubtitlesAndVideo(command, subtitleStream, videoStream, file); command.add(outFile); return command.toArray(new String[0]); } @Override public String[] getValidFormats() { return videoFormats; } }