OSDN Git Service

新しいバージョンのffmpeg処理時間出力に対応
[coroid/inqubus.git] / frontend / src / saccubus / worker / impl / convert / Convert.java
index 1d472d9..0fa9916 100644 (file)
@@ -14,8 +14,8 @@ 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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import saccubus.conv.ConvertToVideoHook;
@@ -40,7 +40,7 @@ import yukihane.swf.Cws2Fws;
  */
 public class Convert extends Worker<ConvertResult, ConvertProgress> {
 
-    private static final Logger logger = Logger.getLogger(Convert.class.getName());
+    private static final Logger logger = LoggerFactory.getLogger(Convert.class);
     private final ConvertProfile profile;
     private final File videoFile;
     private final File commentFile;
@@ -63,7 +63,7 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
         this.profile = profile;
         this.videoFile = video;
         this.commentFile = comment;
-        logger.log(Level.INFO, "convert video:{0}, comment:{1}", new Object[]{videoFile, commentFile});
+        logger.info("convert video:{}, comment:{}", videoFile, commentFile);
     }
 
     @Override
@@ -137,7 +137,7 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
             try {
                 duration = util.getDuration();
             } catch (IOException ex) {
-                logger.log(Level.FINE, "動画再生時間を取得できませんでした: {0}", target);
+                logger.info("動画再生時間を取得できませんでした: {}", target);
                 duration = Integer.MAX_VALUE;
             }
             return executeFfmpeg(arguments, duration);
@@ -194,24 +194,20 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
         }
         if (!avfilterArgs.isEmpty()) {
             cmdList.add("-vfilters");
-            final String args = "\"" + join(avfilterArgs, ", ") + "\"";
+            final String args =  join(avfilterArgs, ", ");
             cmdList.add(args);
         }
         cmdList.add(output.getPath());
-        final StringBuilder argMsg = new StringBuilder();
-        argMsg.append("arg:");
-        for (String s : cmdList) {
-            argMsg.append(" ").append(s);
-        }
-        logger.log(Level.INFO, argMsg.toString());
+
+        logger.info("arg: {}", cmdList);
         return cmdList;
     }
-    private static final Pattern PATTERN_TIME = Pattern.compile("time=(\\d+)");
+    private static final Pattern PATTERN_TIME = Pattern.compile("time=(\\d+):(\\d+):(\\d+)");
 
     private int executeFfmpeg(final List<String> cmdList, int duration) throws InterruptedException, IOException {
         Process process = null;
         try {
-            logger.log(Level.INFO, "Processing FFmpeg...");
+            logger.info("Processing FFmpeg...");
             process = Runtime.getRuntime().exec(cmdList.toArray(new String[0]));
             BufferedReader ebr = new BufferedReader(new InputStreamReader(
                     process.getErrorStream()));
@@ -221,14 +217,18 @@ public class Convert extends Worker<ConvertResult, ConvertProgress> {
                     final Matcher m = PATTERN_TIME.matcher(msg);
                     double per = -1.0;
                     if (m.find()) {
-                        final String strTime = m.group(1);
-                        final double time = Double.parseDouble(strTime);
+                        final double hour = Integer.parseInt(m.group(1));
+                        final double min = Integer.parseInt(m.group(2));
+                        final double sec = Integer.parseInt(m.group(3));
+                        final double time = ((hour * 60) + min) * 60 + sec;
                         per = 100.0 * time / duration;
-                        logger.log(Level.FINEST, "time:{0}, duration:{1}", new Object[]{time, duration});
+                        if (logger.isTraceEnabled()) {
+                            logger.trace("time:{}, duration:{}", time, duration);
+                        }
                     }
                     publish(new ConvertProgress(PROCESS, per, msg));
                 } else if (!msg.endsWith("No accelerated colorspace conversion found")) {
-                    logger.log(Level.INFO, msg);
+                    logger.warn(msg);
                 }
 
                 checkStop();