From: Svjatoslav Agejenko Date: Tue, 19 Nov 2013 14:44:19 +0000 (+0200) Subject: mkv to mp4 conversion X-Git-Tag: meviz-1.0~70 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=dddcfc16c5894cfb8fb98719f7652662d8466062;p=meviz.git mkv to mp4 conversion --- diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java b/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java index ab794c3..9555e6e 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java @@ -15,6 +15,7 @@ import java.util.List; import eu.svjatoslav.meviz.encoder.converters.Avi2Ogv; import eu.svjatoslav.meviz.encoder.converters.Converter; import eu.svjatoslav.meviz.encoder.converters.Jpeg2Png; +import eu.svjatoslav.meviz.encoder.converters.Mkv2Mp4; import eu.svjatoslav.meviz.encoder.converters.Mp42Ogv; import eu.svjatoslav.meviz.encoder.converters.Mts2Mkv; import eu.svjatoslav.meviz.encoder.converters.Mts2Mp4; @@ -26,47 +27,50 @@ import eu.svjatoslav.meviz.encoder.converters.Wav2mp3; public class FormatsRegistry { - public ArrayList encoders = new ArrayList(); + public ArrayList encoders = new ArrayList(); - public FormatsRegistry() { - // video conversion - registerEncoder(new Avi2Ogv()); - registerEncoder(new Mp42Ogv()); - registerEncoder(new Mts2Mp4()); - registerEncoder(new Mts2Mkv()); + public FormatsRegistry() { + // video conversion + registerEncoder(new Avi2Ogv()); + registerEncoder(new Mp42Ogv()); + registerEncoder(new Mts2Mp4()); + registerEncoder(new Mts2Mkv()); + registerEncoder(new Mkv2Mp4()); - // image conversion - registerEncoder(new Jpeg2Png()); - registerEncoder(new Png2Tiff()); - registerEncoder(new Tiff2Png()); + // image conversion + registerEncoder(new Jpeg2Png()); + registerEncoder(new Png2Tiff()); + registerEncoder(new Tiff2Png()); - // audio conversion - registerEncoder(new Ogg2Wav()); - registerEncoder(new Wav2mp3()); - registerEncoder(new Ogg2Mp3()); - } + // audio conversion + registerEncoder(new Ogg2Wav()); + registerEncoder(new Wav2mp3()); + registerEncoder(new Ogg2Mp3()); + } - public List getEncoders(final String sourceFormat, final String targetFormat) { + public List getEncoders(final String sourceFormat, + final String targetFormat) { - final String sourceFormatLowerCase = sourceFormat.toLowerCase(); - final String targetFormatLowerCase = targetFormat.toLowerCase(); + final String sourceFormatLowerCase = sourceFormat.toLowerCase(); + final String targetFormatLowerCase = targetFormat.toLowerCase(); - final ArrayList encoders = new ArrayList(); + final ArrayList encoders = new ArrayList(); - for (final Converter encoder : this.encoders) { - if (encoder.getSourceFileExtension().equals(sourceFormatLowerCase)) { - if (encoder.getTargetFileExtension().equals(targetFormatLowerCase)) { - encoders.add(encoder); - return encoders; - } - } - } + for (final Converter encoder : this.encoders) { + if (encoder.getSourceFileExtension().equals(sourceFormatLowerCase)) { + if (encoder.getTargetFileExtension().equals( + targetFormatLowerCase)) { + encoders.add(encoder); + return encoders; + } + } + } - return encoders; - } + return encoders; + } - public void registerEncoder(final Converter encoder) { - encoders.add(encoder); - } + public void registerEncoder(final Converter encoder) { + encoders.add(encoder); + } } diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mkv2Mp4.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mkv2Mp4.java new file mode 100644 index 0000000..dba7a1e --- /dev/null +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mkv2Mp4.java @@ -0,0 +1,78 @@ +/* + * Meviz - Various tools collection to work with multimedia. + * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation. + */ + +package eu.svjatoslav.meviz.encoder.converters; + +import java.io.File; + +import eu.svjatoslav.meviz.encoder.EncodingOptions; + +public class Mkv2Mp4 implements Converter { + + @Override + public String getCommand(final File inputFile, final File targetFile, + final EncodingOptions options) { + + int videoBitrate; + int audioBitrate; + + switch (options.videoBitrate) { + case LOW: + videoBitrate = 1000; + audioBitrate = 128; + break; + + case MEDIUM: + videoBitrate = 3500; + audioBitrate = 128; + break; + + case HIGH: + videoBitrate = 15000; + audioBitrate = 500; + break; + + default: + throw new RuntimeException("Video bitrate: " + options.videoBitrate + + " is not supported."); + } + + // convert + final StringBuffer codecParams = new StringBuffer(); + + codecParams.append("-acodec libmp3lame -vcodec libx264"); + + codecParams.append(" -b " + videoBitrate + "k"); + codecParams.append(" -b:a " + audioBitrate + "k"); + + if (options.deinterlace) { + codecParams.append(" -filter:v yadif"); + } + + return "avconv -i \"" + inputFile.getAbsolutePath() + "\" " + + codecParams.toString() + " \"" + targetFile.getAbsolutePath() + + "\""; + } + + @Override + public String getSourceFileExtension() { + return "mkv"; + } + + @Override + public String getTargetFileExtension() { + return "mp4"; + } + + @Override + public boolean isTerminalMandatory() { + return true; + } + +}