OSDN Git Service

通常コメントと投稿者コメントを別で処理する.
authoryukihane <yukihane.feather@gmail.com>
Mon, 12 Sep 2011 08:49:45 +0000 (17:49 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 12 Sep 2011 08:53:31 +0000 (17:53 +0900)
一緒にしてしまうと透明化処理なども同じで扱われてしまうため.

frontend/src/saccubus/worker/impl/convert/Convert.java

index 9f94b33..6cc39f6 100644 (file)
@@ -12,12 +12,14 @@ import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.ArrayList;
+import java.util.EnumSet;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import saccubus.conv.ConvertToVideoHook;
+import saccubus.conv.NicoXMLReader.ProcessType;
 import saccubus.util.FfmpegUtil;
 import saccubus.worker.Worker;
 import saccubus.worker.WorkerListener;
@@ -84,19 +86,27 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
         final File outputFile = new File(outprof.getDir(), pattern.createFileName());
 
         File transformedComment = null;
+        File transformedOwner = null;
         try {
 
             if (profile.isCommentOverlay()) {
                 transformedComment = File.createTempFile("vhk", ".tmp", profile.getTempDir());
+                transformedOwner = File.createTempFile("vown", ".tmp", profile.getTempDir());
                 final HideCondition hide = profile.getNgSetting();
+
                 publish(new ConvertProgress(PROCESS, -1.0, "コメントの中間ファイルへの変換中"));
-                ConvertToVideoHook.convert(commentFile, transformedComment, hide.getId(), hide.getWord());
+                ConvertToVideoHook.convert(EnumSet.of(ProcessType.NORMAL), commentFile, transformedComment, hide.getId(),
+                        hide.getWord());
+
+                publish(new ConvertProgress(PROCESS, -1.0, "投稿者コメントの中間ファイルへの変換中"));
+                ConvertToVideoHook.convert(EnumSet.of(ProcessType.OWNER), commentFile, transformedOwner, hide.getId(),
+                        hide.getWord());
             }
 
             checkStop();
             publish(new ConvertProgress(PROCESS, -1.0, "動画の変換を開始"));
 
-            final int code = convert(transformedComment, outputFile);
+            final int code = convert(outputFile, transformedComment, transformedOwner);
             if (code != 0) {
                 throw new IOException("ffmpeg実行失敗: " + outputFile.getPath());
             }
@@ -106,10 +116,13 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
             if (transformedComment != null && transformedComment.exists()) {
                 transformedComment.delete();
             }
+            if (transformedOwner != null && transformedOwner.exists()) {
+                transformedOwner.delete();
+            }
         }
     }
 
-    private int convert(File transformedComment, File outputFile) throws InterruptedException, IOException {
+    private int convert(File outputFile, File commentNormal, File commentOwner) throws InterruptedException, IOException {
         File fwsFile = null;
         try {
             final File tmpCws = File.createTempFile("cws", ".swf", profile.getTempDir());
@@ -117,7 +130,7 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
             tmpCws.delete();
             final File target = (fwsFile != null) ? fwsFile : videoFile;
 
-            final List<String> arguments = createArguments(target, transformedComment, outputFile);
+            final List<String> arguments = createArguments(target, outputFile, commentNormal, commentOwner);
             final FfmpegUtil util = new FfmpegUtil(profile.getFfmpeg(), target);
             int duration;
             try {
@@ -134,7 +147,7 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
         }
     }
 
-    private List<String> createArguments(final File targetVideoFile, File transformedComment, File output)
+    private List<String> createArguments(final File targetVideoFile, File output, File comment, File commentOwner)
             throws IOException, UnsupportedEncodingException {
         final ConvertProfile prof = profile;
         final FfmpegProfile ffop = prof.getFfmpegOption();
@@ -173,7 +186,7 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
         }
         final List<String> avfilterArgs = createAvfilterOptions(ffop.getAvfilterOption());
         if (!prof.isVhookDisabled()) {
-            final String vhookArg = getVhookArg(prof, transformedComment.getPath(), isHD);
+            final String vhookArg = getVhookArg(prof, comment.getPath(), commentOwner.getPath(), isHD);
             if (isNotBlank(vhookArg)) {
                 avfilterArgs.add(vhookArg);
             }
@@ -192,7 +205,6 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
         logger.log(Level.INFO, argMsg.toString());
         return cmdList;
     }
-
     private static final Pattern PATTERN_TIME = Pattern.compile("time=(\\d+)");
 
     private int executeFfmpeg(final List<String> cmdList, int duration) throws InterruptedException, IOException {
@@ -238,7 +250,7 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
         return avfilterArgs;
     }
 
-    private static String getVhookArg(ConvertProfile prof, String commPath, boolean isHD) throws
+    private static String getVhookArg(ConvertProfile prof, String commPath, String commOwnerPath, boolean isHD) throws
             UnsupportedEncodingException {
         StringBuilder sb = new StringBuilder();
         sb.append("vhext=");
@@ -247,6 +259,9 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
             sb.append("|");
             sb.append("--data-user:");
             sb.append(URLEncoder.encode(commPath.replace("\\", "/"), "Shift_JIS"));
+            sb.append("|");
+            sb.append("--data-owner:");
+            sb.append(URLEncoder.encode(commOwnerPath.replace("\\", "/"), "Shift_JIS"));
         }
         sb.append("|");
         sb.append("--font:");