From: Svjatoslav Agejenko Date: Fri, 19 Dec 2014 22:04:33 +0000 (+0200) Subject: possibility to specify video and audio bitrate separately X-Git-Tag: meviz-1.0~39 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=07420c65400942de5b5397ce179df7ee3fa5d994;p=meviz.git possibility to specify video and audio bitrate separately --- diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java index ec7d9cd..ff4b8ec 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java @@ -83,13 +83,10 @@ public class CommandlineHandler { options.forPortablePlayer = forPortableParameter.isParameterSpecified(); if (videoBitrateParameter.isParameterSpecified()) - try { - options.setVideoBitrate(videoBitrateParameter.getValue()); - } catch (final Exception e) { - System.out - .println("Invalid video bitrate. Valid values are: LOW, MEDIUM, HIGH."); - return null; - } + options.setVideoBitrate(videoBitrateParameter.getValue()); + + if (audioBitrateParameter.isParameterSpecified()) + options.setAudioBitrate(audioBitrateParameter.getValue()); return options; } 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 2cda2d8..87a7880 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java @@ -12,6 +12,7 @@ package eu.svjatoslav.meviz.encoder.converters; import java.io.File; import java.util.List; +import eu.svjatoslav.meviz.encoder.BitrateParameter; import eu.svjatoslav.meviz.encoder.BitrateParameter.bitrate; import eu.svjatoslav.meviz.encoder.EncodingOptions; @@ -35,36 +36,32 @@ public class AvconvVideo extends AbstractConverter { codecParams.append("-filter:v yadif "); } - @Override - public String getCommand(final File inputFile, final File targetFile, - final EncodingOptions options) { - - int videoBitrate = -1; - int audioBitrate = -1; - - switch (options.getVideoBitrate()) { + private int getAudioBitrateValue(final BitrateParameter.bitrate bitRate) { + switch (bitRate) { case LOW: - videoBitrate = 1000; - audioBitrate = 128; - break; + return 128; case MEDIUM: - videoBitrate = 4000; - audioBitrate = 192; - break; + return 160; case HIGH: - videoBitrate = 40000; - audioBitrate = 500; - break; + return 320; case COPY: - break; + return -1; default: - throw new RuntimeException("Video bitrate: " + options.getVideoBitrate() + throw new RuntimeException("Audio bitrate: " + bitRate + " is not supported."); } + } + + @Override + public String getCommand(final File inputFile, final File targetFile, + final EncodingOptions options) { + + int videoBitrate = getVideoBitrateValue(options.getVideoBitrate()); + int audioBitrate = getAudioBitrateValue(options.getAudioBitrate()); // convert final StringBuffer codecParams = new StringBuffer(); @@ -72,10 +69,11 @@ public class AvconvVideo extends AbstractConverter { String videoCodec = "libx264"; String audioCodec = "libmp3lame"; - if (options.getVideoBitrate() == bitrate.COPY) { + if (options.getVideoBitrate() == bitrate.COPY) videoCodec = "copy"; + + if (options.getAudioBitrate() == bitrate.COPY) audioCodec = "copy"; - } if (options.forPortablePlayer) { videoBitrate = 1000; @@ -102,6 +100,26 @@ public class AvconvVideo extends AbstractConverter { return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v"); } + private int getVideoBitrateValue(final BitrateParameter.bitrate bitRate) { + switch (bitRate) { + case LOW: + return 1000; + + case MEDIUM: + return 4000; + + case HIGH: + return 40000; + + case COPY: + return -1; + + default: + throw new RuntimeException("Video bitrate: " + bitRate + + " is not supported."); + } + } + @Override public boolean isTerminalMandatory() { return true;