mkv to mp4 conversion
[meviz.git] / src / main / java / eu / svjatoslav / meviz / encoder / converters / Mkv2Mp4.java
1 /*
2  * Meviz - Various tools collection to work with multimedia.
3  * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public License
7  * as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.meviz.encoder.converters;
11
12 import java.io.File;
13
14 import eu.svjatoslav.meviz.encoder.EncodingOptions;
15
16 public class Mkv2Mp4 implements Converter {
17
18         @Override
19         public String getCommand(final File inputFile, final File targetFile,
20                         final EncodingOptions options) {
21
22                 int videoBitrate;
23                 int audioBitrate;
24
25                 switch (options.videoBitrate) {
26                 case LOW:
27                         videoBitrate = 1000;
28                         audioBitrate = 128;
29                         break;
30
31                 case MEDIUM:
32                         videoBitrate = 3500;
33                         audioBitrate = 128;
34                         break;
35
36                 case HIGH:
37                         videoBitrate = 15000;
38                         audioBitrate = 500;
39                         break;
40
41                 default:
42                         throw new RuntimeException("Video bitrate: " + options.videoBitrate
43                                         + " is not supported.");
44                 }
45
46                 // convert
47                 final StringBuffer codecParams = new StringBuffer();
48
49                 codecParams.append("-acodec libmp3lame -vcodec libx264");
50
51                 codecParams.append(" -b " + videoBitrate + "k");
52                 codecParams.append(" -b:a " + audioBitrate + "k");
53
54                 if (options.deinterlace) {
55                         codecParams.append(" -filter:v yadif");
56                 }
57
58                 return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
59                                 + codecParams.toString() + " \"" + targetFile.getAbsolutePath()
60                                 + "\"";
61         }
62
63         @Override
64         public String getSourceFileExtension() {
65                 return "mkv";
66         }
67
68         @Override
69         public String getTargetFileExtension() {
70                 return "mp4";
71         }
72
73         @Override
74         public boolean isTerminalMandatory() {
75                 return true;
76         }
77
78 }