OSDN Git Service

リサイズに関するコンフィグ読み書き
[coroid/inqubus.git] / frontend / src / saccubus / properties / MovieSetting.java
1 /* $Id$ */
2 package saccubus.properties;
3
4 import java.io.File;
5 import java.util.Properties;
6 import saccubus.converter.profile.FfmpegOption;
7
8 /**
9  * 動画設定.
10  * @author yuki
11  */
12 public class MovieSetting {
13
14     private static final String PROP_FFMPEG_PATH = "FFnpegPath";
15     private static final String PROP_VHOOK_PATH = "VhookPath";
16     private static final String PROP_OPTION_FILE = "OptionFile";
17     private static final String PROP_CMDLINE_EXT = "CMD_EXT";
18     private static final String PROP_CMDLINE_MAIN = "CMD_MAIN";
19     private static final String PROP_CMDLINE_IN = "CMD_IN";
20     private static final String PROP_CMDLINE_OUT = "CMD_OUT";
21     private static final String PROP_CMDLINE_AVFILTER = "CMD_AVFILTER";
22     private static final String PROP_RESIZE = "CMD_RESIZE";
23     private static final String PROP_RESIZE_WIDTH = "CMD_RESIZE_WIDTH";
24     private static final String PROP_RESIZE_HEIGHT = "CMD_RESIZE_HEIGHT";
25     private static final String PROP_ADJUST_RATIO = "CMD_ADJUST_RATIO";
26     private static final String PROP_PADDING ="CMD_PADDING";
27     private final File ffmpeg;
28     private final File vhook;
29     private final File optionFile;
30     private final FfmpegOption ffmpegOption;
31
32     public MovieSetting(File ffmpeg, File vhook, File optionFile, FfmpegOption ffmpegOption) {
33         this.ffmpeg = ffmpeg;
34         this.vhook = vhook;
35         this.optionFile = optionFile;
36         this.ffmpegOption = ffmpegOption;
37     }
38
39     public File getFfmpeg() {
40         return ffmpeg;
41     }
42
43     public File getVhook() {
44         return vhook;
45     }
46
47     public File getOptionFile() {
48         return optionFile;
49     }
50
51     public FfmpegOption getFfmpegOption() {
52         return ffmpegOption;
53     }
54
55     public void save(Properties prop) {
56         prop.setProperty(PROP_FFMPEG_PATH, getFfmpeg().getPath());
57         prop.setProperty(PROP_VHOOK_PATH, getVhook().getPath());
58         prop.setProperty(PROP_CMDLINE_EXT, getFfmpegOption().getExtOption());
59         prop.setProperty(PROP_CMDLINE_MAIN, getFfmpegOption().getMainOption());
60         prop.setProperty(PROP_CMDLINE_IN, getFfmpegOption().getInOption());
61         prop.setProperty(PROP_CMDLINE_OUT, getFfmpegOption().getOutOption());
62         prop.setProperty(PROP_CMDLINE_AVFILTER, getFfmpegOption().getAvfilterOption());
63         prop.setProperty(PROP_RESIZE, Boolean.toString(getFfmpegOption().isResize()));
64         prop.setProperty(PROP_RESIZE_WIDTH, Integer.toString(getFfmpegOption().getResizeWidth()));
65         prop.setProperty(PROP_RESIZE_HEIGHT, Integer.toString(getFfmpegOption().getResizeHeight()));
66         prop.setProperty(PROP_ADJUST_RATIO, Boolean.toString(getFfmpegOption().isAdjustRatio()));
67         prop.setProperty(PROP_PADDING, Boolean.toString(getFfmpegOption().isPadding()));
68         if (getOptionFile() != null) {
69             prop.setProperty(PROP_OPTION_FILE, getOptionFile().getPath());
70         } else {
71             prop.remove(PROP_OPTION_FILE);
72         }
73     }
74
75     public static MovieSetting load(Properties prop) {
76         String name = prop.getProperty(PROP_OPTION_FILE);
77         File optionFile = null;
78         if (name != null) {
79             optionFile = new File(name);
80         }
81
82         String ffmpeg = prop.getProperty(PROP_FFMPEG_PATH, new File("bin", "ffmpeg.exe").getPath());
83         String vhook = prop.getProperty(PROP_VHOOK_PATH, new File("bin", "nicovideo.dll").getPath());
84         String ext = prop.getProperty(PROP_CMDLINE_EXT, ".m4v");
85         String main = prop.getProperty(PROP_CMDLINE_MAIN, "");
86         String in = prop.getProperty(PROP_CMDLINE_IN, "");
87         String out = prop.getProperty(PROP_CMDLINE_OUT,
88                 "-f ipod -g 150 -qcomp 0.7 -qmin 20 -qmax 30 -qdiff 4 -subq 6 -me_range 16 -i_qfactor 0.714286");
89         String avfilter = prop.getProperty(PROP_CMDLINE_AVFILTER, "");
90         boolean resize = Boolean.getBoolean(prop.getProperty(PROP_RESIZE,"false"));
91         String width = prop.getProperty(PROP_RESIZE_WIDTH, "512");
92         String height = prop.getProperty(PROP_RESIZE_HEIGHT, "384");
93         boolean adjust = Boolean.getBoolean(prop.getProperty(PROP_ADJUST_RATIO,"false"));
94         boolean pad = Boolean.getBoolean(prop.getProperty(PROP_PADDING, "false"));
95         FfmpegOption opt = new FfmpegOption(ext, main, in, out, avfilter, resize, width, height, adjust, pad);
96
97         return new MovieSetting(new File(ffmpeg), new File(vhook), optionFile, opt);
98     }
99 }