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 void constructCodecParamsString(final EncodingOptions options,
22 final int videoBitrate, final int audioBitrate,
23 final StringBuffer codecParams, final String videoCodec,
24 final String audioCodec) {
26 if (audioCodec == null)
27 codecParams.append("-an ");
29 codecParams.append("-acodec " + audioCodec + " ");
31 codecParams.append("-vcodec " + videoCodec + " ");
33 if (videoBitrate != -1)
34 codecParams.append("-b " + videoBitrate + "k ");
36 if (audioBitrate != -1)
37 codecParams.append("-b:a " + audioBitrate + "k ");
39 if (options.deinterlace)
40 codecParams.append("-filter:v yadif ");
43 private int getAudioBitrateValue(final BitrateParameter.bitrate bitRate) {
61 throw new RuntimeException("Audio bitrate: " + bitRate
62 + " is not supported.");
67 public String getCommand(final File inputFile, final File targetFile,
68 final EncodingOptions options) {
70 int videoBitrate = getVideoBitrateValue(options.getVideoBitrate());
71 int audioBitrate = getAudioBitrateValue(options.getAudioBitrate());
74 final StringBuffer codecParams = new StringBuffer();
76 String videoCodec = "libx264";
77 String audioCodec = "libmp3lame";
79 if (options.getVideoBitrate() == bitrate.COPY)
82 if (options.getAudioBitrate() == bitrate.COPY)
85 if (options.getAudioBitrate() == bitrate.NONE)
88 if (options.forPortablePlayer) {
91 videoCodec = "libxvid";
92 codecParams.append("-s 640x480 ");
95 constructCodecParamsString(options, videoBitrate, audioBitrate,
96 codecParams, videoCodec, audioCodec);
98 return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
99 + codecParams.toString() + "\"" + targetFile.getAbsolutePath()
104 public List<String> getSourceFileExtensions() {
105 return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v");
109 public List<String> getTargetFileExtensions() {
110 return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob", "m4v");
113 private int getVideoBitrateValue(final BitrateParameter.bitrate bitRate) {
128 throw new RuntimeException("Video bitrate: " + bitRate
129 + " is not supported.");
134 public boolean isTerminalMandatory() {