EpicKnarvik97 4ebd29b358
Some checks failed
KnarCraft/FFmpegConvert/pipeline/head There was a failure building this commit
Makes it possible to enable debug mode
Debug mode is now enabled if the property `debug = true` is set in `conf/config.properties`
Changes code for reading internal configurations
Changes many primitive lists to List<>
Adds some missing annotations
Renames the main class
2024-04-17 15:35:09 +02:00

87 lines
3.3 KiB
Java

package net.knarcraft.ffmpegconverter.converter;
import net.knarcraft.ffmpegconverter.container.FFMpegCommand;
import net.knarcraft.ffmpegconverter.container.StreamProbeResult;
import net.knarcraft.ffmpegconverter.converter.module.ConverterModule;
import net.knarcraft.ffmpegconverter.converter.module.DebugModule;
import net.knarcraft.ffmpegconverter.converter.module.ModuleExecutor;
import net.knarcraft.ffmpegconverter.converter.module.hardwarecoding.H265HardwareEncodingModule;
import net.knarcraft.ffmpegconverter.converter.module.hardwarecoding.HardwareDecodeModule;
import net.knarcraft.ffmpegconverter.converter.module.mapping.MapAllModule;
import net.knarcraft.ffmpegconverter.converter.module.output.CopySubtitlesModule;
import net.knarcraft.ffmpegconverter.converter.module.output.FastStartModule;
import net.knarcraft.ffmpegconverter.converter.module.output.SetOutputFileModule;
import net.knarcraft.ffmpegconverter.streams.AudioStream;
import net.knarcraft.ffmpegconverter.streams.SubtitleStream;
import net.knarcraft.ffmpegconverter.streams.VideoStream;
import net.knarcraft.ffmpegconverter.utility.FFMpegHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* A converter solely for the purpose of converting video streams of MKV files into h264
*/
public class MkvH265ReducedConverter 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 MkvH265ReducedConverter(String ffprobePath, String ffmpegPath) {
super("mkv");
this.ffprobePath = ffprobePath;
this.ffmpegPath = ffmpegPath;
}
@Override
@NotNull
public List<String> getValidFormats() {
return List.of("mkv");
}
@Override
@Nullable
public FFMpegCommand generateConversionCommand(@NotNull String executable, @NotNull StreamProbeResult probeResult,
@NotNull String outFile) {
FFMpegCommand command = FFMpegHelper.getFFMpegGeneralFileCommand(executable, probeResult.parsedFiles());
List<ConverterModule> modules = new ArrayList<>();
if (this.debug) {
modules.add(new DebugModule(0, 0));
}
// Map video if present
List<VideoStream> videoStreams = probeResult.getVideoStreams();
if (!videoStreams.isEmpty()) {
modules.add(new HardwareDecodeModule());
modules.add(new H265HardwareEncodingModule(19));
modules.add(new FastStartModule());
modules.add(new MapAllModule<>(videoStreams));
}
// Map audio if present
List<AudioStream> audioStreams = probeResult.getAudioStreams();
if (!audioStreams.isEmpty()) {
modules.add(new MapAllModule<>(audioStreams));
}
// Map subtitles if present
List<SubtitleStream> subtitleStreams = probeResult.getSubtitleStreams();
if (!subtitleStreams.isEmpty()) {
modules.add(new MapAllModule<>(subtitleStreams));
modules.add(new CopySubtitlesModule());
}
modules.add(new SetOutputFileModule(outFile));
new ModuleExecutor(command, modules).execute();
return command;
}
}