possibility to use stream COPY
[meviz.git] / src / main / java / eu / svjatoslav / meviz / encoder / converters / Mts2Mp4.java
index c2c712d..9af415f 100755 (executable)
@@ -11,6 +11,7 @@ package eu.svjatoslav.meviz.encoder.converters;
 
 import java.io.File;
 
+import eu.svjatoslav.meviz.encoder.BitrateParameter;
 import eu.svjatoslav.meviz.encoder.EncodingOptions;
 
 public class Mts2Mp4 implements Converter {
@@ -18,36 +19,54 @@ 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 = 0;
+               int audioBitrate = 0;
+
+               switch (options.videoBitrate) {
+               case LOW:
+                       videoBitrate = 1000;
+                       audioBitrate = 128;
+                       break;
+
+               case MEDIUM:
+                       videoBitrate = 3500;
+                       audioBitrate = 128;
+                       break;
+
+               case HIGH:
+                       videoBitrate = 15000;
+                       audioBitrate = 500;
+                       break;
+
+               case COPY:
+                       break;
+
+               default:
+                       throw new RuntimeException("Video bitrate: " + options.videoBitrate
+                                       + " is not supported.");
+               }
 
                // convert
-               // final String codecParams =
-               // "-acodec libmp3lame -vcodec libx264 -b 3500k -b:a 192k";
+               final StringBuffer codecParams = new StringBuffer();
+
+               if (options.videoBitrate == BitrateParameter.bitrate.COPY) {
+                       // pass through
+                       codecParams.append("-acodec copy -vcodec copy");
+
+               } else {
+                       codecParams.append("-acodec libmp3lame -vcodec libx264");
+                       codecParams.append(" -b " + videoBitrate + "k");
+                       codecParams.append(" -b:a " + audioBitrate + "k");
+               }
 
-               // pass through
-               final String codecParams = "-acodec copy -vcodec copy";
+               if (options.deinterlace) {
+                       codecParams.append(" -filter:v yadif");
+               }
 
                return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
-                               + codecParams + " \"" + targetFile.getAbsolutePath() + "\"";
+                               + codecParams.toString() + " \"" + targetFile.getAbsolutePath()
+                               + "\"";
        }
 
        @Override