possibility to specify bitrate for MTS to MP4 converter
[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.EncodingOptions;
15
16 public class Mts2Mp4 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                 // pass through
58                 // final String codecParams = "-acodec copy -vcodec copy";
59
60                 return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
61                                 + codecParams.toString() + " \"" + targetFile.getAbsolutePath()
62                                 + "\"";
63         }
64
65         @Override
66         public String getSourceFileExtension() {
67                 return "mts";
68         }
69
70         @Override
71         public String getTargetFileExtension() {
72                 return "mp4";
73         }
74
75         @Override
76         public boolean isTerminalMandatory() {
77                 return true;
78         }
79
80 }