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/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                previewButton.setText("Preview"); 
     198                gridData = new GridData(GridData.FILL_HORIZONTAL); 
     199                gridData.horizontalSpan = 2; 
     200                previewButton.setLayoutData(gridData); 
     201                previewButton.addSelectionListener(this); 
     202                 
     203                Composite output = new Composite(dvdComp, SWT.NONE); 
     204                output.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));            
     205                gridLayout = new GridLayout(); 
     206                gridLayout.horizontalSpacing = 6; 
     207                gridLayout.verticalSpacing = 6; 
     208                gridLayout.marginHeight = 0; 
     209                gridLayout.marginWidth = 0; 
     210                gridLayout.numColumns = 3; 
     211                output.setLayout(gridLayout); 
    93212        } 
    94213         
    95214        public void widgetDefaultSelected(SelectionEvent e) { 
    96                 // empty 
     215                widgetSelected(e); 
    97216        } 
    98217         
     
    129248         
    130249        public String getDescription() {                 
    131                 return "Converting " + new File(inputVideo).getName(); 
     250                return "Converting " + new File(inputVideo.getName()).getName(); 
    132251        } 
    133252         
     
    135254                java.util.List shitToDo = new ArrayList(); 
    136255                 
    137                 java.util.List commandList = MencoderCommand.prepareBaseCommandList(inputVideo, getOutputVideo(), mplayerPath, inputVideoInfo, 0); 
    138                 String[] command = (String[]) commandList.toArray(new String[]{}); 
    139                 shitToDo.add(new MencoderCommand("Encoding...", command)); 
    140                  
    141                 int length = inputVideoInfo.getLength(); 
    142                 String inputVideo = getOutputVideo(); 
    143                 if (length > ConverterOptions.getSplitTime() * 60 && ConverterOptions.getAutoSplit()) { 
    144                         int pieces = (length / (ConverterOptions.getSplitTime() * 60)) + 1; 
    145                         for (int i = 0; i < pieces; i++) { 
    146                                 String outputVideo = inputVideo.substring(0, inputVideo.lastIndexOf('.')) + ".part" + (i + 1) + ".avi"; 
    147                                  
    148                                 if ((i + 1) == 1) 
    149                                         command = new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, inputVideo, "-o", outputVideo, "-ovc", "copy", "-oac", "copy", "-endpos", "" + (length / pieces)}; 
    150                                 else if ((i + 1) == pieces) 
    151                                         command = new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, inputVideo, "-o", outputVideo, "-ovc", "copy", "-oac", "copy", "-ss", "" + (length / pieces) * i}; 
    152                                 else 
    153                                         command = new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, inputVideo, "-o", outputVideo, "-ovc", "copy", "-oac", "copy", "-ss", "" + (length / pieces) * i, "-endpos", "" + (length / pieces)}; 
    154                                  
    155                                 shitToDo.add(new MencoderCommand("Splitting Part " + (i + 1) + " of " + pieces, command)); 
    156                         } 
    157                 } 
     256                MencoderCommand command = new MencoderCommand(inputVideo, getOutputVideo(), mplayerPath, inputVideoInfo, 0); 
     257                shitToDo.add(new MencoderShit("Encoding...", command)); 
    158258                 
    159259                return (ShitToDo[]) shitToDo.toArray(new ShitToDo[]{}); 
Note: See TracChangeset for help on using the changeset viewer.