OSDN Git Service

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