| 38 | | this.mplayerPath = mplayerPath; |
|---|
| 39 | | isCanceled = false; |
|---|
| 40 | | |
|---|
| 41 | | notSplitVideos = new ArrayList(); |
|---|
| 42 | | |
|---|
| 43 | | progressDialogInfo.setTotalJobs(this.jobs.size()); |
|---|
| 44 | | } |
|---|
| 45 | | |
|---|
| 46 | | public static List removeInvalidJobs(List jobs) { |
|---|
| 47 | | List newJobs = new ArrayList(); |
|---|
| 48 | | |
|---|
| 49 | | for (int i = 0; i < jobs.size(); i++) { |
|---|
| 50 | | boolean validOutput = true; |
|---|
| 51 | | if (jobs.get(i) instanceof OutputVideoInfo) { |
|---|
| 52 | | OutputVideoInfo outputVideoInfo = (OutputVideoInfo) jobs.get(i); |
|---|
| 53 | | |
|---|
| 54 | | if (outputVideoInfo.getOutputVideo().equals("")) |
|---|
| 55 | | continue; |
|---|
| 56 | | |
|---|
| 57 | | if (!outputVideoInfo.getOutputVideo().endsWith("." + ConverterOptions.getCurrentProfile().getWrapperFormat()) && !outputVideoInfo.getOutputVideo().equals("")) |
|---|
| 58 | | outputVideoInfo.setOutputVideo(outputVideoInfo.getOutputVideo() + "." + ConverterOptions.getCurrentProfile().getWrapperFormat()); |
|---|
| 59 | | |
|---|
| 60 | | if (!new File(outputVideoInfo.getOutputVideo()).getParentFile().exists()) |
|---|
| 61 | | validOutput = new File(outputVideoInfo.getOutputVideo()).getParentFile().mkdirs(); |
|---|
| 62 | | |
|---|
| 63 | | validOutput = validOutput && new File(outputVideoInfo.getOutputVideo()).getParentFile().canWrite(); |
|---|
| 64 | | } |
|---|
| 65 | | |
|---|
| 66 | | if (jobs.get(i) instanceof SingleVideoInfo) { |
|---|
| 67 | | SingleVideoInfo singleVideoInfo = (SingleVideoInfo) jobs.get(i); |
|---|
| 68 | | if (new File(singleVideoInfo.getInputVideo()).exists() && validOutput) |
|---|
| 69 | | newJobs.add(singleVideoInfo); |
|---|
| 70 | | } else if (jobs.get(i) instanceof DirectoryInfo) { |
|---|
| 71 | | DirectoryInfo directoryInfo = (DirectoryInfo) jobs.get(i); |
|---|
| 72 | | if (new File(directoryInfo.getInputDirectory()).exists() && !directoryInfo.getOutputDirectory().equals("")) |
|---|
| 73 | | if (!new File(directoryInfo.getOutputDirectory()).exists()) |
|---|
| 74 | | validOutput = new File(directoryInfo.getOutputDirectory()).mkdirs(); |
|---|
| 75 | | |
|---|
| 76 | | if (validOutput) |
|---|
| 77 | | newJobs.add(directoryInfo); |
|---|
| 78 | | } else if (jobs.get(i) instanceof DVDInfo) { |
|---|
| 79 | | DVDInfo dvdInfo = (DVDInfo) jobs.get(i); |
|---|
| 80 | | if (!dvdInfo.getDrive().equals("") && validOutput) |
|---|
| 81 | | newJobs.add(dvdInfo); |
|---|
| 82 | | } else if (jobs.get(i) instanceof ManualSplitInfo) { |
|---|
| 83 | | ManualSplitInfo manualSplitInfo = (ManualSplitInfo) jobs.get(i); |
|---|
| 84 | | if (!manualSplitInfo.getVideo().equals("") && manualSplitInfo.getMarks().length > 2) |
|---|
| 85 | | newJobs.add(manualSplitInfo); |
|---|
| 86 | | } else if (jobs.get(i) instanceof JoinVideosInfo) { |
|---|
| 87 | | JoinVideosInfo joinVideosInfo = (JoinVideosInfo) jobs.get(i); |
|---|
| 88 | | if (joinVideosInfo.getInputVideos().length > 0 && validOutput) |
|---|
| 89 | | newJobs.add(joinVideosInfo); |
|---|
| 90 | | } |
|---|
| 91 | | } |
|---|
| 92 | | |
|---|
| 93 | | return newJobs; |
|---|
| 94 | | } |
|---|
| 95 | | |
|---|
| 96 | | public static List expandSingleJobsToMultiple(List jobs) { |
|---|
| 97 | | List newJobs = new ArrayList(); |
|---|
| 98 | | |
|---|
| 99 | | for (int i = 0; i < jobs.size(); i++) |
|---|
| 100 | | if (jobs.get(i) instanceof DirectoryInfo) |
|---|
| 101 | | newJobs.addAll(convertDirectoryToSingleVideos((DirectoryInfo) jobs.get(i))); |
|---|
| 102 | | else if (jobs.get(i) instanceof DVDInfo) |
|---|
| 103 | | newJobs.addAll(separateDVDChaptersToSingleDVDJobs((DVDInfo) jobs.get(i))); |
|---|
| 104 | | else if (jobs.get(i) instanceof ManualSplitInfo) |
|---|
| 105 | | newJobs.addAll(separateMultipleSplitJobsToOneSplitJob((ManualSplitInfo) jobs.get(i))); |
|---|
| 106 | | else |
|---|
| 107 | | newJobs.add(jobs.get(i)); |
|---|
| 108 | | |
|---|
| 109 | | return newJobs; |
|---|
| 110 | | } |
|---|
| 111 | | |
|---|
| 112 | | public static List convertDirectoryToSingleVideos(DirectoryInfo directoryInfo) { |
|---|
| 113 | | List newJobs = new ArrayList(); |
|---|
| 114 | | |
|---|
| 115 | | String[] directory = new File(directoryInfo.getInputDirectory()).list(new VideoFileFilter()); |
|---|
| 116 | | |
|---|
| 117 | | for (int i = 0; i < directory.length; i++) |
|---|
| 118 | | if (new File(directoryInfo.getInputDirectory() + File.separator + directory[i]).isDirectory() && directoryInfo.getConvertSubdirectories()) |
|---|
| 119 | | newJobs.addAll(convertDirectoryToSingleVideos(new DirectoryAdapter(directoryInfo.getInputDirectory() + File.separator + directory[i], directoryInfo.getOutputDirectory() + File.separator + directory[i], directoryInfo.getConvertSubdirectories()))); |
|---|
| 120 | | else if (new File(directoryInfo.getInputDirectory() + File.separator + directory[i]).isFile()) |
|---|
| 121 | | newJobs.add(new SingleVideoAdapter(directoryInfo.getInputDirectory() + File.separator + directory[i], directoryInfo.getOutputDirectory() + File.separator + directory[i].substring(0, directory[i].lastIndexOf('.')) + "." + ConverterOptions.getCurrentProfile().getProfileName() + ".avi")); |
|---|
| 122 | | |
|---|
| 123 | | return newJobs; |
|---|
| 124 | | } |
|---|
| 125 | | |
|---|
| 126 | | public static List separateDVDChaptersToSingleDVDJobs(DVDInfo dvdInfo) { |
|---|
| 127 | | List newJobs = new ArrayList(); |
|---|
| 128 | | |
|---|
| 129 | | Chapters[] chapters = dvdInfo.getChapters(); |
|---|
| 130 | | |
|---|
| 131 | | if (chapters == null) |
|---|
| 132 | | newJobs.add(dvdInfo); |
|---|
| 133 | | else |
|---|
| 134 | | for (int i = 0; i < chapters.length; i++) { |
|---|
| 135 | | String outputVideo = ""; |
|---|
| 136 | | if (chapters[i].getFirstChapter() == chapters[i].getLastChapter()) |
|---|
| 137 | | outputVideo = dvdInfo.getOutputVideo().substring(0, dvdInfo.getOutputVideo().lastIndexOf('.')) + ".ch" + chapters[i].getFirstChapterPadded() + ".avi"; |
|---|
| 138 | | else |
|---|
| 139 | | outputVideo = dvdInfo.getOutputVideo().substring(0, dvdInfo.getOutputVideo().lastIndexOf('.')) + ".ch" + chapters[i].getFirstChapterPadded() + "-" + chapters[i].getLastChapterPadded() + ".avi"; |
|---|
| 140 | | |
|---|
| 141 | | newJobs.add(new DVDAdapter(dvdInfo.getDrive(), dvdInfo.getTitle(), new Chapters[]{chapters[i]}, dvdInfo.getAudioStream(), dvdInfo.getSubtitles(), outputVideo)); |
|---|
| 142 | | } |
|---|
| 143 | | |
|---|
| 144 | | return newJobs; |
|---|
| 145 | | } |
|---|
| 146 | | |
|---|
| 147 | | public static List separateMultipleSplitJobsToOneSplitJob(ManualSplitInfo manualSplitInfo) { |
|---|
| 148 | | List newJobs = new ArrayList(); |
|---|
| 149 | | |
|---|
| 150 | | for (int i = 0; (i + 1) < manualSplitInfo.getMarks().length; i++) |
|---|
| 151 | | newJobs.add(new ManualSplitAdapter(manualSplitInfo.getVideo(), new Mark[]{manualSplitInfo.getMarks()[i], manualSplitInfo.getMarks()[i + 1]}, i + 1)); |
|---|
| 152 | | |
|---|
| 153 | | return newJobs; |
|---|
| 154 | | } |
|---|
| 155 | | |
|---|
| 156 | | public static List checkForOverwritingFiles(List jobs) { |
|---|
| 157 | | List newJobs = new ArrayList(); |
|---|
| 158 | | |
|---|
| 159 | | for (int i = 0; i < jobs.size(); i++) { |
|---|
| 160 | | if (!(jobs.get(i) instanceof OutputVideoInfo)) |
|---|
| 161 | | newJobs.add(jobs.get(i)); |
|---|
| 162 | | else if (new File(((OutputVideoInfo) jobs.get(i)).getOutputVideo()).exists()) { |
|---|
| 163 | | if (OverwriteDialog.overwriteFile(((OutputVideoInfo) jobs.get(i)).getOutputVideo())) |
|---|
| 164 | | newJobs.add(jobs.get(i)); |
|---|
| 165 | | } else |
|---|
| 166 | | newJobs.add(jobs.get(i)); |
|---|
| 167 | | } |
|---|
| 168 | | |
|---|
| 169 | | return newJobs; |
|---|
| 191 | | isCanceled = true; |
|---|
| 192 | | |
|---|
| 193 | | if (proc != null) |
|---|
| 194 | | proc.destroy(); |
|---|
| 195 | | } |
|---|
| 196 | | |
|---|
| 197 | | private List prepareBaseCommandList(String inputVideo, String outputVideo, MPlayerInfo info) { |
|---|
| 198 | | List commandList = new ArrayList(); |
|---|
| 199 | | |
|---|
| 200 | | commandList.add(mplayerPath + MPlayerInfo.MENCODER_BIN); |
|---|
| 201 | | |
|---|
| 202 | | commandList.add(inputVideo); |
|---|
| 203 | | commandList.add("-o"); |
|---|
| 204 | | commandList.add(outputVideo); |
|---|
| 205 | | |
|---|
| 206 | | if (ConverterOptions.getCurrentProfile().getWrapperFormat().equals("mp4")) { |
|---|
| 207 | | commandList.add("-of"); |
|---|
| 208 | | commandList.add("lavf"); |
|---|
| 209 | | commandList.add("-lavfopts"); |
|---|
| 210 | | commandList.add("format=mp4:i_certify_that_my_video_stream_does_not_use_b_frames"); |
|---|
| 211 | | } |
|---|
| 212 | | |
|---|
| 213 | | commandList.add("-ovc"); |
|---|
| 214 | | if (ConverterOptions.getCurrentProfile().getVideoFormat().equals("h264")) { |
|---|
| 215 | | commandList.add("x264"); |
|---|
| 216 | | commandList.add("-x264encopts"); |
|---|
| 217 | | commandList.add("bitrate=" + ConverterOptions.getVideoBitrate() + ":bframes=0:level_idc=13:nocabac"); |
|---|
| 218 | | } else { |
|---|
| 219 | | commandList.add("xvid"); |
|---|
| 220 | | commandList.add("-xvidencopts"); |
|---|
| 221 | | commandList.add("bitrate=" + ConverterOptions.getVideoBitrate() + ":max_bframes=0"); |
|---|
| 222 | | } |
|---|
| 223 | | |
|---|
| 224 | | commandList.add("-oac"); |
|---|
| 225 | | if (ConverterOptions.getCurrentProfile().getAudioFormat().equals("aac")) { |
|---|
| 226 | | commandList.add("faac"); |
|---|
| 227 | | commandList.add("-faacopts"); |
|---|
| 228 | | commandList.add("br=" + ConverterOptions.getAudioBitrate() + ":object=1"); |
|---|
| 229 | | } else { |
|---|
| 230 | | commandList.add("mp3lame"); |
|---|
| 231 | | commandList.add("-lameopts"); |
|---|
| 232 | | commandList.add("mode=0:cbr:br=" + ConverterOptions.getAudioBitrate()); |
|---|
| 233 | | } |
|---|
| 234 | | |
|---|
| 235 | | double ofps = (info.getFrameRate() > ConverterOptions.getCurrentProfile().getMaxFrameRate() ? ConverterOptions.getCurrentProfile().getMaxFrameRate() : info.getFrameRate()); |
|---|
| 236 | | if (info.getFrameRate() != ofps && info.getFrameRate() < 1000) { // HACK: wmv always shows 1000 fps |
|---|
| 237 | | commandList.add("-vf-add"); |
|---|
| 238 | | commandList.add("filmdint=io=" + ((int) Math.round(info.getFrameRate() * 1000)) + ":" + ((int) Math.round(ofps * 1000))); |
|---|
| 239 | | } |
|---|
| 240 | | |
|---|
| 241 | | int scaledWidth = ConverterOptions.getDimensions().getWidth(); |
|---|
| 242 | | int scaledHeight = (info.getDimensions().getHeight() * ConverterOptions.getDimensions().getWidth()) / info.getDimensions().getWidth(); |
|---|
| 243 | | |
|---|
| 244 | | if (scaledHeight > ConverterOptions.getDimensions().getHeight()) { |
|---|
| 245 | | scaledWidth = (scaledWidth * ConverterOptions.getDimensions().getHeight()) / scaledHeight; |
|---|
| 246 | | scaledHeight = ConverterOptions.getDimensions().getHeight(); |
|---|
| 247 | | } |
|---|
| 248 | | |
|---|
| 249 | | commandList.add("-vf-add"); |
|---|
| 250 | | if (ConverterOptions.getPanAndScan()) |
|---|
| 251 | | commandList.add("scale=" + ((int) ((info.getDimensions().getWidth()) * (((double) ConverterOptions.getDimensions().getHeight()) / (double) info.getDimensions().getHeight()))) + ":" + ConverterOptions.getDimensions().getHeight() + ",crop=" + ConverterOptions.getDimensions().getWidth() + ":" + ConverterOptions.getDimensions().getHeight()); |
|---|
| 252 | | else |
|---|
| 253 | | commandList.add("scale=" + scaledWidth + ":" + scaledHeight + ",expand=" + ConverterOptions.getDimensions().getWidth() + ":" + ConverterOptions.getDimensions().getHeight()); |
|---|
| 254 | | |
|---|
| 255 | | commandList.add("-vf-add"); |
|---|
| 256 | | commandList.add("harddup"); |
|---|
| 257 | | |
|---|
| 258 | | if (ConverterOptions.getVolumeFilter().equals(VolumeFilter.VOLNORM)) { |
|---|
| 259 | | commandList.add("-af"); |
|---|
| 260 | | commandList.add("volnorm"); |
|---|
| 261 | | } else if (ConverterOptions.getVolumeFilter().equals(VolumeFilter.VOLUME)) { |
|---|
| 262 | | commandList.add("-af"); |
|---|
| 263 | | commandList.add("volume=" + ConverterOptions.getGain()); |
|---|
| 264 | | } |
|---|
| 265 | | |
|---|
| 266 | | commandList.add("-ofps"); |
|---|
| 267 | | commandList.add("" + ofps); |
|---|
| 268 | | commandList.add("-srate"); |
|---|
| 269 | | commandList.add("44100"); |
|---|
| 270 | | |
|---|
| 271 | | if (!ConverterOptions.getAutoSync()) { |
|---|
| 272 | | commandList.add("-delay"); |
|---|
| 273 | | commandList.add("" + (ConverterOptions.getAudioDelay() / 1000.0)); |
|---|
| 274 | | } |
|---|
| 275 | | |
|---|
| 276 | | return commandList; |
|---|
| 277 | | } |
|---|
| 278 | | |
|---|
| 279 | | public void convertSingleVideo(SingleVideoInfo singleVideoInfo) { |
|---|
| 280 | | Logger.logMessage("Single Video: " + singleVideoInfo.getInputVideo(), Logger.INFO); |
|---|
| 281 | | |
|---|
| 282 | | progressDialogInfo.setInputVideo(new File(singleVideoInfo.getInputVideo()).getName()); |
|---|
| 283 | | progressDialogInfo.setOutputVideo(new File(singleVideoInfo.getOutputVideo()).getName()); |
|---|
| 284 | | progressDialogInfo.setStatus("Gathering information about the input video..."); |
|---|
| 285 | | |
|---|
| 286 | | MPlayerInfo info = new MPlayerInfo(singleVideoInfo.getInputVideo(), mplayerPath); |
|---|
| 287 | | if (!info.videoSupported()) { |
|---|
| 288 | | Logger.logMessage("Unsupported video", Logger.ERROR); |
|---|
| 289 | | return; |
|---|
| 290 | | } |
|---|
| 291 | | |
|---|
| 292 | | List commandList = prepareBaseCommandList(singleVideoInfo.getInputVideo(), singleVideoInfo.getOutputVideo(), info); |
|---|
| 293 | | |
|---|
| 294 | | String[] command = new String[commandList.size()]; |
|---|
| 295 | | for (int i = 0; i < command.length; i++) |
|---|
| 296 | | command[i] = (String) commandList.get(i); |
|---|
| 297 | | |
|---|
| 298 | | if (!isCanceled) { |
|---|
| 299 | | new File(singleVideoInfo.getOutputVideo()).getParentFile().mkdirs(); |
|---|
| 300 | | progressDialogInfo.setStatus("Converting"); |
|---|
| 301 | | splitVideo(singleVideoInfo.getOutputVideo(), runConversionCommand(command)); |
|---|
| 302 | | } |
|---|
| 303 | | } |
|---|
| 304 | | |
|---|
| 305 | | public void convertDVD(DVDInfo dvdInfo) { |
|---|
| 306 | | String inputVideo = "Title " + dvdInfo.getTitle() + " of the DVD at " + dvdInfo.getDrive(); |
|---|
| 307 | | |
|---|
| 308 | | Chapters[] chapters = dvdInfo.getChapters(); |
|---|
| 309 | | if (chapters != null) { |
|---|
| 310 | | if (chapters[0].getFirstChapter() == chapters[0].getLastChapter()) |
|---|
| 311 | | inputVideo = "Chapter " + chapters[0].getFirstChapter() + " of " + inputVideo; |
|---|
| 312 | | else |
|---|
| 313 | | inputVideo = "Chapters " + chapters[0].getFirstChapter() + "-" + chapters[0].getLastChapter() + " of " + inputVideo; |
|---|
| 314 | | } |
|---|
| 315 | | |
|---|
| 316 | | Logger.logMessage("DVD: " + inputVideo, Logger.INFO); |
|---|
| 317 | | |
|---|
| 318 | | progressDialogInfo.setInputVideo(inputVideo); |
|---|
| 319 | | progressDialogInfo.setOutputVideo(new File(dvdInfo.getOutputVideo()).getName()); |
|---|
| 320 | | progressDialogInfo.setStatus("Gathering information about the input video..."); |
|---|
| 321 | | |
|---|
| 322 | | MPlayerInfo info = new MPlayerInfo("dvd://" + dvdInfo.getTitle(), dvdInfo.getDrive(), mplayerPath); |
|---|
| 323 | | |
|---|
| 324 | | List commandList = prepareBaseCommandList("dvd://" + dvdInfo.getTitle(), dvdInfo.getOutputVideo(), info); |
|---|
| 325 | | |
|---|
| 326 | | commandList.add("-dvd-device"); |
|---|
| 327 | | commandList.add(dvdInfo.getDrive()); |
|---|
| 328 | | |
|---|
| 329 | | if (dvdInfo.getAudioStream() > -1) { |
|---|
| 330 | | commandList.add("-aid"); |
|---|
| 331 | | commandList.add("" + dvdInfo.getAudioStream()); |
|---|
| 332 | | } |
|---|
| 333 | | |
|---|
| 334 | | if (dvdInfo.getSubtitles() > -1) { |
|---|
| 335 | | commandList.add("-sid"); |
|---|
| 336 | | commandList.add("" + dvdInfo.getSubtitles()); |
|---|
| 337 | | } |
|---|
| 338 | | |
|---|
| 339 | | if (dvdInfo.getChapters() != null) { |
|---|
| 340 | | commandList.add("-chapter"); |
|---|
| 341 | | commandList.add(dvdInfo.getChapters()[0].getFirstChapter() + "-" + dvdInfo.getChapters()[0].getLastChapter()); |
|---|
| 342 | | } |
|---|
| 343 | | |
|---|
| 344 | | String[] command = new String[commandList.size()]; |
|---|
| 345 | | for (int i = 0; i < command.length; i++) |
|---|
| 346 | | command[i] = (String) commandList.get(i); |
|---|
| 347 | | |
|---|
| 348 | | if (!isCanceled) { |
|---|
| 349 | | new File(dvdInfo.getOutputVideo()).getParentFile().mkdirs(); |
|---|
| 350 | | progressDialogInfo.setStatus("Converting"); |
|---|
| 351 | | splitVideo(dvdInfo.getOutputVideo(), runConversionCommand(command)); |
|---|
| 352 | | } |
|---|
| 353 | | } |
|---|
| 354 | | |
|---|
| 355 | | public void manuallySplitVideo(ManualSplitInfo manualSplitInfo) { |
|---|
| 356 | | Logger.logMessage("Manual Split: " + manualSplitInfo.getVideo(), Logger.INFO); |
|---|
| 357 | | |
|---|
| 358 | | String outputVideo = manualSplitInfo.getVideo().substring(0, manualSplitInfo.getVideo().lastIndexOf('.')) + ".part" + manualSplitInfo.getPart() + ".avi"; |
|---|
| 359 | | |
|---|
| 360 | | progressDialogInfo.setInputVideo(manualSplitInfo.getVideo()); |
|---|
| 361 | | progressDialogInfo.setOutputVideo(outputVideo); |
|---|
| 362 | | progressDialogInfo.setStatus("Splitting"); |
|---|
| 363 | | |
|---|
| 364 | | if (manualSplitInfo.getMarks()[0].getTime() == Mark.START_MARK) |
|---|
| 365 | | runConversionCommand(new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, manualSplitInfo.getVideo(), "-o", outputVideo, "-ovc", "copy", "-oac", "copy", "-endpos", "" + manualSplitInfo.getMarks()[1].getTime()}); |
|---|
| 366 | | else if (manualSplitInfo.getMarks()[1].getTime() == Mark.END_MARK) |
|---|
| 367 | | runConversionCommand(new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, manualSplitInfo.getVideo(), "-o", outputVideo, "-ovc", "copy", "-oac", "copy", "-ss", "" + manualSplitInfo.getMarks()[0].getTime()}); |
|---|
| 368 | | else |
|---|
| 369 | | runConversionCommand(new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, manualSplitInfo.getVideo(), "-o", outputVideo, "-ovc", "copy", "-oac", "copy", "-ss", "" + manualSplitInfo.getMarks()[0].getTime(), "-endpos", "" + (manualSplitInfo.getMarks()[1].getTime() - manualSplitInfo.getMarks()[0].getTime())}); |
|---|
| 370 | | } |
|---|
| 371 | | |
|---|
| 372 | | public void joinVideos(JoinVideosInfo joinVideosInfo) { |
|---|
| 373 | | try { |
|---|
| 374 | | String[] inputVideos = joinVideosInfo.getInputVideos(); |
|---|
| 375 | | /* String[] tempVideos = new String[inputVideos.length]; |
|---|
| 376 | | |
|---|
| 377 | | for (int i = 0; i < inputVideos.length; i++) { |
|---|
| 378 | | File tempFile = File.createTempFile("iriverter-", ".avi"); |
|---|
| 379 | | tempFile.deleteOnExit(); |
|---|
| 380 | | |
|---|
| 381 | | progressDialogInfo.setInputVideo(new File(inputVideos[i]).getName()); |
|---|
| 382 | | progressDialogInfo.setOutputVideo(tempFile.getName()); |
|---|
| 383 | | progressDialogInfo.setStatus("Fixing header"); |
|---|
| 384 | | |
|---|
| 385 | | runConversionCommand(new String[]{MPlayerInfo.getMPlayerPath() + "mencoder", "-idx", inputVideos[i], "-o", tempFile.toString(), "-ovc", "copy", "-oac", "copy"}); |
|---|
| 386 | | |
|---|
| 387 | | tempVideos[i] = tempFile.toString(); |
|---|
| 388 | | } */ |
|---|
| 389 | | |
|---|
| 390 | | File tempFile = File.createTempFile("iriverter-", ".avi"); |
|---|
| 391 | | tempFile.deleteOnExit(); |
|---|
| 392 | | |
|---|
| 393 | | Logger.logMessage("Join Videos: " + tempFile, Logger.INFO); |
|---|
| 394 | | |
|---|
| 395 | | progressDialogInfo.setOutputVideo(tempFile.getName()); |
|---|
| 396 | | progressDialogInfo.setStatus("Concatenating videos to a temporary file..."); |
|---|
| 397 | | |
|---|
| 398 | | FileOutputStream out = new FileOutputStream(tempFile); |
|---|
| 399 | | // SequenceInputStream in = new SequenceInputStream(new ListOfFiles(tempVideos, progressDialogInfo)); |
|---|
| 400 | | SequenceInputStream in = new SequenceInputStream(new ListOfFiles(inputVideos, progressDialogInfo)); |
|---|
| 401 | | byte[] bytes = new byte[4096]; |
|---|
| 402 | | int length; |
|---|
| 403 | | |
|---|
| 404 | | while ((length = in.read(bytes)) != -1 && !isCanceled) |
|---|
| 405 | | out.write(bytes, 0, length); |
|---|
| 406 | | |
|---|
| 407 | | progressDialogInfo.setPercentComplete(100); |
|---|
| 408 | | |
|---|
| 409 | | if (!isCanceled) { |
|---|
| 410 | | Logger.logMessage("Writing header...", Logger.INFO); |
|---|
| 411 | | |
|---|
| 412 | | progressDialogInfo.setInputVideo(tempFile.getName()); |
|---|
| 413 | | progressDialogInfo.setOutputVideo(new File(joinVideosInfo.getOutputVideo()).getName()); |
|---|
| 414 | | progressDialogInfo.setStatus("Writing header"); |
|---|
| 415 | | splitVideo(joinVideosInfo.getOutputVideo(), runConversionCommand(new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, "-forceidx", tempFile.toString(), "-o", joinVideosInfo.getOutputVideo(), "-ovc", "copy", "-oac", "copy"})); |
|---|
| 416 | | } |
|---|
| 417 | | } catch (IOException e) { |
|---|
| 418 | | // empty |
|---|
| 419 | | } |
|---|
| 420 | | } |
|---|
| 421 | | |
|---|
| 422 | | public int runConversionCommand(String[] command) { |
|---|
| 423 | | MencoderStreamParser inputStream = null; |
|---|
| 424 | | MencoderStreamParser errorStream = null; |
|---|
| 425 | | |
|---|
| 426 | | String commandStr = ""; |
|---|
| 427 | | for (int i = 0; i < command.length; i++) |
|---|
| 428 | | commandStr += command[i] + " "; |
|---|
| 429 | | Logger.logMessage(commandStr, Logger.INFO); |
|---|
| 430 | | |
|---|
| 431 | | try { |
|---|
| 432 | | proc = Runtime.getRuntime().exec(command); |
|---|
| 433 | | |
|---|
| 434 | | inputStream = new MencoderStreamParser(progressDialogInfo); |
|---|
| 435 | | inputStream.parse(new BufferedReader(new InputStreamReader(proc.getInputStream()))); |
|---|
| 436 | | errorStream = new MencoderStreamParser(progressDialogInfo); |
|---|
| 437 | | errorStream.parse(new BufferedReader(new InputStreamReader(proc.getErrorStream()))); |
|---|
| 438 | | |
|---|
| 439 | | exitCode = proc.waitFor(); |
|---|
| 440 | | proc = null; |
|---|
| 441 | | } catch (Exception e) { |
|---|
| 442 | | e.printStackTrace(); |
|---|
| 443 | | } |
|---|
| 444 | | |
|---|
| 445 | | if (exitCode != 0) |
|---|
| 446 | | isCanceled = true; |
|---|
| 447 | | |
|---|
| 448 | | return isCanceled ? 0 : ((errorStream.getLength() > -1) ? errorStream.getLength() : inputStream.getLength()); |
|---|
| 449 | | } |
|---|
| 450 | | |
|---|
| 451 | | public void splitVideo(String inputVideo, int length) { |
|---|
| 452 | | if (length < ConverterOptions.getSplitTime() * 60) |
|---|
| 453 | | return; |
|---|
| 454 | | |
|---|
| 455 | | if (!ConverterOptions.getAutoSplit()) { |
|---|
| 456 | | notSplitVideos.add(inputVideo); |
|---|
| 457 | | return; |
|---|
| 458 | | } |
|---|
| 459 | | |
|---|
| 460 | | int pieces = (length / (ConverterOptions.getSplitTime() * 60)) + 1; |
|---|
| 461 | | for (int i = 0; i < pieces; i++) { |
|---|
| 462 | | String outputVideo = inputVideo.substring(0, inputVideo.lastIndexOf('.')) + ".part" + (i + 1) + ".avi"; |
|---|
| 463 | | |
|---|
| 464 | | progressDialogInfo.setInputVideo(new File(inputVideo).getName()); |
|---|
| 465 | | progressDialogInfo.setOutputVideo(new File(outputVideo).getName()); |
|---|
| 466 | | progressDialogInfo.setStatus("Splitting"); |
|---|
| 467 | | |
|---|
| 468 | | if ((i + 1) == 1) |
|---|
| 469 | | runConversionCommand(new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, inputVideo, "-o", outputVideo, "-ovc", "copy", "-oac", "copy", "-endpos", "" + (length / pieces)}); |
|---|
| 470 | | else if ((i + 1) == pieces) |
|---|
| 471 | | runConversionCommand(new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, inputVideo, "-o", outputVideo, "-ovc", "copy", "-oac", "copy", "-ss", "" + (length / pieces) * i}); |
|---|
| 472 | | else |
|---|
| 473 | | runConversionCommand(new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, inputVideo, "-o", outputVideo, "-ovc", "copy", "-oac", "copy", "-ss", "" + (length / pieces) * i, "-endpos", "" + (length / pieces)}); |
|---|
| 474 | | } |
|---|
| 475 | | } |
|---|
| 476 | | |
|---|
| 477 | | public List getNotSplitVideos() { |
|---|
| 478 | | return notSplitVideos; |
|---|
| | 24 | currentCommand.cancel(); |
|---|