2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
10 package eu.svjatoslav.meviz.encoder.converters;
13 import java.util.List;
15 import eu.svjatoslav.meviz.encoder.BitrateParameter.bitrate;
16 import eu.svjatoslav.meviz.encoder.EncodingOptions;
18 public class AvconvVideo extends AbstractConverter {
20 private void constructCodecParamsString(final EncodingOptions options,
21 final int videoBitrate, final int audioBitrate,
22 final StringBuffer codecParams, final String videoCodec,
23 final String audioCodec) {
25 codecParams.append("-acodec " + audioCodec + " -vcodec " + videoCodec
28 if (videoBitrate != -1)
29 codecParams.append("-b " + videoBitrate + "k ");
31 if (audioBitrate != -1)
32 codecParams.append("-b:a " + audioBitrate + "k ");
34 if (options.deinterlace)
35 codecParams.append("-filter:v yadif ");
39 public String getCommand(final File inputFile, final File targetFile,
40 final EncodingOptions options) {
42 int videoBitrate = -1;
43 int audioBitrate = -1;
45 switch (options.videoBitrate) {
65 throw new RuntimeException("Video bitrate: " + options.videoBitrate
66 + " is not supported.");
70 final StringBuffer codecParams = new StringBuffer();
72 String videoCodec = "libx264";
73 String audioCodec = "libmp3lame";
75 if (options.videoBitrate == bitrate.COPY) {
80 if (options.forPortablePlayer) {
83 videoCodec = "libxvid";
84 codecParams.append("-s 640x480 ");
87 constructCodecParamsString(options, videoBitrate, audioBitrate,
88 codecParams, videoCodec, audioCodec);
90 return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
91 + codecParams.toString() + "\"" + targetFile.getAbsolutePath()
96 public List<String> getSourceFileExtensions() {
97 return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v");
101 public List<String> getTargetFileExtensions() {
102 return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob");
106 public boolean isTerminalMandatory() {