support for copy codec for avconv
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 14 Dec 2014 20:21:57 +0000 (22:21 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 14 Dec 2014 20:21:57 +0000 (22:21 +0200)
src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java

index c8aa863..6e3ade7 100755 (executable)
@@ -47,7 +47,7 @@ public class BitrateParameter extends Parameter {
        @Override
        public boolean validate(final String value) {
                try {
        @Override
        public boolean validate(final String value) {
                try {
-                       bitrate.valueOf(value);
+                       bitrate.valueOf(value.toUpperCase());
                } catch (final IllegalArgumentException exception) {
                        return false;
                }
                } catch (final IllegalArgumentException exception) {
                        return false;
                }
index 7687ac4..db6ab4d 100644 (file)
@@ -12,16 +12,35 @@ package eu.svjatoslav.meviz.encoder.converters;
 import java.io.File;
 import java.util.List;
 
 import java.io.File;
 import java.util.List;
 
+import eu.svjatoslav.meviz.encoder.BitrateParameter.bitrate;
 import eu.svjatoslav.meviz.encoder.EncodingOptions;
 
 public class AvconvVideo extends AbstractConverter {
 
 import eu.svjatoslav.meviz.encoder.EncodingOptions;
 
 public class AvconvVideo extends AbstractConverter {
 
+       private void constructCodecParamsString(final EncodingOptions options,
+                       final int videoBitrate, final int audioBitrate,
+                       final StringBuffer codecParams, final String videoCodec,
+                       final String audioCodec) {
+
+               codecParams.append("-acodec " + audioCodec + " -vcodec " + videoCodec
+                               + " ");
+
+               if (videoBitrate != -1)
+                       codecParams.append("-b " + videoBitrate + "k ");
+
+               if (audioBitrate != -1)
+                       codecParams.append("-b:a " + audioBitrate + "k ");
+
+               if (options.deinterlace)
+                       codecParams.append("-filter:v yadif ");
+       }
+
        @Override
        public String getCommand(final File inputFile, final File targetFile,
                        final EncodingOptions options) {
 
        @Override
        public String getCommand(final File inputFile, final File targetFile,
                        final EncodingOptions options) {
 
-               int videoBitrate;
-               int audioBitrate;
+               int videoBitrate = -1;
+               int audioBitrate = -1;
 
                switch (options.videoBitrate) {
                case LOW:
 
                switch (options.videoBitrate) {
                case LOW:
@@ -39,6 +58,9 @@ public class AvconvVideo extends AbstractConverter {
                        audioBitrate = 500;
                        break;
 
                        audioBitrate = 500;
                        break;
 
+               case COPY:
+                       break;
+
                default:
                        throw new RuntimeException("Video bitrate: " + options.videoBitrate
                                        + " is not supported.");
                default:
                        throw new RuntimeException("Video bitrate: " + options.videoBitrate
                                        + " is not supported.");
@@ -47,26 +69,27 @@ public class AvconvVideo extends AbstractConverter {
                // convert
                final StringBuffer codecParams = new StringBuffer();
 
                // convert
                final StringBuffer codecParams = new StringBuffer();
 
-               String videoCodec = "libx264 ";
+               String videoCodec = "libx264";
+               String audioCodec = "libmp3lame";
+
+               if (options.videoBitrate == bitrate.COPY) {
+                       videoCodec = "copy";
+                       audioCodec = "copy";
+               }
 
                if (options.forPortablePlayer) {
                        videoBitrate = 1000;
                        audioBitrate = 128;
 
                if (options.forPortablePlayer) {
                        videoBitrate = 1000;
                        audioBitrate = 128;
-                       videoCodec = "libxvid ";
+                       videoCodec = "libxvid";
                        codecParams.append("-s 640x480 ");
                }
 
                        codecParams.append("-s 640x480 ");
                }
 
-               codecParams.append("-acodec libmp3lame -vcodec " + videoCodec);
-
-               codecParams.append("-b " + videoBitrate + "k ");
-               codecParams.append("-b:a " + audioBitrate + "k ");
-
-               if (options.deinterlace)
-                       codecParams.append("-filter:v yadif ");
+               constructCodecParamsString(options, videoBitrate, audioBitrate,
+                               codecParams, videoCodec, audioCodec);
 
                return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
 
                return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
-                               + codecParams.toString() + "\"" + targetFile.getAbsolutePath()
-                               + "\"";
+               + codecParams.toString() + "\"" + targetFile.getAbsolutePath()
+               + "\"";
        }
 
        @Override
        }
 
        @Override