OSDN Git Service

avfilter設定の保存、読み取り、設定値を用いたコマンドライン文字列作成処理を追加
authoryukihane <yukihane.feather@gmail.com>
Mon, 1 Aug 2011 12:51:49 +0000 (21:51 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 1 Aug 2011 12:51:49 +0000 (21:51 +0900)
frontend/src/saccubus/MainFrame.java
frontend/src/saccubus/converter/FfmpegCommand.java
frontend/src/saccubus/converter/profile/FfmpegOption.java
frontend/src/saccubus/prompt/Prompt.java
frontend/src/saccubus/properties/MovieSetting.java

index 1bbcc08..6dc36e5 100644 (file)
@@ -739,8 +739,9 @@ public class MainFrame extends JFrame {
         vhookPathField.setText(movie.getVhook().toString());
         extOptionField.setText(movie.getFfmpegOption().getExtOption());
         mainOptionField.setText(movie.getFfmpegOption().getMainOption());
-        outputOptionField.setText(movie.getFfmpegOption().getOutOption());
         inputOptionField.setText(movie.getFfmpegOption().getInOption());
+        outputOptionField.setText(movie.getFfmpegOption().getOutOption());
+        avfilterOptionField.setText(movie.getFfmpegOption().getAvfilterOption());
         FFmpegOptionModel.reload(movie.getOptionFile());
 
         // 変換設定
@@ -1349,9 +1350,10 @@ public class MainFrame extends JFrame {
         String main = mainOptionField.getText();
         String in = inputOptionField.getText();
         String out = outputOptionField.getText();
+        String avfilter = avfilterOptionField.getText();
         File optionFile = FFmpegOptionModel.getSelectedFile();
 
-        FfmpegOption opt = new FfmpegOption(ext, main, in, out);
+        FfmpegOption opt = new FfmpegOption(ext, main, in, out, avfilter);
         return new MovieSetting(new File(ffmpeg), new File(vhook), optionFile, opt);
     }
 
index d45a39c..1989d4b 100644 (file)
@@ -88,7 +88,8 @@ public class FfmpegCommand extends AbstractCommand {
         stopFlagReturn();
         sendText("動画の変換を開始");
         int code;
-        if ((code = converting_video(videoFile, convertedVideoFile, (commentFile != null), commentMiddleFile.getPath(), (tcommFile
+        if ((code = converting_video(videoFile, convertedVideoFile, (commentFile != null), commentMiddleFile.getPath(),
+                (tcommFile
                 != null), tcommMiddleFile.getPath(), getFfmpeg().getFfmpegOption())) == 0) {
             sendText("変換が正常に終了しました。");
             return true;
@@ -130,11 +131,15 @@ public class FfmpegCommand extends AbstractCommand {
                 cmdList.add(opt);
             }
         }
-        if (!getFfmpeg().isVhookDisabled()) {
-            if (!addVhookSetting(cmdList, addComment, vhook_path, addTcomment, tcommPath)) {
-                return -1;
-            }
+
+        List<String> avfilterArgs = getAvfilterOptions(ov, addComment, vhook_path, addTcomment, tcommPath);
+
+        if (!avfilterArgs.isEmpty()) {
+            cmdList.add("-vfilters");
+            final String args = "\"" + StringUtils.join(avfilterArgs, ", ") + "\"";
+            cmdList.add(args);
         }
+
         cmdList.add(convertedVideoFile.getPath());
 
         System.out.print("arg:");
@@ -174,54 +179,62 @@ public class FfmpegCommand extends AbstractCommand {
         }
     }
 
-    private boolean addVhookSetting(List cmdList, boolean addComment, String vhook_path, boolean addTcomment,
-            String tcommPath) {
-        try {
-            cmdList.add("-vfilters");
-            StringBuffer sb = new StringBuffer();
-            sb.append("vhext=");
-            sb.append(getFfmpeg().getVhook().getPath().replace("\\", "/"));
-            if (addComment) {
-                sb.append("|");
-                sb.append("--data-user:");
-                sb.append(URLEncoder.encode(vhook_path.replace("\\", "/"), "Shift_JIS"));
-            }
-            if (addTcomment) {
-                sb.append("|");
-                sb.append("--data-owner:");
-                sb.append(URLEncoder.encode(tcommPath.replace("\\", "/"), "Shift_JIS"));
-            }
-            sb.append("|");
-            sb.append("--font:");
-            sb.append(URLEncoder.encode(
-                    getFfmpeg().getFont().getPath().replace("\\", "/"), "Shift_JIS"));
+    private List<String> getAvfilterOptions(FfmpegOption ov, boolean addComment, String vhook_path, boolean addTcomment,
+            String tcommPath) throws UnsupportedEncodingException {
+        final List<String> avfilterArgs = new ArrayList<String>();
+        final String avfilterOption = ov.getAvfilterOption();
+        if (StringUtils.isNotBlank(avfilterOption)) {
+            avfilterArgs.add(avfilterOption);
+        }
+        final String vhookArg = (getFfmpeg().isVhookDisabled())
+                ? null : getVhookArg(addComment, vhook_path, addTcomment, tcommPath);
+        if (vhookArg != null) {
+            avfilterArgs.add(vhookArg);
+        }
+        return avfilterArgs;
+    }
+
+    private String getVhookArg(boolean addComment, String vhook_path, boolean addTcomment,
+            String tcommPath) throws UnsupportedEncodingException {
+        StringBuilder sb = new StringBuilder();
+        sb.append("vhext=");
+        sb.append(getFfmpeg().getVhook().getPath().replace("\\", "/"));
+        if (addComment) {
             sb.append("|");
-            sb.append("--font-index:");
-            sb.append(getFfmpeg().getFontIndex());
+            sb.append("--data-user:");
+            sb.append(URLEncoder.encode(vhook_path.replace("\\", "/"), "Shift_JIS"));
+        }
+        if (addTcomment) {
             sb.append("|");
-            sb.append("--show-user:");
-            sb.append(getFfmpeg().getMaxNumOfComment());
+            sb.append("--data-owner:");
+            sb.append(URLEncoder.encode(tcommPath.replace("\\", "/"), "Shift_JIS"));
+        }
+        sb.append("|");
+        sb.append("--font:");
+        sb.append(URLEncoder.encode(
+                getFfmpeg().getFont().getPath().replace("\\", "/"), "Shift_JIS"));
+        sb.append("|");
+        sb.append("--font-index:");
+        sb.append(getFfmpeg().getFontIndex());
+        sb.append("|");
+        sb.append("--show-user:");
+        sb.append(getFfmpeg().getMaxNumOfComment());
+        sb.append("|");
+        sb.append("--shadow:");
+        sb.append(getFfmpeg().getShadowIndex());
+        sb.append("|");
+        if (getFfmpeg().isShowConverting()) {
+            sb.append("--enable-show-video");
             sb.append("|");
-            sb.append("--shadow:");
-            sb.append(getFfmpeg().getShadowIndex());
+        }
+        if (getFfmpeg().isSelfAdjustFontSize()) {
+            sb.append("--enable-fix-font-size");
             sb.append("|");
-            if (getFfmpeg().isShowConverting()) {
-                sb.append("--enable-show-video");
-                sb.append("|");
-            }
-            if (getFfmpeg().isSelfAdjustFontSize()) {
-                sb.append("--enable-fix-font-size");
-                sb.append("|");
-            }
-            if (getFfmpeg().isCommentOpaque()) {
-                sb.append("--enable-opaque-comment");
-            }
-            cmdList.add(sb.toString());
-            return true;
-        } catch (UnsupportedEncodingException e) {
-            e.printStackTrace();
-            return false;
         }
+        if (getFfmpeg().isCommentOpaque()) {
+            sb.append("--enable-opaque-comment");
+        }
+        return sb.toString();
     }
 
     private Ffmpeg getFfmpeg() {
index e0933a7..872296c 100644 (file)
@@ -13,43 +13,52 @@ import java.util.Properties;
 public class FfmpegOption {
 
     private final String extOption;
+    private final String mainOption;
     private final String inOption;
     private final String outOption;
-    private final String mainOption;
+    private final String avfilterOption;
 
     public static FfmpegOption load(File file) throws IOException {
         Properties prop = new Properties();
         prop.loadFromXML(new FileInputStream(file));
         String ext = prop.getProperty("EXT");
+        String main = prop.getProperty("MAIN");
         String in = prop.getProperty("IN");
         String out = prop.getProperty("OUT");
-        String main = prop.getProperty("MAIN");
-        if (ext == null || in == null || out == null || main == null) {
-            throw new IOException("変換オプションファイル書式誤り。");
+        String avfilter = prop.getProperty("AVFILTER");
+
+        if (ext == null || main == null || in == null || out == null || avfilter == null) {
+            throw new IOException("変換オプションファイル書式誤り ext: "
+                    + ext + ", main: " + main + ", in: " + in + ", out: " + out + ", avfilter: " + avfilter);
         }
-        return new FfmpegOption(ext, main, in, out);
+        return new FfmpegOption(ext, main, in, out, avfilter);
     }
 
-    public FfmpegOption(String extOption, String mainOption, String inOption, String outOption) {
+    public FfmpegOption(String extOption, String mainOption, String inOption, String outOption, String avfilterOption) {
         this.extOption = (extOption.startsWith(".")) ? extOption : "." + extOption;
+        this.mainOption = mainOption;
         this.inOption = inOption;
         this.outOption = outOption;
-        this.mainOption = mainOption;
+        this.avfilterOption = avfilterOption;
     }
 
     public String getExtOption() {
         return extOption;
     }
 
-    public String getInOption() {
-        return inOption;
-    }
-
     public String getMainOption() {
         return mainOption;
     }
 
+    public String getInOption() {
+        return inOption;
+    }
+
     public String getOutOption() {
         return outOption;
     }
+
+    public String getAvfilterOption() {
+        return avfilterOption;
+    }
 }
index 433c769..74f09a4 100644 (file)
@@ -32,19 +32,19 @@ import saccubus.net.TextProgressListener;
  * <p>
  * タイトル: さきゅばす
  * </p>
- * 
+ *
  * <p>
  * 説明: ニコニコ動画の動画をコメントつきで保存
  * </p>
- * 
+ *
  * <p>
  * 著作権: Copyright (c) 2007 PSI
  * </p>
- * 
+ *
  * <p>
  * 会社名:
  * </p>
- * 
+ *
  * @author 未入力
  * @version 1.0
  */
@@ -137,7 +137,7 @@ 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, "");
         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 8363e05..adfe9c2 100644 (file)
@@ -18,6 +18,7 @@ public class MovieSetting {
     private static final String PROP_CMDLINE_MAIN = "CMD_MAIN";
     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 final File ffmpeg;
     private final File vhook;
     private final File optionFile;
@@ -53,6 +54,7 @@ public class MovieSetting {
         prop.setProperty(PROP_CMDLINE_MAIN, getFfmpegOption().getMainOption());
         prop.setProperty(PROP_CMDLINE_IN, getFfmpegOption().getInOption());
         prop.setProperty(PROP_CMDLINE_OUT, getFfmpegOption().getOutOption());
+        prop.setProperty(PROP_CMDLINE_AVFILTER, getFfmpegOption().getAvfilterOption());
         if (getOptionFile() != null) {
             prop.setProperty(PROP_OPTION_FILE, getOptionFile().getPath());
         } else {
@@ -74,7 +76,8 @@ public class MovieSetting {
         String in = prop.getProperty(PROP_CMDLINE_IN, "");
         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");
-        FfmpegOption opt = new FfmpegOption(ext, main, in, out);
+        String avfilter = prop.getProperty(PROP_CMDLINE_AVFILTER, "");
+        FfmpegOption opt = new FfmpegOption(ext, main, in, out, avfilter);
 
         return new MovieSetting(new File(ffmpeg), new File(vhook), optionFile, opt);
     }