2 package saccubus.converter;
4 import java.io.BufferedReader;
6 import java.io.IOException;
7 import java.io.InputStreamReader;
8 import java.io.UnsupportedEncodingException;
9 import java.net.URLEncoder;
10 import saccubus.ConvertStopFlag;
11 import saccubus.conv.ConvertToVideoHook;
12 import saccubus.converter.profile.Ffmpeg;
13 import saccubus.converter.profile.FfmpegOption;
14 import saccubus.converter.profile.NgSetting;
15 import saccubus.net.TextProgressListener;
16 import yukihane.swf.Cws2Fws;
22 public class FfmpegCommand extends AbstractCommand {
24 private final File commentMiddleFile = new File("./vhook.tmp");
25 private final File tcommMiddleFile = new File("./tcomment.tmp");
26 private static final String TMP_CWS = "fws_tmp.swf";
27 private final File commentFile;
28 private final File tcommFile;
29 private final File videoFile;
30 private final File convertedVideoFile;
31 private final Ffmpeg ffmpeg;
33 FfmpegCommand(TextProgressListener listener, ConvertStopFlag flag, File commentFile, File tcommFile,
34 File videoFile, File convertedVideoFile, Ffmpeg ffmpeg) {
35 super(listener, flag);
36 this.commentFile = commentFile;
37 this.tcommFile = tcommFile;
38 this.videoFile = videoFile;
39 this.convertedVideoFile = convertedVideoFile;
44 public boolean execute() throws InterruptedException, IOException {
48 if (commentMiddleFile.exists()) {
49 commentMiddleFile.delete();
51 if (tcommMiddleFile.exists()) {
52 tcommMiddleFile.delete();
57 private boolean exec() throws InterruptedException, IOException {
58 final NgSetting ngSetting = getFfmpeg().getNgSetting();
59 if (commentFile != null) {
60 sendText("
\83R
\83\81\83\93\83g
\82Ì
\92\86\8aÔ
\83t
\83@
\83C
\83\8b\82Ö
\82Ì
\95Ï
\8a·
\92\86");
61 boolean conv = ConvertToVideoHook.convert(commentFile, commentMiddleFile, ngSetting.getId(), ngSetting.
64 sendText("
\83R
\83\81\83\93\83g
\95Ï
\8a·
\82É
\8e¸
\94s
\81B
\83t
\83@
\83C
\83\8b\96¼
\82É
\8eg
\97p
\82Å
\82«
\82È
\82¢
\95¶
\8e\9a\82ª
\8aÜ
\82Ü
\82ê
\82Ä
\82¢
\82é
\82©
\90³
\8bK
\95\
\8c»
\82Ì
\8aÔ
\88á
\82¢
\81H");
69 if (tcommFile != null) {
70 sendText("
\93\8a\8de
\8eÒ
\83R
\83\81\83\93\83g
\82Ì
\92\86\8aÔ
\83t
\83@
\83C
\83\8b\82Ö
\82Ì
\95Ï
\8a·
\92\86");
71 boolean conv = ConvertToVideoHook.convert(tcommFile, tcommMiddleFile, ngSetting.getId(), ngSetting.getWord());
73 sendText("
\83R
\83\81\83\93\83g
\95Ï
\8a·
\82É
\8e¸
\94s
\81B
\83t
\83@
\83C
\83\8b\96¼
\82É
\8eg
\97p
\82Å
\82«
\82È
\82¢
\95¶
\8e\9a\82ª
\8aÜ
\82Ü
\82ê
\82Ä
\82¢
\82é
\82©
\90³
\8bK
\95\
\8c»
\82Ì
\8aÔ
\88á
\82¢
\81H");
78 sendText("
\93®
\89æ
\82Ì
\95Ï
\8a·
\82ð
\8aJ
\8en");
80 if ((code = converting_video(videoFile, convertedVideoFile, (commentFile != null), commentMiddleFile.getPath(), (tcommFile
81 != null), tcommMiddleFile.getPath(), getFfmpeg().getFfmpegOption())) == 0) {
82 sendText("
\95Ï
\8a·
\82ª
\90³
\8fí
\82É
\8fI
\97¹
\82µ
\82Ü
\82µ
\82½
\81B");
85 sendText("
\95Ï
\8a·
\83G
\83\89\81[:" + convertedVideoFile.getPath());
90 private int converting_video(File videoFile, File convertedVideoFile, boolean addComment, String vhook_path,
91 boolean addTcomment, String tcommPath, FfmpegOption ov) throws InterruptedException, IOException {
92 File fwsFile = Cws2Fws.createFws(videoFile, new File(TMP_CWS));
94 StringBuffer sb = new StringBuffer();
96 sb.append(getFfmpeg().getFfmpeg().getPath().replace("\\", "\\\\"));
99 sb.append(ov.getMainOption());
101 sb.append(ov.getInOption());
103 if (fwsFile == null) {
105 sb.append(videoFile.getPath().replace("\\", "\\\\"));
108 sb.append(fwsFile.getPath().replace("\\", "\\\\"));
111 sb.append(ov.getOutOption());
113 sb.append(convertedVideoFile.getPath().replace("\\", "\\\\"));
115 if (!getFfmpeg().isVhookDisabled()) {
116 if (!addVhookSetting(sb, addComment, vhook_path, addTcomment, tcommPath)) {
120 String cmd = sb.substring(0);
121 System.out.println("arg:" + cmd);
123 System.out.println("\n\n----\nProcessing FFmpeg...\n----\n\n");
124 Process process = Runtime.getRuntime().exec(cmd);
125 BufferedReader ebr = new BufferedReader(new InputStreamReader(
126 process.getErrorStream()));
128 while ((e = ebr.readLine()) != null) {
130 if (state.startsWith("frame=")) {
132 } else if (!state.endsWith("No accelerated colorspace conversion found")) {
133 System.out.println(e);
138 } catch (InterruptedException ex) {
145 return process.exitValue();
147 if (fwsFile != null) {
153 private boolean addVhookSetting(StringBuffer sb, boolean addComment, String vhook_path, boolean addTcomment,
156 sb.append(" -vfilters \"vhext=");
157 sb.append(getFfmpeg().getVhook().getPath().replace("\\", "/"));
160 sb.append("--data-user:");
161 sb.append(URLEncoder.encode(vhook_path.replace("\\", "/"), "Shift_JIS"));
165 sb.append("--data-owner:");
166 sb.append(URLEncoder.encode(tcommPath.replace("\\", "/"), "Shift_JIS"));
169 sb.append("--font:");
170 sb.append(URLEncoder.encode(
171 getFfmpeg().getFont().getPath().replace("\\", "/"), "Shift_JIS"));
173 sb.append("--font-index:");
174 sb.append(getFfmpeg().getFontIndex());
176 sb.append("--show-user:");
177 sb.append(getFfmpeg().getMaxNumOfComment());
179 sb.append("--shadow:");
180 sb.append(getFfmpeg().getShadowIndex());
182 if (getFfmpeg().isShowConverting()) {
183 sb.append("--enable-show-video");
186 if (getFfmpeg().isSelfAdjustFontSize()) {
187 sb.append("--enable-fix-font-size");
190 if (getFfmpeg().isCommentOpaque()) {
191 sb.append("--enable-opaque-comment");
195 } catch (UnsupportedEncodingException e) {
201 private Ffmpeg getFfmpeg() {