OSDN Git Service

リサイズに関するコンフィグ読み書き
authoryukihane <yukihane.feather@gmail.com>
Mon, 1 Aug 2011 21:38:09 +0000 (06:38 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 1 Aug 2011 21:38:09 +0000 (06:38 +0900)
frontend/src/saccubus/MainFrame.java
frontend/src/saccubus/converter/profile/FfmpegOption.java
frontend/src/saccubus/prompt/Prompt.java
frontend/src/saccubus/properties/MovieSetting.java

index 0d53dba..d126d8a 100644 (file)
@@ -115,6 +115,25 @@ public class MainFrame extends JFrame {
     ButtonGroup CommentSaveButtonGroup = new ButtonGroup();
     ButtonGroup ConvSaveButtonGroup = new ButtonGroup();
 
+    private class FfmpegOptionCheckBoxListener implements ActionListener{
+
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            setFFMpegOptionCheckbox();
+        }
+    }
+    private final FfmpegOptionCheckBoxListener ffmpegOptionCheckBoxListener = new FfmpegOptionCheckBoxListener();
+
+    private void setFFMpegOptionCheckbox() {
+        boolean resizable = (resizeCheckBox.isEnabled() && resizeCheckBox.isSelected());
+        resizeWidthField.setEnabled(resizable);
+        resizeHeigitField.setEnabled(resizable);
+        adjustRatioCheckBox.setEnabled(resizable);
+
+        boolean adjustable = (adjustRatioCheckBox.isEnabled() && adjustRatioCheckBox.isSelected());
+        paddingCheckBox.setEnabled(adjustable);
+    }
+
     private void setNames() {
         mainTabbedPane.setName("mainTabbedPane");
 
@@ -451,7 +470,7 @@ public class MainFrame extends JFrame {
                         .addComponent(adjustRatioCheckBox))
                     .addGroup(layout.createSequentialGroup()
                         .addGap(20)
-                    .addComponent(padCheckBox))
+                    .addComponent(paddingCheckBox))
                 );
 
         layout.setVerticalGroup(layout.createSequentialGroup()
@@ -476,7 +495,12 @@ public class MainFrame extends JFrame {
                         .addComponent(resizeHeightLabel)
                         .addComponent(resizeHeigitField))
                     .addComponent(adjustRatioCheckBox)
-                    .addComponent(padCheckBox)));
+                    .addComponent(paddingCheckBox)));
+
+        resizeCheckBox.addActionListener(ffmpegOptionCheckBoxListener);
+        adjustRatioCheckBox.addActionListener(ffmpegOptionCheckBoxListener);
+        paddingCheckBox.addActionListener(ffmpegOptionCheckBoxListener);
+        setFFMpegOptionCheckbox();
 
 
         VideoInfoPanel.add(DoButton, gridBagConstraints71);
@@ -757,6 +781,11 @@ public class MainFrame extends JFrame {
         inputOptionField.setText(movie.getFfmpegOption().getInOption());
         outputOptionField.setText(movie.getFfmpegOption().getOutOption());
         avfilterOptionField.setText(movie.getFfmpegOption().getAvfilterOption());
+        resizeCheckBox.setSelected(movie.getFfmpegOption().isResize());
+        resizeWidthField.setText(Integer.toString(movie.getFfmpegOption().getResizeWidth()));
+        resizeHeigitField.setText(Integer.toString(movie.getFfmpegOption().getResizeHeight()));
+        adjustRatioCheckBox.setSelected(movie.getFfmpegOption().isAdjustRatio());
+        paddingCheckBox.setSelected(movie.getFfmpegOption().isPadding());
         FFmpegOptionModel.reload(movie.getOptionFile());
 
         // 変換設定
@@ -817,7 +846,7 @@ public class MainFrame extends JFrame {
     private final JLabel resizeHeightLabel = new JLabel("縦");
     private final JTextField resizeHeigitField = new JTextField();
     private final JCheckBox adjustRatioCheckBox = new JCheckBox("アスペクト比を維持");
-    private final JCheckBox padCheckBox = new JCheckBox("黒幕を付与");
+    private final JCheckBox paddingCheckBox = new JCheckBox("黒幕を付与");
     // FFmpegの設定 ここまで
     private JLabel FontIndexLabel = new JLabel();
     private JTextField fontIndexField = new JTextField();
@@ -1186,19 +1215,25 @@ public class MainFrame extends JFrame {
 
                 public void actionPerformed(java.awt.event.ActionEvent e) {
                     if (FFmpegOptionModel.isFile()) {// ファイル
-                        extOptionField.setEnabled(false);
-                        mainOptionField.setEnabled(false);
-                        inputOptionField.setEnabled(false);
-                        outputOptionField.setEnabled(false);
-                        avfilterOptionField.setEnabled(false);
+                        setFFMpegOptionEnabled(false);
                     } else {// ファイルでない
-                        extOptionField.setEnabled(true);
-                        mainOptionField.setEnabled(true);
-                        inputOptionField.setEnabled(true);
-                        outputOptionField.setEnabled(true);
-                        avfilterOptionField.setEditable(true);
+                        setFFMpegOptionEnabled(true);
+                        setFFMpegOptionCheckbox();
                     }
                 }
+
+                private void setFFMpegOptionEnabled(boolean enable) {
+                    extOptionField.setEnabled(enable);
+                    mainOptionField.setEnabled(enable);
+                    inputOptionField.setEnabled(enable);
+                    outputOptionField.setEnabled(enable);
+                    avfilterOptionField.setEnabled(enable);
+                    resizeCheckBox.setEnabled(enable);
+                    resizeWidthField.setEnabled(enable);
+                    resizeHeigitField.setEditable(enable);
+                    adjustRatioCheckBox.setEnabled(enable);
+                    paddingCheckBox.setEnabled(enable);
+                }
             });
         }
         return FFmpegOptionComboBox;
@@ -1377,9 +1412,14 @@ public class MainFrame extends JFrame {
         String in = inputOptionField.getText();
         String out = outputOptionField.getText();
         String avfilter = avfilterOptionField.getText();
+        boolean resize = resizeCheckBox.isSelected();
+        String width = resizeWidthField.getText();
+        String height = resizeHeigitField.getText();
+        boolean adjust = adjustRatioCheckBox.isSelected();
+        boolean pad = paddingCheckBox.isSelected();
         File optionFile = FFmpegOptionModel.getSelectedFile();
 
-        FfmpegOption opt = new FfmpegOption(ext, main, in, out, avfilter);
+        FfmpegOption opt = new FfmpegOption(ext, main, in, out, avfilter, resize, width, height, adjust, pad);
         return new MovieSetting(new File(ffmpeg), new File(vhook), optionFile, opt);
     }
 
index 79dfa0e..f92617c 100644 (file)
@@ -18,6 +18,11 @@ public class FfmpegOption {
     private final String inOption;
     private final String outOption;
     private final String avfilterOption;
+    private final boolean resize;
+    private final int resizeWidth;
+    private final int resizeHeight;
+    private final boolean adjustRatio;
+    private final boolean padding;
 
     public static FfmpegOption load(File file) throws IOException {
         Properties prop = new Properties();
@@ -27,22 +32,34 @@ public class FfmpegOption {
         String in = prop.getProperty("IN", "");
         String out = prop.getProperty("OUT", "");
         String avfilter = prop.getProperty("AVFILTER", "");
+        boolean resize = Boolean.getBoolean(prop.getProperty("RESIZE", "false"));
+        String width = prop.getProperty("WIDTH", "");
+        String height = prop.getProperty("HEIGHT", "");
+        boolean adjust =  Boolean.getBoolean(prop.getProperty("ADJST_RATIO", "true"));
+        boolean pad =  Boolean.getBoolean(prop.getProperty("ADJST_RATIO", "false"));
 
         if (StringUtils.isBlank(ext)) {
             throw new IOException("変換オプションファイル書式誤り ext: "
                     + ext + ", main: " + main + ", in: " + in + ", out: " + out + ", avfilter: " + avfilter);
         }
-        return new FfmpegOption(ext, main, in, out, avfilter);
+        return new FfmpegOption(ext, main, in, out, avfilter, resize, width, height, adjust, pad);
     }
 
-    public FfmpegOption(String extOption, String mainOption, String inOption, String outOption, String avfilterOption) {
+    public FfmpegOption(String extOption, String mainOption, String inOption, String outOption, String avfilterOption,
+            boolean resize, String width, String height, boolean adjust, boolean pad) {
         this.extOption = (extOption.startsWith(".")) ? extOption : "." + extOption;
         this.mainOption = mainOption;
         this.inOption = inOption;
         this.outOption = outOption;
         this.avfilterOption = avfilterOption;
+        this.resize = resize;
+        this.resizeWidth = (width.isEmpty()) ? 0 : Integer.parseInt(width);
+        this.resizeHeight = (height.isEmpty()) ? 0 : Integer.parseInt(height);
+        this.adjustRatio = adjust;
+        this.padding = pad;
     }
 
+
     public String getExtOption() {
         return extOption;
     }
@@ -62,4 +79,25 @@ public class FfmpegOption {
     public String getAvfilterOption() {
         return avfilterOption;
     }
+
+    public boolean isResize() {
+        return resize;
+    }
+
+    public int getResizeWidth() {
+        return resizeWidth;
+    }
+
+    public int getResizeHeight() {
+        return resizeHeight;
+    }
+
+    public boolean isAdjustRatio() {
+        return adjustRatio;
+    }
+
+    public boolean isPadding() {
+        return padding;
+    }
+
 }
index 74f09a4..94458fa 100644 (file)
@@ -137,7 +137,8 @@ public class Prompt {
 //        OutputFileSetting outputFileSetting = p.getOutputFileSetting();
         Ffmpeg ffmpeg = p.getFfmpeg();
 
-        FfmpegOption newFfmpegOption = new FfmpegOption(ffmpeg.getFfmpegOption().getExtOption(), "", "", ff, "");
+        FfmpegOption newFfmpegOption = new FfmpegOption(ffmpeg.getFfmpegOption().getExtOption(), "", "", ff, "", false,
+                "", "", false, false);
         InputFileSetting newVideoSetting = new InputFileSetting(new SFile(true, new File(video)), false, false);
         InputFileSetting newCommentSetting = new InputFileSetting(new SFile(true, new File(comm)), false, false);
         InputFileSetting newTcommentSetting = new InputFileSetting(new SFile(true, new File(tcomm)), false, false);
index adfe9c2..e58bd36 100644 (file)
@@ -19,6 +19,11 @@ public class MovieSetting {
     private static final String PROP_CMDLINE_IN = "CMD_IN";
     private static final String PROP_CMDLINE_OUT = "CMD_OUT";
     private static final String PROP_CMDLINE_AVFILTER = "CMD_AVFILTER";
+    private static final String PROP_RESIZE = "CMD_RESIZE";
+    private static final String PROP_RESIZE_WIDTH = "CMD_RESIZE_WIDTH";
+    private static final String PROP_RESIZE_HEIGHT = "CMD_RESIZE_HEIGHT";
+    private static final String PROP_ADJUST_RATIO = "CMD_ADJUST_RATIO";
+    private static final String PROP_PADDING ="CMD_PADDING";
     private final File ffmpeg;
     private final File vhook;
     private final File optionFile;
@@ -55,6 +60,11 @@ public class MovieSetting {
         prop.setProperty(PROP_CMDLINE_IN, getFfmpegOption().getInOption());
         prop.setProperty(PROP_CMDLINE_OUT, getFfmpegOption().getOutOption());
         prop.setProperty(PROP_CMDLINE_AVFILTER, getFfmpegOption().getAvfilterOption());
+        prop.setProperty(PROP_RESIZE, Boolean.toString(getFfmpegOption().isResize()));
+        prop.setProperty(PROP_RESIZE_WIDTH, Integer.toString(getFfmpegOption().getResizeWidth()));
+        prop.setProperty(PROP_RESIZE_HEIGHT, Integer.toString(getFfmpegOption().getResizeHeight()));
+        prop.setProperty(PROP_ADJUST_RATIO, Boolean.toString(getFfmpegOption().isAdjustRatio()));
+        prop.setProperty(PROP_PADDING, Boolean.toString(getFfmpegOption().isPadding()));
         if (getOptionFile() != null) {
             prop.setProperty(PROP_OPTION_FILE, getOptionFile().getPath());
         } else {
@@ -77,7 +87,12 @@ public class MovieSetting {
         String out = prop.getProperty(PROP_CMDLINE_OUT,
                 "-f ipod -g 150 -qcomp 0.7 -qmin 20 -qmax 30 -qdiff 4 -subq 6 -me_range 16 -i_qfactor 0.714286");
         String avfilter = prop.getProperty(PROP_CMDLINE_AVFILTER, "");
-        FfmpegOption opt = new FfmpegOption(ext, main, in, out, avfilter);
+        boolean resize = Boolean.getBoolean(prop.getProperty(PROP_RESIZE,"false"));
+        String width = prop.getProperty(PROP_RESIZE_WIDTH, "512");
+        String height = prop.getProperty(PROP_RESIZE_HEIGHT, "384");
+        boolean adjust = Boolean.getBoolean(prop.getProperty(PROP_ADJUST_RATIO,"false"));
+        boolean pad = Boolean.getBoolean(prop.getProperty(PROP_PADDING, "false"));
+        FfmpegOption opt = new FfmpegOption(ext, main, in, out, avfilter, resize, width, height, adjust, pad);
 
         return new MovieSetting(new File(ffmpeg), new File(vhook), optionFile, opt);
     }