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;
16 import eu.svjatoslav.meviz.encoder.BitrateParameter.bitrate;
17 import eu.svjatoslav.meviz.encoder.EncodingOptions;
19 public class AvconvVideo extends AbstractConverter {
21 private String constructCodecParamsString(final EncodingOptions options,
22 final int videoBitrate, final int audioBitrate,
23 final String videoCodec, final String audioCodec) {
25 StringBuffer codecParams = new StringBuffer();
27 if (audioCodec == null)
28 codecParams.append("-an ");
30 codecParams.append("-acodec " + audioCodec + " ");
32 codecParams.append("-vcodec " + videoCodec + " ");
34 if (videoBitrate != -1)
35 codecParams.append("-b " + videoBitrate + "k ");
37 if (audioBitrate != -1)
38 codecParams.append("-b:a " + audioBitrate + "k ");
40 if (options.deinterlace)
41 codecParams.append("-filter:v yadif ");
43 return codecParams.toString();
46 private int getAudioBitrateValue(final BitrateParameter.bitrate bitRate) {
64 throw new RuntimeException("Audio bitrate: " + bitRate
65 + " is not supported.");
70 public String getCommand(final File inputFile, final File targetFile,
71 final EncodingOptions options, String targetFormat) {
73 int videoBitrate = getVideoBitrateValue(options.getVideoBitrate());
74 int audioBitrate = getAudioBitrateValue(options.getAudioBitrate());
77 final StringBuffer codecParams = new StringBuffer();
79 String videoCodec = "libx264";
80 String audioCodec = "libmp3lame";
82 if (targetFormat.equals("webm")) {
85 codecParams.append("-s 800x600 ");
88 if (options.getVideoBitrate() == bitrate.COPY)
91 if (options.getAudioBitrate() == bitrate.COPY)
94 if (options.getAudioBitrate() == bitrate.NONE)
97 if (options.forPortablePlayer) {
100 videoCodec = "libxvid";
101 codecParams.append("-s 640x480 ");
104 codecParams.append(constructCodecParamsString(options, videoBitrate,
105 audioBitrate, videoCodec, audioCodec));
107 return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
108 + codecParams.toString() + "\"" + targetFile.getAbsolutePath()
113 public List<String> getSourceFileExtensions() {
114 return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v",
119 public List<String> getTargetFileExtensions() {
120 return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v",
124 private int getVideoBitrateValue(final BitrateParameter.bitrate bitRate) {
139 throw new RuntimeException("Video bitrate: " + bitRate
140 + " is not supported.");
145 public boolean isTerminalMandatory() {