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;
-import saccubus.conv.NicoXMLReader.ProcessType;
+import saccubus.conv.CommentType;
import saccubus.util.FfmpegUtil;
import saccubus.worker.Worker;
import saccubus.worker.WorkerListener;
*/
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;
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
final HideCondition hide = profile.getNgSetting();
publish(new ConvertProgress(PROCESS, -1.0, "コメントの中間ファイルへの変換中"));
- ConvertToVideoHook.convert(EnumSet.of(ProcessType.NORMAL), commentFile, transformedComment, hide.getId(),
+ ConvertToVideoHook.convert(EnumSet.of(CommentType.NORMAL), commentFile, transformedComment, hide.getId(),
hide.getWord());
publish(new ConvertProgress(PROCESS, -1.0, "投稿者コメントの中間ファイルへの変換中"));
- ConvertToVideoHook.convert(EnumSet.of(ProcessType.OWNER), commentFile, transformedOwner, hide.getId(),
+ ConvertToVideoHook.convert(EnumSet.of(CommentType.OWNER), commentFile, transformedOwner, hide.getId(),
hide.getWord());
}
final int code = convert(outputFile, transformedComment, transformedOwner);
if (code != 0) {
- throw new IOException("ffmpeg実行失敗: " + outputFile.getPath());
+ throw new IOException("ffmpeg実行失敗(code " + code + "): " + outputFile.getPath());
}
publish(new ConvertProgress(PROCESS, 100.0, "変換が正常に終了しました。"));
return new ConvertResult(true, outputFile.getName());
try {
duration = util.getDuration();
} catch (IOException ex) {
- logger.log(Level.FINE, "動画再生時間を取得できませんでした: {0}", target);
+ logger.info("動画再生時間を取得できませんでした: {}", target);
duration = Integer.MAX_VALUE;
}
return executeFfmpeg(arguments, duration);
cmdList.add(opt);
}
}
- final Info info = MediaInfo.getInfo(new File("bin", "MediaInfo"), targetVideoFile);
+ final Info info = MediaInfo.getInfo(profile.getMediaInfo(), targetVideoFile);
// 4:3 なら1.33, 16:9 なら1.76
final boolean isHD = ((double) info.getWidth() / (double) info.getHeight() > 1.5);
if (ffop.isResize()) {
}
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()));
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);
+ logger.trace(msg);
+ }
}
publish(new ConvertProgress(PROCESS, per, msg));
} else if (!msg.endsWith("No accelerated colorspace conversion found")) {
- logger.log(Level.INFO, msg);
+ logger.warn(msg);
+ } else {
+ logger.info(msg);
}
checkStop();