From be2283b8b8302dd02cf60726bdc2d45f0bfaf255 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Thu, 25 Jun 2015 20:18:20 +0300 Subject: [PATCH] possibility to change video framerate --- .../meviz/encoder/CommandlineHandler.java | 14 +++- .../meviz/encoder/EncodingOptions.java | 74 ++++++++++--------- .../meviz/encoder/converters/AvconvVideo.java | 9 ++- 3 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java index d6282c2..5a6ecbd 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java @@ -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()); diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java index 9721cdc..419aae4 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java @@ -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 getInputPatterns() { return inputPatterns; } - public void setInputPatterns(List inputPatterns) { - this.inputPatterns = inputPatterns; - } - public List getOutputFormats() { return outputFormats; } - public void setOutputFormats(List 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 inputPatterns) { + this.inputPatterns = inputPatterns; + } + + public void setOutputFormats(final List 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; } } diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java index 3d3393b..4d2743a 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java @@ -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; -- 2.20.1