OSDN Git Service

interfaceに追加されたメソッドを追加
[coroid/inqubus.git] / frontend / src / saccubus / converter / classic / profile / FfmpegOption.java
1 /* $Id$ */
2 package saccubus.converter.classic.profile;
3
4 import java.io.File;
5 import java.io.FileInputStream;
6 import java.io.IOException;
7 import java.util.Properties;
8 import org.apache.commons.lang.StringUtils;
9
10 /**
11  *
12  * @author yuki
13  */
14 public class FfmpegOption implements yukihane.saccubus.converter.profile.FfmpegOption {
15
16     private final String extOption;
17     private final String mainOption;
18     private final String inOption;
19     private final String outOption;
20     private final String avfilterOption;
21     private final boolean resize;
22     private final int resizeWidth;
23     private final int resizeHeight;
24     private final boolean adjustRatio;
25
26     public static FfmpegOption load(File file) throws IOException {
27         Properties prop = new Properties();
28         prop.loadFromXML(new FileInputStream(file));
29         String ext = prop.getProperty("EXT");
30         String main = prop.getProperty("MAIN", "");
31         String in = prop.getProperty("IN", "");
32         String out = prop.getProperty("OUT", "");
33         String avfilter = prop.getProperty("AVFILTER", "");
34         boolean resize = Boolean.getBoolean(prop.getProperty("RESIZE", "false"));
35         String width = prop.getProperty("WIDTH", "");
36         String height = prop.getProperty("HEIGHT", "");
37         boolean adjust =  Boolean.getBoolean(prop.getProperty("ADJST_RATIO", "true"));
38
39         if (StringUtils.isBlank(ext)) {
40             throw new IOException("変換オプションファイル書式誤り ext: "
41                     + ext + ", main: " + main + ", in: " + in + ", out: " + out + ", avfilter: " + avfilter);
42         }
43         return new FfmpegOption(ext, main, in, out, avfilter, resize, width, height, adjust);
44     }
45
46     public FfmpegOption(String extOption, String mainOption, String inOption, String outOption, String avfilterOption,
47             boolean resize, String width, String height, boolean adjust) {
48         this.extOption = (extOption.startsWith(".")) ? extOption : "." + extOption;
49         this.mainOption = mainOption;
50         this.inOption = inOption;
51         this.outOption = outOption;
52         this.avfilterOption = avfilterOption;
53         this.resize = resize;
54         this.resizeWidth = (width.isEmpty()) ? 0 : Integer.parseInt(width);
55         this.resizeHeight = (height.isEmpty()) ? 0 : Integer.parseInt(height);
56         this.adjustRatio = adjust;
57     }
58
59
60     @Override
61     public String getExtOption() {
62         return extOption;
63     }
64
65     @Override
66     public String getMainOption() {
67         return mainOption;
68     }
69
70     @Override
71     public String getInOption() {
72         return inOption;
73     }
74
75     @Override
76     public String getOutOption() {
77         return outOption;
78     }
79
80     @Override
81     public String getAvfilterOption() {
82         return avfilterOption;
83     }
84
85     @Override
86     public boolean isResize() {
87         return resize;
88     }
89
90     @Override
91     public int getResizeWidth() {
92         return resizeWidth;
93     }
94
95     @Override
96     public int getResizeHeight() {
97         return resizeHeight;
98     }
99
100     @Override
101     public boolean isAdjustRatio() {
102         return adjustRatio;
103     }
104 }