From a46bdb8da875d21b3598412470d25b727a9baa04 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 13 Jul 2013 14:34:35 +0300 Subject: [PATCH] possibility to specify bitrate for MTS to MP4 converter --- .../meviz/encoder/CommandlineHandler.java | 8 +++ .../meviz/encoder/EncodingOptions.java | 18 +++--- .../meviz/encoder/converters/Mts2Mp4.java | 58 +++++++++++-------- 3 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java index fbde5c5..eb2ac08 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java @@ -22,6 +22,9 @@ public class CommandlineHandler { Parameter terminalParameter = new Parameter("Enable popup terminal.", "--terminal"); + Parameter deinterlaceParameter = new Parameter("Deinterlace video.", + "--deinterlace", "-d"); + Parameter testParameter = new Parameter("Simulate file encoding.", "-t", "--test"); @@ -47,6 +50,8 @@ public class CommandlineHandler { parser.addParameter(recursiveParameter); + parser.addParameter(deinterlaceParameter); + parser.addParameter(testParameter); parser.addParameter(terminalParameter); @@ -77,6 +82,9 @@ public class CommandlineHandler { if (recursiveParameter.isParameterSpecified()) options.recursive = true; + if (deinterlaceParameter.isParameterSpecified()) + options.deinterlace = true; + if (terminalParameter.isParameterSpecified()) options.terminal = true; diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java index d9df4bd..a2f09d8 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java @@ -15,20 +15,22 @@ import java.util.List; public class EncodingOptions { - public Bitrate.bitrate videoBitrate = Bitrate.bitrate.MEDIUM; + public Bitrate.bitrate videoBitrate = Bitrate.bitrate.MEDIUM; - public Bitrate audioBitrate; + // public Bitrate audioBitrate; - public boolean recursive; + public boolean deinterlace = false; - public boolean terminal; + public boolean recursive; - public boolean testOnly; + public boolean terminal; - public File workingDirectory = new File(System.getProperty("user.dir")); + public boolean testOnly; - List outputFormats = new ArrayList(); + public File workingDirectory = new File(System.getProperty("user.dir")); - List inputPatterns = new ArrayList(); + List outputFormats = new ArrayList(); + + List inputPatterns = new ArrayList(); } diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mp4.java b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mp4.java index decab0e..9ea8da7 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mp4.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/Mts2Mp4.java @@ -18,38 +18,48 @@ public class Mts2Mp4 implements Converter { @Override public String getCommand(final File inputFile, final File targetFile, final EncodingOptions options) { - // - // int videoBitrate; - // - // switch (options.videoBitrate) { - // case LOW: - // videoBitrate = 3000; - // break; - // - // case MEDIUM: - // videoBitrate = 7000; - // break; - // - // case HIGH: - // videoBitrate = 15000; - // break; - // - // default: - // throw new RuntimeException("Video bitrate: " + options.videoBitrate - // + " is not supported."); - // } + + int videoBitrate; + int audioBitrate; + + switch (options.videoBitrate) { + case LOW: + videoBitrate = 1000; + audioBitrate = 128; + break; + + case MEDIUM: + videoBitrate = 3500; + audioBitrate = 128; + break; + + case HIGH: + videoBitrate = 15000; + audioBitrate = 500; + break; + + default: + throw new RuntimeException("Video bitrate: " + options.videoBitrate + + " is not supported."); + } // convert - // final String codecParams = - // "-acodec libmp3lame -vcodec libx264 -b 10000k -b:a 500k -filter:v yadif"; + final StringBuffer codecParams = new StringBuffer(); + + codecParams.append("-acodec libmp3lame -vcodec libx264"); + + codecParams.append(" -b " + videoBitrate + "k"); + codecParams.append(" -b:a " + audioBitrate + "k"); - final String codecParams = "-acodec libmp3lame -vcodec libx264 -b 3500k -b:a 128k"; + if (options.deinterlace) + codecParams.append(" -filter:v yadif"); // pass through // final String codecParams = "-acodec copy -vcodec copy"; return "avconv -i \"" + inputFile.getAbsolutePath() + "\" " - + codecParams + " \"" + targetFile.getAbsolutePath() + "\""; + + codecParams.toString() + " \"" + targetFile.getAbsolutePath() + + "\""; } @Override -- 2.20.1