6a43d2621d0ccddd4bd22bcbefc87072fa1571aa
[meviz.git] / src / main / java / eu / svjatoslav / meviz / encoder / converters / AvconvVideo.java
1 /*
2  * Meviz - Various tools collection to work with multimedia.
3  * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  *
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.
8  */
9
10 package eu.svjatoslav.meviz.encoder.converters;
11
12 import java.io.File;
13 import java.util.List;
14
15 import eu.svjatoslav.meviz.encoder.EncodingOptions;
16
17 public class AvconvVideo extends AbstractConverter {
18
19         @Override
20         public String getCommand(final File inputFile, final File targetFile,
21                         final EncodingOptions options) {
22
23                 int videoBitrate;
24                 int audioBitrate;
25
26                 switch (options.videoBitrate) {
27                 case LOW:
28                         videoBitrate = 1000;
29                         audioBitrate = 128;
30                         break;
31
32                 case MEDIUM:
33                         videoBitrate = 4000;
34                         audioBitrate = 192;
35                         break;
36
37                 case HIGH:
38                         videoBitrate = 40000;
39                         audioBitrate = 500;
40                         break;
41
42                 default:
43                         throw new RuntimeException("Video bitrate: " + options.videoBitrate
44                                         + " is not supported.");
45                 }
46
47                 // convert
48                 final StringBuffer codecParams = new StringBuffer();
49
50                 String videoCodec = "libx264 ";
51
52                 if (options.forPortablePlayer) {
53                         videoBitrate = 1000;
54                         audioBitrate = 128;
55                         videoCodec = "libxvid ";
56                         codecParams.append("-s 640x480 ");
57                 }
58
59                 codecParams.append("-acodec libmp3lame -vcodec " + videoCodec);
60
61                 codecParams.append("-b " + videoBitrate + "k ");
62                 codecParams.append("-b:a " + audioBitrate + "k ");
63
64                 if (options.deinterlace)
65                         codecParams.append("-filter:v yadif ");
66
67                 return "avconv -i \"" + inputFile.getAbsolutePath() + "\" "
68                                 + codecParams.toString() + "\"" + targetFile.getAbsolutePath()
69                                 + "\"";
70         }
71
72         @Override
73         public List<String> getSourceFileExtensions() {
74                 return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob");
75         }
76
77         @Override
78         public List<String> getTargetFileExtensions() {
79                 return toList("mkv", "mts", "mp4", "avi", "mpg", "mpeg", "vob");
80         }
81
82         @Override
83         public boolean isTerminalMandatory() {
84                 return true;
85         }
86
87 }