From 1d9057cc722b349a0bc370c0860344f59c42fd0f Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 14 Dec 2014 22:21:57 +0200 Subject: [PATCH] support for copy codec for avconv --- .../meviz/encoder/BitrateParameter.java | 2 +- .../meviz/encoder/converters/AvconvVideo.java | 49 ++++++++++++++----- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java b/src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java index c8aa863..6e3ade7 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java @@ -47,7 +47,7 @@ public class BitrateParameter extends Parameter { @Override public boolean validate(final String value) { try { - bitrate.valueOf(value); + bitrate.valueOf(value.toUpperCase()); } catch (final IllegalArgumentException exception) { return false; } 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 7687ac4..db6ab4d 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java @@ -12,16 +12,35 @@ package eu.svjatoslav.meviz.encoder.converters; import java.io.File; import java.util.List; +import eu.svjatoslav.meviz.encoder.BitrateParameter.bitrate; import eu.svjatoslav.meviz.encoder.EncodingOptions; public class AvconvVideo extends AbstractConverter { + private void constructCodecParamsString(final EncodingOptions options, + final int videoBitrate, final int audioBitrate, + final StringBuffer codecParams, final String videoCodec, + final String audioCodec) { + + codecParams.append("-acodec " + audioCodec + " -vcodec " + videoCodec + + " "); + + if (videoBitrate != -1) + codecParams.append("-b " + videoBitrate + "k "); + + if (audioBitrate != -1) + codecParams.append("-b:a " + audioBitrate + "k "); + + if (options.deinterlace) + codecParams.append("-filter:v yadif "); + } + @Override public String getCommand(final File inputFile, final File targetFile, final EncodingOptions options) { - int videoBitrate; - int audioBitrate; + int videoBitrate = -1; + int audioBitrate = -1; switch (options.videoBitrate) { case LOW: @@ -39,6 +58,9 @@ public class AvconvVideo extends AbstractConverter { audioBitrate = 500; break; + case COPY: + break; + default: throw new RuntimeException("Video bitrate: " + options.videoBitrate + " is not supported."); @@ -47,26 +69,27 @@ public class AvconvVideo extends AbstractConverter { // convert final StringBuffer codecParams = new StringBuffer(); - String videoCodec = "libx264 "; + String videoCodec = "libx264"; + String audioCodec = "libmp3lame"; + + if (options.videoBitrate == bitrate.COPY) { + videoCodec = "copy"; + audioCodec = "copy"; + } if (options.forPortablePlayer) { videoBitrate = 1000; audioBitrate = 128; - videoCodec = "libxvid "; + 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 "); + constructCodecParamsString(options, videoBitrate, audioBitrate, + codecParams, videoCodec, audioCodec); return "avconv -i \"" + inputFile.getAbsolutePath() + "\" " - + codecParams.toString() + "\"" + targetFile.getAbsolutePath() - + "\""; + + codecParams.toString() + "\"" + targetFile.getAbsolutePath() + + "\""; } @Override -- 2.20.1