+/*
+ * 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;
+ }
+
+}