From 64e6f0bfee5ada06170af9f01cc3d8ec42216ef5 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Tue, 31 Dec 2013 16:25:14 +0200 Subject: [PATCH] possibility to quickly encode video for portable players --- .../meviz/encoder/CommandlineHandler.java | 14 ++++++----- .../meviz/encoder/EncodingOptions.java | 2 ++ .../meviz/encoder/FormatsRegistry.java | 8 +++---- .../meviz/encoder/converters/AvconvVideo.java | 23 +++++++++++++------ 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java index b6e10ce..ba54599 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java @@ -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(); diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java index 463b48a..9e7f2b4 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java @@ -25,6 +25,8 @@ public class EncodingOptions { public boolean testOnly; + public boolean forPortablePlayer = false; + public File workingDirectory = new File(System.getProperty("user.dir")); List outputFormats = new ArrayList(); diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java b/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java index 0d8bc8e..2d6a788 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/FormatsRegistry.java @@ -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 { 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 c63837a..de295ca 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java @@ -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 getSourceFileExtensions() { - return toList("mkv", "mts"); + return toList("mkv", "mts", "mp4", "avi"); } @Override public List getTargetFileExtensions() { - return toList("mp4"); + return toList("mkv", "mts", "mp4", "avi"); } @Override -- 2.20.1