X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fmeviz%2Fencoder%2Fconverters%2FAvconvVideo.java;h=ea4d1d3444f7447e199b4af9b52c5fe666b61d7e;hb=99240fb3b40e8dd7e3759d2b81ae9a4b05fae1b5;hp=87a7880ac603724707b52673761acfc62f4b90ba;hpb=07420c65400942de5b5397ce179df7ee3fa5d994;p=meviz.git 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 87a7880..ea4d1d3 100644 --- a/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/converters/AvconvVideo.java @@ -18,13 +18,18 @@ import eu.svjatoslav.meviz.encoder.EncodingOptions; public class AvconvVideo extends AbstractConverter { - private void constructCodecParamsString(final EncodingOptions options, + private String constructCodecParamsString(final EncodingOptions options, final int videoBitrate, final int audioBitrate, - final StringBuffer codecParams, final String videoCodec, - final String audioCodec) { + final String videoCodec, final String audioCodec) { - codecParams.append("-acodec " + audioCodec + " -vcodec " + videoCodec - + " "); + StringBuffer codecParams = new StringBuffer(); + + if (audioCodec == null) + codecParams.append("-an "); + else + codecParams.append("-acodec " + audioCodec + " "); + + codecParams.append("-vcodec " + videoCodec + " "); if (videoBitrate != -1) codecParams.append("-b " + videoBitrate + "k "); @@ -34,6 +39,8 @@ public class AvconvVideo extends AbstractConverter { if (options.deinterlace) codecParams.append("-filter:v yadif "); + + return codecParams.toString(); } private int getAudioBitrateValue(final BitrateParameter.bitrate bitRate) { @@ -50,6 +57,9 @@ public class AvconvVideo extends AbstractConverter { case COPY: return -1; + case NONE: + return -1; + default: throw new RuntimeException("Audio bitrate: " + bitRate + " is not supported."); @@ -58,7 +68,7 @@ public class AvconvVideo extends AbstractConverter { @Override public String getCommand(final File inputFile, final File targetFile, - final EncodingOptions options) { + final EncodingOptions options, String targetFormat) { int videoBitrate = getVideoBitrateValue(options.getVideoBitrate()); int audioBitrate = getAudioBitrateValue(options.getAudioBitrate()); @@ -69,21 +79,35 @@ public class AvconvVideo extends AbstractConverter { String videoCodec = "libx264"; String audioCodec = "libmp3lame"; + if (targetFormat.equals("webm")) { + videoCodec = "vp8"; + audioCodec = "opus"; + codecParams.append("-s 800x600 "); + } + if (options.getVideoBitrate() == bitrate.COPY) videoCodec = "copy"; if (options.getAudioBitrate() == bitrate.COPY) audioCodec = "copy"; + if (options.getAudioBitrate() == bitrate.NONE) + audioCodec = null; + if (options.forPortablePlayer) { videoBitrate = 1000; audioBitrate = 128; videoCodec = "libxvid"; + + // reduce resolution codecParams.append("-s 640x480 "); + + // enforce maximum keyframe interval + codecParams.append("-g 150 "); } - constructCodecParamsString(options, videoBitrate, audioBitrate, - codecParams, videoCodec, audioCodec); + codecParams.append(constructCodecParamsString(options, videoBitrate, + audioBitrate, videoCodec, audioCodec)); return "avconv -i \"" + inputFile.getAbsolutePath() + "\" " + codecParams.toString() + "\"" + targetFile.getAbsolutePath() @@ -92,12 +116,14 @@ public class AvconvVideo extends AbstractConverter { @Override public List getSourceFileExtensions() { - return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v"); + return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v", + "webm"); } @Override public List getTargetFileExtensions() { - return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v"); + return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v", + "webm"); } private int getVideoBitrateValue(final BitrateParameter.bitrate bitRate) {