possibility to quickly encode video for portable players
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 31 Dec 2013 14:25:14 +0000 (16:25 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 31 Dec 2013 14:25:14 +0000 (16:25 +0200)
src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java
src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java
src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java
src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java

index b6e10ce..ba54599 100755 (executable)
@@ -31,6 +31,9 @@ public class CommandlineHandler {
        NullParameter recursiveParameter = parser.createNullParameter(
                        "Enable recursive mode.").addAliases("-r", "--recursive");
 
+       NullParameter forPortableParameter = parser.createNullParameter(
+                       "Encode for portable player.").addAliases("-p", "--portable");
+
        StringParameter inputPatternParameter = parser
                        .createStringParameter("File input pattern.")
                        .addAliases("-i", "--input-pattern").setMandatory();
@@ -58,14 +61,11 @@ public class CommandlineHandler {
 
                parser.parse(args);
 
-               if (recursiveParameter.isParameterSpecified())
-                       options.recursive = true;
+               options.recursive = recursiveParameter.isParameterSpecified();
 
-               if (deinterlaceParameter.isParameterSpecified())
-                       options.deinterlace = true;
+               options.deinterlace = deinterlaceParameter.isParameterSpecified();
 
-               if (testParameter.isParameterSpecified())
-                       options.testOnly = true;
+               options.testOnly = testParameter.isParameterSpecified();
 
                if (outputFormatParameter.isParameterSpecified())
                        options.outputFormats.addAll(outputFormatParameter
@@ -79,6 +79,8 @@ public class CommandlineHandler {
                        options.inputPatterns.addAll(inputPatternParameter
                                        .getArgumentsAsStrings());
 
+               options.forPortablePlayer = forPortableParameter.isParameterSpecified();
+
                if (videoBitrateParameter.isParameterSpecified())
                        try {
                                options.videoBitrate = videoBitrateParameter.getValue();
index 463b48a..9e7f2b4 100755 (executable)
@@ -25,6 +25,8 @@ public class EncodingOptions {
 
        public boolean testOnly;
 
+       public boolean forPortablePlayer = false;
+
        public File workingDirectory = new File(System.getProperty("user.dir"));
 
        List<String> outputFormats = new ArrayList<String>();
index 0d8bc8e..2d6a788 100755 (executable)
@@ -12,14 +12,14 @@ package eu.svjatoslav.meviz.encoder;
 import java.util.ArrayList;
 import java.util.List;
 
-import eu.svjatoslav.meviz.encoder.converters.Ffmpeg2theora;
 import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
-import eu.svjatoslav.meviz.encoder.converters.AvconvVideo;
-import eu.svjatoslav.meviz.encoder.converters.Ffmpeg;
 import eu.svjatoslav.meviz.encoder.converters.AvconvAudio;
-import eu.svjatoslav.meviz.encoder.converters.Ogg2Wav;
+import eu.svjatoslav.meviz.encoder.converters.AvconvVideo;
 import eu.svjatoslav.meviz.encoder.converters.Convert;
+import eu.svjatoslav.meviz.encoder.converters.Ffmpeg;
+import eu.svjatoslav.meviz.encoder.converters.Ffmpeg2theora;
 import eu.svjatoslav.meviz.encoder.converters.Flac;
+import eu.svjatoslav.meviz.encoder.converters.Ogg2Wav;
 
 public class FormatsRegistry {
 
index c63837a..de295ca 100644 (file)
@@ -47,27 +47,36 @@ public class AvconvVideo extends AbstractConverter {
                // convert
                final StringBuffer codecParams = new StringBuffer();
 
-               codecParams.append("-acodec libmp3lame -vcodec libx264");
+               String videoCodec = "libx264 ";
 
-               codecParams.append(" -b " + videoBitrate + "k");
-               codecParams.append(" -b:a " + audioBitrate + "k");
+               if (options.forPortablePlayer) {
+                       videoBitrate = 1000;
+                       audioBitrate = 128;
+                       videoCodec = "libxvid ";
+                       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");
+                       codecParams.append("-filter:v yadif ");
 
                return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
-                               + codecParams.toString() + " \"" + targetFile.getAbsolutePath()
+                               + codecParams.toString() + "\"" + targetFile.getAbsolutePath()
                                + "\"";
        }
 
        @Override
        public List<String> getSourceFileExtensions() {
-               return toList("mkv", "mts");
+               return toList("mkv", "mts", "mp4", "avi");
        }
 
        @Override
        public List<String> getTargetFileExtensions() {
-               return toList("mp4");
+               return toList("mkv", "mts", "mp4", "avi");
        }
 
        @Override