- Timestamp:
- 04/14/07 15:52:46 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.
