From: yukihane Date: Wed, 21 Sep 2011 08:09:18 +0000 (+0900) Subject: オプショナルコメントの中間ファイル生成とffmpeg引数での引き渡し X-Git-Tag: rel20110922_ver2.1.0~6^2 X-Git-Url: http://git.osdn.net/view?p=coroid%2Finqubus.git;a=commitdiff_plain;h=72fb617267f6719945adbeadc7caa1e264001f7f オプショナルコメントの中間ファイル生成とffmpeg引数での引き渡し --- diff --git a/frontend/src/saccubus/worker/impl/convert/Convert.java b/frontend/src/saccubus/worker/impl/convert/Convert.java index b8449f3..a02524e 100644 --- a/frontend/src/saccubus/worker/impl/convert/Convert.java +++ b/frontend/src/saccubus/worker/impl/convert/Convert.java @@ -12,8 +12,11 @@ import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.EnumMap; import java.util.EnumSet; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.regex.Matcher; @@ -86,44 +89,42 @@ public class Convert extends Worker { final File outputFile = new File(outprof.getDir(), outputPattern.createFileName() + profile.getFfmpegOption().getExtOption()); - File transformedComment = null; - File transformedOwner = null; + final Map tmpComments = new EnumMap<>(CommentType.class); try { if (profile.isCommentOverlay()) { - transformedComment = File.createTempFile("vhk", ".tmp", profile.getTempDir()); - transformedOwner = File.createTempFile("vown", ".tmp", profile.getTempDir()); - final HideCondition hide = profile.getNgSetting(); + for (CommentType ct : CommentType.values()) { + tmpComments.put(ct, File.createTempFile("vhk", ".tmp", profile.getTempDir())); + } - publish(new ConvertProgress(PROCESS, -1.0, "コメントの中間ファイルへの変換中")); - ConvertToVideoHook.convert(EnumSet.of(CommentType.NORMAL), commentFile, transformedComment, hide.getId(), - hide.getWord()); + final HideCondition hide = profile.getNgSetting(); - publish(new ConvertProgress(PROCESS, -1.0, "投稿者コメントの中間ファイルへの変換中")); - ConvertToVideoHook.convert(EnumSet.of(CommentType.OWNER), commentFile, transformedOwner, hide.getId(), - hide.getWord()); + for (CommentType ct : CommentType.values()) { + publish(new ConvertProgress(PROCESS, -1.0, ct.toString() + "の中間ファイルへの変換中")); + ConvertToVideoHook.convert(EnumSet.of(ct), commentFile, tmpComments.get(ct), + hide.getId(), hide.getWord()); + } } checkStop(); publish(new ConvertProgress(PROCESS, -1.0, "動画の変換を開始")); - final int code = convert(outputFile, transformedComment, transformedOwner); + final int code = convert(outputFile, new EnumMap<>(tmpComments)); if (code != 0) { throw new IOException("ffmpeg実行失敗(code " + code + "): " + outputFile.getPath()); } publish(new ConvertProgress(PROCESS, 100.0, "変換が正常に終了しました。")); return new ConvertResult(true, outputFile.getName()); } finally { - if (transformedComment != null && transformedComment.exists()) { - transformedComment.delete(); - } - if (transformedOwner != null && transformedOwner.exists()) { - transformedOwner.delete(); + for(File f : tmpComments.values()) { + if(f != null && f.exists()) { + f.delete(); + } } } } - private int convert(File outputFile, File commentNormal, File commentOwner) throws InterruptedException, IOException { + private int convert(File outputFile, Map tmpComments) throws InterruptedException, IOException { File fwsFile = null; try { final File tmpCws = File.createTempFile("cws", ".swf", profile.getTempDir()); @@ -131,7 +132,7 @@ public class Convert extends Worker { tmpCws.delete(); final File target = (fwsFile != null) ? fwsFile : videoFile; - final List arguments = createArguments(target, outputFile, commentNormal, commentOwner); + final List arguments = createArguments(target, outputFile, tmpComments); final FfmpegUtil util = new FfmpegUtil(profile.getFfmpeg(), target); int duration; try { @@ -148,7 +149,7 @@ public class Convert extends Worker { } } - private List createArguments(final File targetVideoFile, File output, File comment, File commentOwner) + private List createArguments(final File targetVideoFile, File output, Map comments) throws IOException, UnsupportedEncodingException { final ConvertProfile prof = profile; final FfmpegProfile ffop = prof.getFfmpegOption(); @@ -187,14 +188,14 @@ public class Convert extends Worker { } final List avfilterArgs = createAvfilterOptions(ffop.getAvfilterOption()); if (!prof.isVhookDisabled()) { - final String vhookArg = getVhookArg(prof, comment.getPath(), commentOwner.getPath(), isHD); + final String vhookArg = getVhookArg(prof, comments, isHD); if (isNotBlank(vhookArg)) { avfilterArgs.add(vhookArg); } } if (!avfilterArgs.isEmpty()) { cmdList.add("-vfilters"); - final String args = join(avfilterArgs, ", "); + final String args = join(avfilterArgs, ", "); cmdList.add(args); } cmdList.add(output.getPath()); @@ -254,18 +255,17 @@ public class Convert extends Worker { return avfilterArgs; } - private static String getVhookArg(ConvertProfile prof, String commPath, String commOwnerPath, boolean isHD) throws + private static String getVhookArg(ConvertProfile prof, Map comments, boolean isHD) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); sb.append("vhext="); sb.append(prof.getVhook().getPath().replace("\\", "/")); if (prof.isCommentOverlay()) { - 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")); + for(Entry e : comments.entrySet()) { + sb.append("|"); + sb.append(e.getKey().getVhookOptionPrefix()); + sb.append(URLEncoder.encode(e.getValue().getPath().replace("\\", "/"), "Shift_JIS")); + } } sb.append("|"); sb.append("--font:");