Changeset 161
- Timestamp:
- 04/14/07 12:52:46 (2 years ago)
- Files:
-
- trunk/src/org/thestaticvoid/iriverter/BlackHole.java (added)
- trunk/src/org/thestaticvoid/iriverter/ConverterUI.java (modified) (5 diffs)
- trunk/src/org/thestaticvoid/iriverter/DVD.java (deleted)
- trunk/src/org/thestaticvoid/iriverter/DVDInfoReader.java (modified) (2 diffs)
- trunk/src/org/thestaticvoid/iriverter/InputVideo.java (added)
- trunk/src/org/thestaticvoid/iriverter/MPlayerInfo.java (modified) (7 diffs)
- trunk/src/org/thestaticvoid/iriverter/MencoderCommand.java (modified) (2 diffs)
- trunk/src/org/thestaticvoid/iriverter/MencoderShit.java (added)
- trunk/src/org/thestaticvoid/iriverter/SingleVideo.java (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/org/thestaticvoid/iriverter/ConverterUI.java
r158 r161 414 414 while (!canceled) 415 415 try { 416 Runtime.getRuntime().exec(new String[]{MPlayerInfo.getMPlayerPath() + MPlayerInfo.MPLAYER_BIN, file}); 416 Process proc = Runtime.getRuntime().exec(new String[]{MPlayerInfo.getMPlayerPath() + MPlayerInfo.MPLAYER_BIN, file}); 417 BlackHole.suck(proc.getInputStream()); 418 BlackHole.suck(proc.getInputStream()); 417 419 canceled = true; 418 420 } catch (IOException io) { … … 438 440 newDirectory(); 439 441 440 if (e.getSource() == newDVD || e.getSource() == newDVDTool)441 newDVD(); 442 /*if (e.getSource() == newDVD || e.getSource() == newDVDTool) 443 newDVD();*/ 442 444 443 445 if (e.getSource() == manualSplit) … … 684 686 while (!canceled) 685 687 try { 686 singleVideo = new SingleVideo(tabFolder, SWT.NONE, tabItem, video, MPlayerInfo.getMPlayerPath());688 singleVideo = new SingleVideo(tabFolder, SWT.NONE, tabItem, new InputVideo(video), MPlayerInfo.getMPlayerPath()); 687 689 tabItem.setControl(singleVideo); 688 690 tabFolder.setSelection(tabItem); … … 718 720 } 719 721 720 private DVD newDVD() {722 /*private DVD newDVD() { 721 723 DVD lastDVD = null; 722 724 for (int i = tabFolder.getItemCount() - 1; i >= 0 && lastDVD == null; i--) … … 737 739 738 740 return dvd; 739 } 741 }*/ 740 742 741 743 private ManualSplit newManualSplit() { trunk/src/org/thestaticvoid/iriverter/DVDInfoReader.java
r157 r161 26 26 public class DVDInfoReader extends Thread { 27 27 private DVDProgressDialog progressDialog; 28 private String drive, mplayerPath; 28 private InputVideo inputVideo; 29 private String mplayerPath; 29 30 private Map titleInfo; 30 31 31 public DVDInfoReader(DVDProgressDialog progressDialog, String drive, String mplayerPath) {32 public DVDInfoReader(DVDProgressDialog progressDialog, InputVideo inputVideo, String mplayerPath) { 32 33 this.progressDialog = progressDialog; 33 this. drive = drive;34 this.inputVideo = inputVideo; 34 35 this.mplayerPath = mplayerPath; 35 36 titleInfo = new LinkedHashMap(); … … 39 40 40 41 public void run() { 41 int numberOfTitles = new MPlayerInfo( "dvd://", drive, mplayerPath).getNumberOfTitles();42 int numberOfTitles = new MPlayerInfo(inputVideo, mplayerPath).getNumberOfTitles(); 42 43 progressDialog.setMaximum(numberOfTitles); 43 44 44 45 for (int i = 1; i <= numberOfTitles; i++) { 45 46 progressDialog.setCurrent(i); 46 MPlayerInfo rawTitleInfo = new MPlayerInfo( "dvd://" + i, drive, mplayerPath);47 MPlayerInfo rawTitleInfo = new MPlayerInfo(new InputVideo("dvd://" + i, inputVideo.getName()), mplayerPath); 47 48 48 49 int length = rawTitleInfo.getLength(); trunk/src/org/thestaticvoid/iriverter/MPlayerInfo.java
r157 r161 2 2 * MPlayerInfo.java 3 3 * Copyright (C) 2005-2007 James Lee 4 * Copyright (C) 2007 David Grundberg 4 5 * 5 6 * This program is free software; you can redistribute it and/or … … 34 35 private boolean commandFound = true; 35 36 36 public MPlayerInfo(String video) throws MPlayerNotFoundException { 37 this(video, MPlayerInfo.getMPlayerPath()); 38 } 39 40 public MPlayerInfo(String video, String mplayerPath) { 41 this(video, null, mplayerPath); 42 } 43 44 public MPlayerInfo(String video, String dvdDrive, String mplayerPath) { 45 String[] command = null; 46 if (dvdDrive != null) 47 command = new String[]{mplayerPath + File.separator + MPLAYER_BIN, "-vo", "null", "-ao", "null", "-frames", "1", "-dvd-device", dvdDrive, video.toString(), "-v", "-identify"}; 48 else 49 command = new String[]{mplayerPath + File.separator + MPLAYER_BIN, "-vo", "null", "-ao", "null", "-frames", "1", video.toString(), "-identify"}; 37 public MPlayerInfo(InputVideo inputVideo) throws MPlayerNotFoundException { 38 this(inputVideo, MPlayerInfo.getMPlayerPath()); 39 } 40 41 public MPlayerInfo(InputVideo inputVideo, String mplayerPath) { 42 String[] command = inputVideo.appendToCommand(new String[]{mplayerPath + File.separator + MPLAYER_BIN, "-v", "-identify", "-vo", "null", "-ao", "null", "-frames", "1"}); 50 43 51 44 String commandStr = ""; … … 53 46 commandStr += command[i] + " "; 54 47 Logger.logMessage(commandStr, Logger.INFO); 48 49 mplayerOutput = new StringBuffer(); 55 50 56 51 try { … … 60 55 } 61 56 62 mplayerOutput = new StringBuffer(); 57 // We'll need to read the error stream too, otherwise mplayer may stall. 58 BlackHole.suck(proc.getErrorStream()); 63 59 64 60 try { … … 77 73 78 74 public String getVideoFormat() { 79 Matcher matcher = Pattern.compile("ID_VIDEO_FORMAT=.*").matcher(mplayerOutput); 80 matcher.find(); 81 String output = ""; 82 83 try { 84 output = matcher.group(); 85 } catch (Exception e) { 86 // empty 87 } 88 89 return output.substring(output.indexOf('=') + 1); 75 Matcher matcher = Pattern.compile("ID_VIDEO_FORMAT=(.*)").matcher(mplayerOutput); 76 77 if (matcher.find()) 78 return matcher.group(1); 79 80 return ""; 90 81 } 91 82 92 83 public int getLength() { 93 Matcher matcher = Pattern.compile("ID_LENGTH=[0-9]*").matcher(mplayerOutput); 94 matcher.find(); 95 String output = ""; 96 97 try { 98 output = matcher.group(); 99 } catch (Exception e) { 100 // empty 101 } 102 103 try { 104 return Integer.parseInt(output.substring(output.indexOf('=') + 1)); 105 } catch (Exception e) { 106 return 0; 107 } 84 Matcher matcher = Pattern.compile("ID_LENGTH=([0-9]*)").matcher(mplayerOutput); 85 86 if (matcher.find()) 87 return Integer.parseInt(matcher.group(1)); 88 89 return 0; 108 90 } 109 91 110 92 public int getNumberOfTitles() { 111 Matcher matcher = Pattern.compile("ID_DVD_TITLES=[0-9]*").matcher(mplayerOutput); 112 matcher.find(); 113 String output = matcher.group(); 114 115 return Integer.parseInt(output.substring(14)); 93 Matcher matcher = Pattern.compile("ID_DVD_TITLES=([0-9]*)").matcher(mplayerOutput); 94 95 if (matcher.find()) 96 return Integer.parseInt(matcher.group(1)); 97 98 return 0; 116 99 } 117 100 … … 127 110 public Map getAudioStreams() { 128 111 Map languages = new LinkedHashMap(); 129 130 112 languages.put("Default", "-1"); 131 132 Matcher matcher = Pattern.compile("audio stream: [0-9]* audio format: ac3.*").matcher(mplayerOutput); 133 while (matcher.find()) { 134 String stream = matcher.group(); 135 String lang = (Integer.parseInt(stream.substring(stream.indexOf("stream: ") + 8, stream.indexOf(" audio format:"))) + 1) + ". " + stream.substring(stream.indexOf("language: ") + 10, stream.indexOf(" aid:")); 136 languages.put(lang, stream.substring(stream.indexOf(" aid: ") + 6)); 137 } 138 113 114 /* 115 * = Pattern.compile("audio stream: [0-9]* audio format: 116 * ac3.*").matcher(mplayerOutput); while (matcher.find()) { String 117 * stream = matcher.group(); String lang = 118 * (Integer.parseInt(stream.substring(stream.indexOf("stream: ") + 8, 119 * stream.indexOf(" audio format:"))) + 1) + ". " + 120 * stream.substring(stream.indexOf("language: ") + 10, stream.indexOf(" 121 * aid:")); languages.put(lang, stream.substring(stream.indexOf(" aid: ") + 122 * 6)); } 123 */ 124 125 // Parse embedded audio streams (matroska) 126 /* 127 * if (languages.size() == 1) { matcher = Pattern.compile(" -aid 128 * ([0-9]{1,})[ ,-]* -alang ([a-z]{2,})").matcher(mplayerOutput); while 129 * (matcher.find()) { String aid = matcher.group(1); String lang = 130 * matcher.group(2); languages.put(lang, aid); } } 131 */ 132 133 // Parse embedded audio streams (tested with matroska, ogg vorbis) 134 if (languages.size() == 1) { 135 Matcher matcher = Pattern.compile("^ID_AUDIO_ID=([0-9]+)$", Pattern.MULTILINE).matcher(mplayerOutput); 136 137 List audioIds = new ArrayList(); 138 while (matcher.find()) 139 audioIds.add(matcher.group(1)); 140 141 if (audioIds.size() > 1) 142 for (int i = 0; i < audioIds.size(); i++) { 143 String aid = (String) audioIds.get(i); 144 145 // Find out audio stream language if available 146 // Default string in case there is no corresponding 147 // ID_AID_x_LANG (can happen) 148 String description = "Unknown"; 149 Matcher descMatcher = Pattern.compile("^ID_AID_" + aid + "_LANG=(.*)$", Pattern.MULTILINE).matcher(mplayerOutput); 150 if (descMatcher.find()) 151 description = descMatcher.group(1); 152 153 // Add format info if DVD (hack) 154 descMatcher = Pattern.compile("^audio stream: .* format: (.*) language: .* aid: " + aid + ".$", Pattern.MULTILINE).matcher(mplayerOutput); 155 if (descMatcher.find()) 156 description = description + " " + descMatcher.group(1); 157 description = aid + ": " + description; 158 // System.out.println(aid+":---"+lang); 159 160 languages.put(description, aid); 161 } 162 } 163 139 164 return languages; 140 165 } … … 142 167 public Map getSubtitleLanguages() { 143 168 Map languages = new LinkedHashMap(); 144 145 169 languages.put("None", "-1"); 146 170 147 Matcher matcher = Pattern.compile("[0-9]{1,} language: [a-z]{2}").matcher(mplayerOutput); 148 while (matcher.find()) { 149 String sub = matcher.group(); 150 String lang = (Integer.parseInt(sub.substring(0, sub.indexOf(' '))) + 1) + ". " + sub.substring(sub.indexOf(": ") + 2); 151 languages.put(lang, sub.substring(0, sub.indexOf(' '))); 152 } 153 171 /* 172 * Matcher matcher = Pattern.compile("[0-9]{1,} language: 173 * [a-z]{2}").matcher(mplayerOutput); while (matcher.find()) { String 174 * sub = matcher.group(); String lang = 175 * (Integer.parseInt(sub.substring(0, sub.indexOf(' '))) + 1) + ". " + 176 * sub.substring(sub.indexOf(": ") + 2); languages.put(lang, 177 * sub.substring(0, sub.indexOf(' '))); } 178 */ 179 180 /* 181 * // Parse embedded subtitles (matroska) if (languages.size() == 1) { 182 * matcher = Pattern.compile(" -sid ([0-9]{1,})[ ,-]* -slang 183 * ([a-z]{2,})").matcher(mplayerOutput); while (matcher.find()) { String 184 * sid = matcher.group(1); String lang = matcher.group(2); 185 * languages.put(lang, sid); } } 186 */ 187 188 // Parse embedded subtitles (tested with matroska, ogg vorbis) 189 if (languages.size() == 1) { 190 Matcher matcher = Pattern.compile("^ID_SUBTITLE_ID=([0-9]+)$", Pattern.MULTILINE).matcher(mplayerOutput); 191 while (matcher.find()) { 192 String sid = matcher.group(1); 193 String description = "Unknown"; 194 195 Matcher descMatcher = Pattern.compile("^ID_SID_" + sid + "_LANG=(.*)$", Pattern.MULTILINE).matcher(mplayerOutput); 196 if (descMatcher.find()) 197 description = descMatcher.group(1); 198 199 // Add name if found (I've seen Matroska use these) Here's an 200 // example: 201 // ID_SUBTITLE_ID=0 202 // ID_SID_0_NAME=Normal Subtitles 203 // ID_SID_0_LANG=eng 204 // [mkv] Track ID 4: subtitles (S_TEXT/SSA) "Normal Subtitles", 205 // -sid 0, -slang eng 206 // ID_SUBTITLE_ID=1 207 // ID_SID_1_NAME=Subtitles with Karaoke 208 // ID_SID_1_LANG=eng 209 // [mkv] Track ID 5: subtitles (S_TEXT/SSA) "Subtitles with 210 // Karaoke", -sid 1, -slang eng 211 212 descMatcher = Pattern.compile("^ID_SID_" + sid + "_NAME=(.*)$", Pattern.MULTILINE).matcher(mplayerOutput); 213 if (descMatcher.find()) 214 description = description + ": " + descMatcher.group(1); 215 216 // hack: Add matroska subtitle format info. 217 String t = "^\\[mkv\\] Track ID .*: subtitles \\((.*)\\).* -sid " + sid + ",.*$"; 218 System.out.println("muh: " + t); 219 descMatcher = Pattern.compile(t, Pattern.MULTILINE).matcher(mplayerOutput); 220 if (descMatcher.find()) 221 description = description + " (" + descMatcher.group(1) + ")"; 222 223 description = sid + ": " + description; 224 // System.out.println(sid+":---"+descr); 225 226 languages.put(description, sid); 227 } 228 } 229 154 230 return languages; 155 231 } 156 232 157 233 public double getFrameRate() { 158 double frameRate = 0; 159 Matcher matcher = Pattern.compile("[0-9.]* fps").matcher(mplayerOutput); 234 Matcher matcher = Pattern.compile("([0-9.]+) fps").matcher(mplayerOutput); 160 235 161 236 if (!matcher.find()) 162 237 return -1; 163 238 164 frameRate = Double.parseDouble(matcher.group().substring(0, 165 matcher.group().indexOf(' '))); 166 167 return frameRate; 239 return Double.parseDouble(matcher.group(1)); 168 240 } 169 241 170 242 public Dimensions getDimensions() { 171 Matcher matcher = Pattern.compile("=> [0-9]*x[0-9]*").matcher(mplayerOutput); 243 Matcher matcher = Pattern.compile("ID_VIDEO_WIDTH=(\\d+)").matcher(mplayerOutput); 244 245 if (matcher.find()) { 246 int width = Integer.parseInt(matcher.group(1)); 247 matcher = Pattern.compile("ID_VIDEO_HEIGHT=(\\d+)").matcher(mplayerOutput); 248 if (matcher.find()) { 249 int height = Integer.parseInt(matcher.group(1)); 250 matcher = Pattern.compile("Movie-Aspect is (\\d+(?:\\.\\d+)?):1 - prescaling to correct movie aspect.").matcher(mplayerOutput); 251 if (matcher.find()) { 252 double scale = Double.parseDouble(matcher.group(1)); 253 width = (int) Math.round(height * scale); 254 } 255 return new Dimensions(width, height); 256 } 257 } 258 259 matcher = Pattern.compile("=> [0-9]*x[0-9]*").matcher(mplayerOutput); 172 260 173 261 if (!matcher.find()) 174 262 return new Dimensions(-1, -1); 175 176 return new Dimensions(matcher.group().substring(matcher.group().indexOf(' ') + 1)); 263 264 matcher = Pattern.compile("=> ([0-9]*x[0-9]*)").matcher(mplayerOutput); 265 266 if (!matcher.find()) 267 return new Dimensions(-1, -1); 268 269 return new Dimensions(matcher.group(1)); 177 270 } 178 271 trunk/src/org/thestaticvoid/iriverter/MencoderCommand.java
r159 r161 23 23 24 24 import java.util.*; 25 import java.io.*;26 25 27 public class MencoderCommand implements ShitToDo { 28 private String description; 29 private String[] command; 30 private Process proc; 26 public class MencoderCommand extends ArrayList { 27 private InputVideo inputVideo; 28 private String outputVideo; 31 29 32 public MencoderCommand(String description, String[] command) { 33 this.description = description; 34 this.command = command; 30 public MencoderCommand(String[] command, InputVideo inputVideo, String outputVideo) { 31 this.inputVideo = inputVideo; 32 this.outputVideo = outputVideo; 33 34 for (int i = 0; i < command.length; i++) 35 add(command[i]); 36 37 inputVideo.appendToCommandList(this); 38 add("-o"); 39 add(outputVideo); 35 40 } 36 41 37 public void run(ProgressDialogInfo progressDialogInfo) throws FailedToDoSomeShit { 38 int exitCode = 1; 42 public MencoderCommand(InputVideo inputVideo, String outputVideo, String mplayerPath, MPlayerInfo info, int pass) { 43 this.inputVideo = inputVideo; 44 this.outputVideo = outputVideo; 39 45 40 MencoderStreamParser inputStream = null; 41 MencoderStreamParser errorStream = null; 46 add(mplayerPath + MPlayerInfo.MENCODER_BIN); 42 47 43 String commandStr = ""; 44 for (int i = 0; i < command.length; i++) 45 commandStr += command[i] + " "; 46 Logger.logMessage(description + " " + commandStr, Logger.INFO); 48 inputVideo.appendToCommandList(this); 49 add("-o"); 50 add(outputVideo); 47 51 48 progressDialogInfo.setSubdescription(description); 49 50 try { 51 proc = Runtime.getRuntime().exec(command); 52 53 inputStream = new MencoderStreamParser(progressDialogInfo); 54 inputStream.parse(new BufferedReader(new InputStreamReader(proc.getInputStream()))); 55 errorStream = new MencoderStreamParser(progressDialogInfo); 56 errorStream.parse(new BufferedReader(new InputStreamReader(proc.getErrorStream()))); 57 58 exitCode = proc.waitFor(); 59 } catch (Exception e) { 60 e.printStackTrace(); 52 if (ConverterOptions.getCurrentProfile().getWrapperFormat().equals("mp4")) { 53 add("-of"); 54 add("lavf"); 55 add("-lavfopts"); 56 add("format=mp4:i_certify_that_my_video_stream_does_not_use_b_frames"); 61 57 } 62 58 63 if (exitCode > 0) 64 throw new FailedToDoSomeShit(description); 65 } 66 67 public void cancel() { 68 proc.destroy(); 69 } 70 71 public static List prepareBaseCommandList(String inputVideo, String outputVideo, String mplayerPath, MPlayerInfo info, int pass) { 72 List commandList = new ArrayList(); 73 74 commandList.add(mplayerPath + MPlayerInfo.MENCODER_BIN); 75 76 commandList.add(inputVideo); 77 commandList.add("-o"); 78 commandList.add(outputVideo); 79 80 if (ConverterOptions.getCurrentProfile().getWrapperFormat().equals("mp4")) { 81 commandList.add("-of"); 82 commandList.add("lavf"); 83 commandList.add("-lavfopts"); 84 commandList.add("format=mp4:i_certify_that_my_video_stream_does_not_use_b_frames"); 59 add("-ovc"); 60 if (ConverterOptions.getCurrentProfile().getVideoFormat().equals("h264")) { 61 add("x264"); 62 add("-x264encopts"); 63 add("bitrate=" + ConverterOptions.getVideoBitrate() + ":bframes=0:level_idc=13:nocabac"); 64 } else { 65 add("xvid"); 66 add("-xvidencopts"); 67 add("bitrate=" + ConverterOptions.getVideoBitrate() + ":max_bframes=0"); 85 68 } 86 69 87 commandList.add("-ovc");88 if (ConverterOptions.getCurrentProfile().get VideoFormat().equals("h264")) {89 commandList.add("x264");90 commandList.add("-x264encopts");91 commandList.add("bitrate=" + ConverterOptions.getVideoBitrate() + ":bframes=0:level_idc=13:nocabac");70 add("-oac"); 71 if (ConverterOptions.getCurrentProfile().getAudioFormat().equals("aac")) { 72 add("faac"); 73 add("-faacopts"); 74 add("br=" + ConverterOptions.getAudioBitrate() + ":object=1"); 92 75 } else { 93 commandList.add("xvid"); 94 commandList.add("-xvidencopts"); 95 commandList.add("bitrate=" + ConverterOptions.getVideoBitrate() + ":max_bframes=0"); 96 } 97 98 commandList.add("-oac"); 99 if (ConverterOptions.getCurrentProfile().getAudioFormat().equals("aac")) { 100 commandList.add("faac"); 101 commandList.add("-faacopts"); 102 commandList.add("br=" + ConverterOptions.getAudioBitrate() + ":object=1"); 103 } else { 104 commandList.add("mp3lame"); 105 commandList.add("-lameopts"); 106 commandList.add("mode=0:cbr:br=" + ConverterOptions.getAudioBitrate()); 76 add("mp3lame"); 77 add("-lameopts"); 78 add("mode=0:cbr:br=" + ConverterOptions.getAudioBitrate()); 107 79 } 108 80 109 81 double ofps = (info.getFrameRate() > ConverterOptions.getCurrentProfile().getMaxFrameRate() ? ConverterOptions.getCurrentProfile().getMaxFrameRate() : info.getFrameRate()); 110 82 if (info.getFrameRate() != ofps && info.getFrameRate() < 1000) { // HACK: wmv always shows 1000 fps 111 commandList.add("-vf-add");112 commandList.add("filmdint=io=" + ((int) Math.round(info.getFrameRate() * 1000)) + ":" + ((int) Math.round(ofps * 1000)));83 add("-vf-add"); 84 add("filmdint=io=" + ((int) Math.round(info.getFrameRate() * 1000)) + ":" + ((int) Math.round(ofps * 1000))); 113 85 } 114 86 … … 121 93 } 122 94 123 commandList.add("-vf-add");95 add("-vf-add"); 124 96 if (ConverterOptions.getPanAndScan()) 125 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());97 add("scale=" + ((int) ((info.getDimensions().getWidth()) * (((double) ConverterOptions.getDimensions().getHeight()) / (double) info.getDimensions().getHeight()))) + ":" + ConverterOptions.getDimensions().getHeight() + ",crop=" + ConverterOptions.getDimensions().getWidth() + ":" + ConverterOptions.getDimensions().getHeight()); 126 98 else 127 commandList.add("scale=" + scaledWidth + ":" + scaledHeight + ",expand=" + ConverterOptions.getDimensions().getWidth() + ":" + ConverterOptions.getDimensions().getHeight());99 add("scale=" + scaledWidth + ":" + scaledHeight + ",expand=" + ConverterOptions.getDimensions().getWidth() + ":" + ConverterOptions.getDimensions().getHeight()); 128 100 129 commandList.add("-vf-add");130 commandList.add("harddup");101 add("-vf-add"); 102 add("harddup"); 131 103 132 104 if (ConverterOptions.getVolumeFilter().equals(VolumeFilter.VOLNORM)) { 133 commandList.add("-af");134 commandList.add("volnorm");105 add("-af"); 106 add("volnorm"); 135 107 } else if (ConverterOptions.getVolumeFilter().equals(VolumeFilter.VOLUME)) { 136 commandList.add("-af");137 commandList.add("volume=" + ConverterOptions.getGain());108 add("-af"); 109 add("volume=" + ConverterOptions.getGain()); 138 110 } 139 111 140 commandList.add("-ofps");141 commandList.add("" + ofps);142 commandList.add("-srate");143 commandList.add("44100");112 add("-ofps"); 113 add("" + ofps); 114 add("-srate"); 115 add("44100"); 144 116 145 117 if (!ConverterOptions.getAutoSync()) { 146 commandList.add("-delay");147 commandList.add("" + (ConverterOptions.getAudioDelay() / 1000.0));118 add("-delay"); 119 add("" + (ConverterOptions.getAudioDelay() / 1000.0)); 148 120 } 121 } 122 123 public String toString() { 124 String string = ""; 149 125 150 return commandList; 126 for (int i = 0; i < size(); i++) 127 string += (String) get(i); 128 129 return string; 130 } 131 132 public String[] toStringArray() { 133 return (String[]) toArray(new String[]{}); 134 } 135 136 public InputVideo getInputVideo() { 137 return inputVideo; 138 } 139 140 public String getOutputVideo() { 141 return outputVideo; 151 142 } 152 143 } trunk/src/org/thestaticvoid/iriverter/SingleVideo.java
r159 r161 34 34 public class SingleVideo extends Composite implements SelectionListener, TabItemControl, Job { 35 35 private CTabItem tabItem; 36 private StringinputVideo;36 private InputVideo inputVideo; 37 37 private MPlayerInfo inputVideoInfo; 38 38 private Text outputVideoInput; 39 private Button outputVideoSelect; 39 private Button outputVideoSelect, chapterSelection, previewButton; 40 private Combo titleCombo, audioStreamCombo, subtitlesCombo; 40 41 private String mplayerPath, outputVideoText; 41 42 public SingleVideo(Composite parent, int style, CTabItem tabItem, String inputVideo, String mplayerPath) throws Exception { 42 private boolean isDvd, hasMultipleAudio, hasMultipleSubtitles; 43 44 public SingleVideo(Composite parent, int style, CTabItem tabItem, InputVideo inputVideo, String mplayerPath) throws Exception { 43 45 super(parent, style); 44 46 this.tabItem = tabItem; … … 46 48 this.mplayerPath = mplayerPath; 47 49 48 inputVideoInfo = new MPlayerInfo(inputVideo .toString(), mplayerPath);50 inputVideoInfo = new MPlayerInfo(inputVideo, mplayerPath); 49 51 if (!inputVideoInfo.videoSupported()) { 50 52 MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_ERROR); 51 53 messageBox.setText("Unsupported Video"); 52 messageBox.setMessage("MPlayer does not recognize this type of video:\n" + new File(inputVideo ).getName());54 messageBox.setMessage("MPlayer does not recognize this type of video:\n" + new File(inputVideo.getName()).getName()); 53 55 messageBox.open(); 54 56 throw new Exception("Unsupported video"); 55 57 } 56 58 57 InputStream is = getClass().getResourceAsStream("icons/singlevideo-16.png"); 59 if (inputVideoInfo.getNumberOfTitles() > 0) { 60 isDvd = true; 61 hasMultipleAudio = true; 62 hasMultipleSubtitles = true; 63 } else { 64 isDvd = false; 65 hasMultipleAudio = false; 66 hasMultipleSubtitles = false; 67 68 if (inputVideoInfo.getAudioStreams().size() > 1) 69 hasMultipleAudio = true; 70 if (inputVideoInfo.getSubtitleLanguages().size() > 1) 71 hasMultipleSubtitles = true; 72 } 73 74 InputStream is = getClass().getResourceAsStream(isDvd ? "icons/dvd-16.png" : "icons/singlevideo-16.png"); 58 75 tabItem.setImage(new Image(getDisplay(), is)); 59 tabItem.setText(new File(inputVideo ).getName());76 tabItem.setText(new File(inputVideo.getName()).getName()); 60 77 61 78 GridLayout gridLayout = new GridLayout(); … … 69 86 70 87 Label singleVideoLabel = new Label(this, SWT.NONE); 71 singleVideoLabel.setText( "SingleVideo");88 singleVideoLabel.setText(isDvd ? "DVD" : "Video"); 72 89 FontData[] fontData = singleVideoLabel.getFont().getFontData(); 73 90 fontData[0].setStyle(SWT.BOLD); … … 82 99 83 100 outputVideoInput = new Text(this, SWT.BORDER); 84 outputVideoInput.setText(inputVideo. substring(0, inputVideo.lastIndexOf('.')) + "." + ConverterOptions.getCurrentProfile().getProfileName() + "." + ConverterOptions.getCurrentProfile().getWrapperFormat());101 outputVideoInput.setText(inputVideo.getName().substring(0, inputVideo.getName().lastIndexOf('.')) + "." + ConverterOptions.getCurrentProfile().getProfileName() + "." + ConverterOptions.getCurrentProfile().getWrapperFormat()); 85 102 outputVideoInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 86 103 … … 91 108 outputVideoSelect.setLayoutData(gridData); 92 109 outputVideoSelect.addSelectionListener(this); 110 111 Composite dvdComp = new Composite(this, SWT.NONE); 112 dvdComp.setVisible(isDvd || hasMultipleAudio || hasMultipleSubtitles); 113 gridLayout = new GridLayout(); 114 gridLayout.horizontalSpacing = 6; 115 gridLayout.verticalSpacing = 6; 116 gridLayout.marginHeight = 0; 117 gridLayout.marginWidth = 0; 118 dvdComp.setLayout(gridLayout); 119 gridData = new GridData(GridData.FILL_HORIZONTAL); 120 gridData.horizontalSpan = 3; 121 dvdComp.setLayoutData(gridData); 122 123 Composite groupsComp = new Composite(dvdComp, SWT.NONE); 124 gridLayout = new GridLayout(); 125 gridLayout.horizontalSpacing = 6; 126 gridLayout.verticalSpacing = 6; 127 gridLayout.marginHeight = 0; 128 gridLayout.marginWidth = 0; 129 gridLayout.numColumns = 2; 130 gridLayout.makeColumnsEqualWidth = true; 131 groupsComp.setLayout(gridLayout); 132 groupsComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 133 134 Group locations = new Group(groupsComp, SWT.NONE); 135 locations.setEnabled(isDvd); 136 locations.setText("Parts"); 137 gridLayout = new GridLayout(); 138 gridLayout.horizontalSpacing = 6; 139 gridLayout.verticalSpacing = 6; 140 locations.setLayout(gridLayout); 141 locations.setLayoutData(new GridData(GridData.FILL_BOTH)); 142 143 Composite titleComposite = new Composite(locations, SWT.NONE); 144 gridLayout = new GridLayout(); 145 gridLayout.horizontalSpacing = 6; 146 gridLayout.verticalSpacing = 6; 147 gridLayout.marginHeight = 0; 148 gridLayout.marginWidth = 0; 149 gridLayout.numColumns = 2; 150 titleComposite.setLayout(gridLayout); 151 gridData = new GridData(GridData.FILL_BOTH); 152 gridData.verticalAlignment = SWT.CENTER; 153 titleComposite.setLayoutData(gridData); 154 155 Label titleLabel = new Label(titleComposite, SWT.NONE); 156 titleLabel.setEnabled(isDvd); 157 titleLabel.setText("Title:"); 158 159 titleCombo = new Combo(titleComposite, SWT.DROP_DOWN | SWT.READ_ONLY); 160 titleCombo.setEnabled(isDvd); 161 titleCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 162 titleCombo.addSelectionListener(this); 163 164 chapterSelection = new Button(locations, SWT.PUSH); 165 chapterSelection.setEnabled(isDvd); 166 chapterSelection.setText("Chapters"); 167 chapterSelection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 168 chapterSelection.addSelectionListener(this); 169 170 Group languages = new Group(groupsComp, SWT.NONE); 171 languages.setEnabled(hasMultipleAudio || hasMultipleSubtitles); 172 languages.setText("Languages"); 173 gridLayout = new GridLayout(); 174 gridLayout.horizontalSpacing = 6; 175 gridLayout.verticalSpacing = 6; 176 gridLayout.numColumns = 2; 177 languages.setLayout(gridLayout); 178 languages.setLayoutData(new GridData(GridData.FILL_BOTH)); 179 180 Label audioStreamLabel = new Label(languages, SWT.NONE); 181 audioStreamLabel.setEnabled(hasMultipleAudio); 182 audioStreamLabel.setText("Audio:"); 183 184 audioStreamCombo = new Combo(languages, SWT.DROP_DOWN | SWT.READ_ONLY); 185 audioStreamCombo.setEnabled(hasMultipleAudio); 186 audioStreamCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 187 188 Label subtitlesLabel = new Label(languages, SWT.NONE); 189 subtitlesLabel.setEnabled(hasMultipleSubtitles); 190 subtitlesLabel.setText("Subtitles:"); 191 192 subtitlesCombo = new Combo(languages, SWT.DROP_DOWN | SWT.READ_ONLY); 193 subtitlesCombo.setEnabled(hasMultipleSubtitles); 194 subtitlesCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 195 196 previewButton = new Button(languages, SWT.PUSH); 197
