Ignore:
Timestamp:
04/14/07 15:52:46 (5 years ago)
Author:
jlee
Message:

Add code from David Grundberg's KuwaiiRiver?; preparation to combine DVD and SingleVideo? code; improvements to the shitty stuff (more modular conversion code)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/thestaticvoid/iriverter/MencoderCommand.java

    r159 r161  
    2323 
    2424import java.util.*; 
    25 import java.io.*; 
    2625 
    27 public class MencoderCommand implements ShitToDo { 
    28         private String description; 
    29         private String[] command; 
    30         private Process proc; 
     26public class MencoderCommand extends ArrayList { 
     27        private InputVideo inputVideo; 
     28        private String outputVideo; 
    3129         
    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); 
    3540        } 
    3641         
    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; 
    3945                 
    40                 MencoderStreamParser inputStream = null; 
    41                 MencoderStreamParser errorStream = null; 
     46                add(mplayerPath + MPlayerInfo.MENCODER_BIN); 
    4247                 
    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); 
    4751                 
    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"); 
    6157                } 
    6258                 
    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"); 
    8568                } 
    8669                 
    87                 commandList.add("-ovc"); 
    88                 if (ConverterOptions.getCurrentProfile().getVideoFormat().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"); 
    9275                } 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()); 
    10779                } 
    10880                 
    10981                double ofps = (info.getFrameRate() > ConverterOptions.getCurrentProfile().getMaxFrameRate() ? ConverterOptions.getCurrentProfile().getMaxFrameRate() : info.getFrameRate()); 
    11082                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))); 
    11385                } 
    11486                 
     
    12193                } 
    12294                 
    123                 commandList.add("-vf-add"); 
     95                add("-vf-add"); 
    12496                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()); 
    12698                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()); 
    128100                 
    129                 commandList.add("-vf-add"); 
    130                 commandList.add("harddup"); 
     101                add("-vf-add"); 
     102                add("harddup"); 
    131103                 
    132104                if (ConverterOptions.getVolumeFilter().equals(VolumeFilter.VOLNORM)) { 
    133                         commandList.add("-af"); 
    134                         commandList.add("volnorm"); 
     105                        add("-af"); 
     106                        add("volnorm"); 
    135107                } 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()); 
    138110                } 
    139111                 
    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"); 
    144116                 
    145117                if (!ConverterOptions.getAutoSync()) { 
    146                         commandList.add("-delay"); 
    147                         commandList.add("" + (ConverterOptions.getAudioDelay() / 1000.0)); 
     118                        add("-delay"); 
     119                        add("" + (ConverterOptions.getAudioDelay() / 1000.0)); 
    148120                } 
     121        } 
     122         
     123        public String toString() { 
     124                String string = ""; 
    149125                 
    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; 
    151142        } 
    152143} 
Note: See TracChangeset for help on using the changeset viewer.