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.util.FfmpegUtil;
import saccubus.worker.Worker;
import saccubus.worker.WorkerListener;
import saccubus.worker.profile.ConvertProfile;
final File target = (fwsFile != null) ? fwsFile : videoFile;
final List<String> arguments = createArguments(target, transformedComment, outputFile);
- return executeFfmpeg(arguments);
+ final int duration = new FfmpegUtil(profile.getFfmpeg(), target).getDuration();
+ return executeFfmpeg(arguments, duration);
} finally {
if (fwsFile != null && fwsFile.exists()) {
fwsFile.delete();
return cmdList;
}
- private int executeFfmpeg(final List<String> cmdList) throws InterruptedException, IOException {
+ private static final Pattern PATTERN_TIME = Pattern.compile("time=(\\d+)");
+
+ private int executeFfmpeg(final List<String> cmdList, int duration) throws InterruptedException, IOException {
Process process = null;
try {
logger.log(Level.INFO, "Processing FFmpeg...");
String msg;
while ((msg = ebr.readLine()) != null) {
if (msg.startsWith("frame=")) {
- // TODO パーセンテージ計算、出力
- publish(new ConvertProgress(PROCESS, 0.0, msg));
+ final Matcher m = PATTERN_TIME.matcher(msg);
+ double per = -1.0;
+ if (m.find()) {
+ final String strTime = m.group(1);
+ final int time = Integer.parseInt(strTime);
+ per = 100.0 * time / duration;
+ logger.log(Level.FINEST, "time:{0}, duration:{1}", new Object[]{time, duration});
+ }
+ publish(new ConvertProgress(PROCESS, per, msg));
} else if (!msg.endsWith("No accelerated colorspace conversion found")) {
logger.log(Level.INFO, msg);
}