Changeset 161

Show
Ignore:
Timestamp:
04/14/07 12:52:46 (2 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)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/org/thestaticvoid/iriverter/ConverterUI.java

    r158 r161  
    414414                                while (!canceled) 
    415415                                        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()); 
    417419                                                canceled = true; 
    418420                                        } catch (IOException io) { 
     
    438440                        newDirectory(); 
    439441                 
    440                 if (e.getSource() == newDVD || e.getSource() == newDVDTool) 
    441                         newDVD(); 
     442                /*if (e.getSource() == newDVD || e.getSource() == newDVDTool) 
     443                        newDVD();*/ 
    442444                 
    443445                if (e.getSource() == manualSplit) 
     
    684686                                while (!canceled) 
    685687                                        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());  
    687689                                                tabItem.setControl(singleVideo); 
    688690                                                tabFolder.setSelection(tabItem); 
     
    718720        } 
    719721         
    720         private DVD newDVD() { 
     722        /*private DVD newDVD() { 
    721723                DVD lastDVD = null; 
    722724                for (int i = tabFolder.getItemCount() - 1; i >= 0 && lastDVD == null; i--) 
     
    737739                 
    738740                return dvd; 
    739         } 
     741        }*/ 
    740742         
    741743        private ManualSplit newManualSplit() { 
  • trunk/src/org/thestaticvoid/iriverter/DVDInfoReader.java

    r157 r161  
    2626public class DVDInfoReader extends Thread { 
    2727        private DVDProgressDialog progressDialog; 
    28         private String drive, mplayerPath; 
     28        private InputVideo inputVideo; 
     29        private String mplayerPath; 
    2930        private Map titleInfo; 
    3031         
    31         public DVDInfoReader(DVDProgressDialog progressDialog, String drive, String mplayerPath) { 
     32        public DVDInfoReader(DVDProgressDialog progressDialog, InputVideo inputVideo, String mplayerPath) { 
    3233                this.progressDialog = progressDialog; 
    33                 this.drive = drive
     34                this.inputVideo = inputVideo
    3435                this.mplayerPath = mplayerPath; 
    3536                titleInfo = new LinkedHashMap(); 
     
    3940         
    4041        public void run() { 
    41                 int numberOfTitles = new MPlayerInfo("dvd://", drive, mplayerPath).getNumberOfTitles(); 
     42                int numberOfTitles = new MPlayerInfo(inputVideo, mplayerPath).getNumberOfTitles(); 
    4243                progressDialog.setMaximum(numberOfTitles); 
    4344                 
    4445                for (int i = 1; i <= numberOfTitles; i++) { 
    4546                        progressDialog.setCurrent(i); 
    46                         MPlayerInfo rawTitleInfo = new MPlayerInfo("dvd://" + i, drive, mplayerPath); 
     47                        MPlayerInfo rawTitleInfo = new MPlayerInfo(new InputVideo("dvd://" + i, inputVideo.getName()), mplayerPath); 
    4748                         
    4849                        int length = rawTitleInfo.getLength(); 
  • trunk/src/org/thestaticvoid/iriverter/MPlayerInfo.java

    r157 r161  
    22 * MPlayerInfo.java 
    33 * Copyright (C) 2005-2007 James Lee 
     4 * Copyright (C) 2007 David Grundberg 
    45 * 
    56 * This program is free software; you can redistribute it and/or 
     
    3435        private boolean commandFound = true; 
    3536         
    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"}); 
    5043                 
    5144                String commandStr = ""; 
     
    5346                        commandStr += command[i] + " "; 
    5447                Logger.logMessage(commandStr, Logger.INFO); 
     48 
     49                mplayerOutput = new StringBuffer(); 
    5550                 
    5651                try { 
     
    6055                } 
    6156                 
    62                 mplayerOutput = new StringBuffer(); 
     57                // We'll need to read the error stream too, otherwise mplayer may stall. 
     58                BlackHole.suck(proc.getErrorStream()); 
    6359                 
    6460                try { 
     
    7773         
    7874        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 ""; 
    9081        } 
    9182         
    9283        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; 
    10890        } 
    10991         
    11092        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; 
    11699        } 
    117100         
     
    127110        public Map getAudioStreams() { 
    128111                Map languages = new LinkedHashMap(); 
    129                  
    130112                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 
    139164                return languages; 
    140165        } 
     
    142167        public Map getSubtitleLanguages() { 
    143168                Map languages = new LinkedHashMap(); 
    144                  
    145169                languages.put("None", "-1"); 
    146170                 
    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 
    154230                return languages; 
    155231        } 
    156232 
    157233        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); 
    160235 
    161236                if (!matcher.find()) 
    162237                        return -1; 
    163238                 
    164                 frameRate = Double.parseDouble(matcher.group().substring(0, 
    165                                 matcher.group().indexOf(' '))); 
    166  
    167                 return frameRate; 
     239                return Double.parseDouble(matcher.group(1)); 
    168240        } 
    169241 
    170242        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); 
    172260 
    173261                if (!matcher.find()) 
    174262                        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)); 
    177270        } 
    178271         
  • 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} 
  • trunk/src/org/thestaticvoid/iriverter/SingleVideo.java

    r159 r161  
    3434public class SingleVideo extends Composite implements SelectionListener, TabItemControl, Job { 
    3535        private CTabItem tabItem; 
    36         private String inputVideo; 
     36        private InputVideo inputVideo; 
    3737        private MPlayerInfo inputVideoInfo; 
    3838        private Text outputVideoInput; 
    39         private Button outputVideoSelect; 
     39        private Button outputVideoSelect, chapterSelection, previewButton; 
     40        private Combo titleCombo, audioStreamCombo, subtitlesCombo; 
    4041        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 { 
    4345                super(parent, style); 
    4446                this.tabItem = tabItem; 
     
    4648                this.mplayerPath = mplayerPath; 
    4749                 
    48                 inputVideoInfo = new MPlayerInfo(inputVideo.toString(), mplayerPath); 
     50                inputVideoInfo = new MPlayerInfo(inputVideo, mplayerPath); 
    4951                if (!inputVideoInfo.videoSupported()) { 
    5052                        MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_ERROR); 
    5153                        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()); 
    5355                        messageBox.open(); 
    5456                        throw new Exception("Unsupported video"); 
    5557                } 
    5658                 
    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"); 
    5875                tabItem.setImage(new Image(getDisplay(), is)); 
    59                 tabItem.setText(new File(inputVideo).getName()); 
     76                tabItem.setText(new File(inputVideo.getName()).getName()); 
    6077                 
    6178                GridLayout gridLayout = new GridLayout(); 
     
    6986                 
    7087                Label singleVideoLabel = new Label(this, SWT.NONE); 
    71                 singleVideoLabel.setText("Single Video"); 
     88                singleVideoLabel.setText(isDvd ? "DVD" : "Video"); 
    7289                FontData[] fontData = singleVideoLabel.getFont().getFontData(); 
    7390                fontData[0].setStyle(SWT.BOLD); 
     
    8299                 
    83100                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()); 
    85102                outputVideoInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 
    86103                 
     
    91108                outputVideoSelect.setLayoutData(gridData); 
    92109                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