possibility to change video framerate
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 25 Jun 2015 17:18:20 +0000 (20:18 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 25 Jun 2015 17:18:20 +0000 (20:18 +0300)
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/converters/AvconvVideo.java

index d6282c2..5a6ecbd 100755 (executable)
@@ -11,6 +11,7 @@ package eu.svjatoslav.meviz.encoder;
 
 import eu.svjatoslav.commons.commandline.parameterparser.Parser;
 import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter;
+import eu.svjatoslav.commons.commandline.parameterparser.parameter.IntegerParameter;
 import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter;
 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameters;
 
@@ -22,9 +23,12 @@ public class CommandlineHandler {
                        .add(new StringParameters("Encoding output format."))
                        .addAliases("-o", "--output-format").setMandatory();
 
+       IntegerParameter targetFramerate = parser.add(new IntegerParameter(
+                       "Target framerate.").addAliases("-f", "--target-frame"));
+
        NullParameter deinterlaceParameter = parser.add(
-                       new NullParameter("Deinterlace video.")).addAliases(
-                       "--deinterlace", "-d");
+                       new NullParameter("Deinterlace video.")).addAliases("-d",
+                       "--deinterlace");
 
        NullParameter testParameter = parser.add(
                        new NullParameter("Simulate file encoding.")).addAliases("-t",
@@ -74,13 +78,17 @@ public class CommandlineHandler {
                if (outputFormatParameter.isParameterSpecified())
                        options.getOutputFormats().addAll(outputFormatParameter.getValue());
 
+               if (targetFramerate.isParameterSpecified())
+                       options.setTargetFps(targetFramerate.getValue());
+
                if (workingDirectoryParameter.isParameterSpecified())
                        options.setWorkingDirectory(workingDirectoryParameter.getValue());
 
                if (inputPatternParameter.isParameterSpecified())
                        options.getInputPatterns().addAll(inputPatternParameter.getValue());
 
-               options.setForPortablePlayer(forPortableParameter.isParameterSpecified());
+               options.setForPortablePlayer(forPortableParameter
+                               .isParameterSpecified());
 
                if (videoBitrateParameter.isParameterSpecified())
                        options.setVideoBitrate(videoBitrateParameter.getValue());
index 9721cdc..419aae4 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright (C) 2012-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
@@ -19,7 +19,7 @@ public class EncodingOptions {
 
        private BitrateParameter.bitrate audioBitrate = BitrateParameter.bitrate.MEDIUM;
 
-       // public Bitrate audioBitrate;
+       private Integer targetFps;
 
        private boolean deinterlace = false;
 
@@ -39,72 +39,80 @@ public class EncodingOptions {
                return audioBitrate;
        }
 
-       public BitrateParameter.bitrate getVideoBitrate() {
-               return videoBitrate;
-       }
-
-       public void setAudioBitrate(final BitrateParameter.bitrate audioBitrate) {
-               this.audioBitrate = audioBitrate;
-       }
-
-       public void setVideoBitrate(final BitrateParameter.bitrate videoBitrate) {
-               this.videoBitrate = videoBitrate;
-       }
-
        public List<String> getInputPatterns() {
                return inputPatterns;
        }
 
-       public void setInputPatterns(List<String> inputPatterns) {
-               this.inputPatterns = inputPatterns;
-       }
-
        public List<String> getOutputFormats() {
                return outputFormats;
        }
 
-       public void setOutputFormats(List<String> outputFormats) {
-               this.outputFormats = outputFormats;
+       public Integer getTargetFps() {
+               return targetFps;
+       }
+
+       public BitrateParameter.bitrate getVideoBitrate() {
+               return videoBitrate;
        }
 
        public File getWorkingDirectory() {
                return workingDirectory;
        }
 
-       public void setWorkingDirectory(File workingDirectory) {
-               this.workingDirectory = workingDirectory;
+       public boolean isDeinterlace() {
+               return deinterlace;
        }
 
        public boolean isForPortablePlayer() {
                return forPortablePlayer;
        }
 
-       public void setForPortablePlayer(boolean forPortablePlayer) {
-               this.forPortablePlayer = forPortablePlayer;
+       public boolean isRecursive() {
+               return recursive;
        }
 
        public boolean isTestOnly() {
                return testOnly;
        }
 
-       public void setTestOnly(boolean testOnly) {
-               this.testOnly = testOnly;
+       public void setAudioBitrate(final BitrateParameter.bitrate audioBitrate) {
+               this.audioBitrate = audioBitrate;
        }
 
-       public boolean isRecursive() {
-               return recursive;
+       public void setDeinterlace(final boolean deinterlace) {
+               this.deinterlace = deinterlace;
+       }
+
+       public void setForPortablePlayer(final boolean forPortablePlayer) {
+               this.forPortablePlayer = forPortablePlayer;
+       }
+
+       public void setInputPatterns(final List<String> inputPatterns) {
+               this.inputPatterns = inputPatterns;
+       }
+
+       public void setOutputFormats(final List<String> outputFormats) {
+               this.outputFormats = outputFormats;
        }
 
-       public void setRecursive(boolean recursive) {
+       public void setRecursive(final boolean recursive) {
                this.recursive = recursive;
        }
 
-       public boolean isDeinterlace() {
-               return deinterlace;
+       public void setTargetFps(final Integer targetFps) {
+               this.targetFps = targetFps;
        }
 
-       public void setDeinterlace(boolean deinterlace) {
-               this.deinterlace = deinterlace;
+       public void setTestOnly(final boolean testOnly) {
+               this.testOnly = testOnly;
+       }
+
+       public void setVideoBitrate(final BitrateParameter.bitrate videoBitrate) {
+               this.videoBitrate = videoBitrate;
+       }
+
+       public void setWorkingDirectory(final File workingDirectory) {
+               this.workingDirectory = workingDirectory;
        }
 
 }
index 3d3393b..4d2743a 100644 (file)
@@ -22,7 +22,7 @@ public class AvconvVideo extends AbstractConverter {
                        final int videoBitrate, final int audioBitrate,
                        final String videoCodec, final String audioCodec) {
 
-               StringBuffer codecParams = new StringBuffer();
+               final StringBuffer codecParams = new StringBuffer();
 
                if (audioCodec == null)
                        codecParams.append("-an ");
@@ -40,6 +40,9 @@ public class AvconvVideo extends AbstractConverter {
                if (options.isDeinterlace())
                        codecParams.append("-filter:v yadif ");
 
+               if (options.getTargetFps() != null)
+                       codecParams.append("-r " + options.getTargetFps() + " ");
+
                return codecParams.toString();
        }
 
@@ -68,7 +71,7 @@ public class AvconvVideo extends AbstractConverter {
 
        @Override
        public String getCommand(final File inputFile, final File targetFile,
-                       final EncodingOptions options, String targetFormat) {
+                       final EncodingOptions options, final String targetFormat) {
 
                int videoBitrate = getVideoBitrateValue(options.getVideoBitrate());
                int audioBitrate = getAudioBitrateValue(options.getAudioBitrate());
@@ -135,7 +138,7 @@ public class AvconvVideo extends AbstractConverter {
                        return 4000;
 
                case HIGH:
-                       return 40000;
+                       return 16000;
 
                case COPY:
                        return -1;