possibility to specify bitrate for MTS to MP4 converter
[meviz.git] / src / main / java / eu / svjatoslav / meviz / encoder / converters / Mts2Mp4.java
index decab0e..9ea8da7 100755 (executable)
@@ -18,38 +18,48 @@ public class Mts2Mp4 implements Converter {
        @Override
        public String getCommand(final File inputFile, final File targetFile,
                        final EncodingOptions options) {
-               //
-               // int videoBitrate;
-               //
-               // switch (options.videoBitrate) {
-               // case LOW:
-               // videoBitrate = 3000;
-               // break;
-               //
-               // case MEDIUM:
-               // videoBitrate = 7000;
-               // break;
-               //
-               // case HIGH:
-               // videoBitrate = 15000;
-               // break;
-               //
-               // default:
-               // throw new RuntimeException("Video bitrate: " + options.videoBitrate
-               // + " is not supported.");
-               // }
+
+               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 String codecParams =
-               // "-acodec libmp3lame -vcodec libx264 -b 10000k -b:a 500k -filter:v yadif";
+               final StringBuffer codecParams = new StringBuffer();
+
+               codecParams.append("-acodec libmp3lame -vcodec libx264");
+
+               codecParams.append(" -b " + videoBitrate + "k");
+               codecParams.append(" -b:a " + audioBitrate + "k");
 
-               final String codecParams = "-acodec libmp3lame -vcodec libx264 -b 3500k -b:a 128k";
+               if (options.deinterlace)
+                       codecParams.append(" -filter:v yadif");
 
                // pass through
                // final String codecParams = "-acodec copy -vcodec copy";
 
                return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
-                               + codecParams + " \"" + targetFile.getAbsolutePath() + "\"";
+                               + codecParams.toString() + " \"" + targetFile.getAbsolutePath()
+                               + "\"";
        }
 
        @Override