All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
Adds a module to de-interlace when converting a video. It's enabled by a new configuration option. Fixes some bugs in the letterbox cropper Adds mpeg4 to video formats
88 lines
3.7 KiB
Java
88 lines
3.7 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.HardwareDecodeModule;
|
|
import net.knarcraft.ffmpegconverter.converter.module.mapping.NthAudioStreamModule;
|
|
import net.knarcraft.ffmpegconverter.converter.module.mapping.NthSubtitleStreamModule;
|
|
import net.knarcraft.ffmpegconverter.converter.module.mapping.NthVideoStreamModule;
|
|
import net.knarcraft.ffmpegconverter.converter.module.output.CopyAllModule;
|
|
import net.knarcraft.ffmpegconverter.converter.module.output.SetOutputFileModule;
|
|
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 transcoder which takes one of each stream from an MKV file and produces an MP4 file
|
|
*/
|
|
public class MKVToMP4Transcoder extends AbstractConverter {
|
|
|
|
private final int videoStreamIndex;
|
|
private final int audioStreamIndex;
|
|
private final int subtitleStreamIndex;
|
|
|
|
/**
|
|
* Instantiates a new mkv to mp4 transcoder
|
|
*
|
|
* @param ffprobePath <p>Path/command to ffprobe.</p>
|
|
* @param ffmpegPath <p>Path/command to ffmpeg.</p>
|
|
* @param audioStreamIndex <p>The relative index of the audio stream to use (0 or below selects the first)</p>
|
|
* @param subtitleStreamIndex <p>The relative index of the subtitle stream to use (0 or below selects the first)</p>
|
|
* @param videoStreamIndex <p>The relative index of the video stream to use (0 or below selects the first)</p>
|
|
*/
|
|
public MKVToMP4Transcoder(String ffprobePath, String ffmpegPath, int audioStreamIndex, int subtitleStreamIndex,
|
|
int videoStreamIndex) {
|
|
super("mp4");
|
|
this.ffprobePath = ffprobePath;
|
|
this.ffmpegPath = ffmpegPath;
|
|
this.videoStreamIndex = videoStreamIndex;
|
|
this.audioStreamIndex = audioStreamIndex;
|
|
this.subtitleStreamIndex = subtitleStreamIndex;
|
|
}
|
|
|
|
@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());
|
|
}
|
|
|
|
// Copy stream info
|
|
modules.add(new CopyAllModule());
|
|
|
|
//Add streams to output file
|
|
if (!probeResult.getAudioStreams().isEmpty()) {
|
|
modules.add(new NthAudioStreamModule(probeResult.getAudioStreams(), this.audioStreamIndex));
|
|
}
|
|
if (!probeResult.getVideoStreams().isEmpty()) {
|
|
modules.add(new NthVideoStreamModule(probeResult.getVideoStreams(), this.videoStreamIndex));
|
|
modules.add(new HardwareDecodeModule());
|
|
}
|
|
if (!probeResult.getSubtitleStreams().isEmpty()) {
|
|
modules.add(new NthSubtitleStreamModule(probeResult.getSubtitleStreams(), this.subtitleStreamIndex));
|
|
}
|
|
|
|
modules.add(new SetOutputFileModule(outFile));
|
|
|
|
new ModuleExecutor(command, modules).execute();
|
|
return command;
|
|
}
|
|
|
|
}
|