fixed source vs target
[meviz.git] / src / main / java / eu / svjatoslav / meviz / encoder / converters / Mts2Mp4.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.BitrateParameter;
15 import eu.svjatoslav.meviz.encoder.EncodingOptions;
16
17 public class Mts2Mp4 implements Converter {
18
19         @Override
20         public String getCommand(final File inputFile, final File targetFile,
21                         final EncodingOptions options) {
22
23                 int videoBitrate = 0;
24                 int audioBitrate = 0;
25
26                 switch (options.videoBitrate) {
27                 case LOW:
28                         videoBitrate = 1000;
29                         audioBitrate = 128;
30                         break;
31
32                 case MEDIUM:
33                         videoBitrate = 3500;
34                         audioBitrate = 128;
35                         break;
36
37                 case HIGH:
38                         videoBitrate = 15000;
39                         audioBitrate = 500;
40                         break;
41
42                 case COPY:
43                         break;
44
45                 default:
46                         throw new RuntimeException("Video bitrate: " + options.videoBitrate
47                                         + " is not supported.");
48                 }
49
50                 // convert
51                 final StringBuffer codecParams = new StringBuffer();
52
53                 if (options.videoBitrate == BitrateParameter.bitrate.COPY) {
54                         // pass through
55                         codecParams.append("-acodec copy -vcodec copy");
56
57                 } else {
58                         codecParams.append("-acodec libmp3lame -vcodec libx264");
59                         codecParams.append(" -b " + videoBitrate + "k");
60                         codecParams.append(" -b:a " + audioBitrate + "k");
61                 }
62
63                 if (options.deinterlace) {
64                         codecParams.append(" -filter:v yadif");
65                 }
66
67                 return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
68                                 + codecParams.toString() + " \"" + targetFile.getAbsolutePath()
69                                 + "\"";
70         }
71
72         @Override
73         public String getSourceFileExtension() {
74                 return "mts";
75         }
76
77         @Override
78         public String getTargetFileExtension() {
79                 return "mp4";
80         }
81
82         @Override
83         public boolean isTerminalMandatory() {
84                 return true;
85         }
86
87 }