public AdvancedVideoOptionsWindow(AdvancedVideoOptions avo)
        {
            try
            {
                InitializeComponent();
                this.avo = new AdvancedVideoOptions(avo);

                checkBoxManualFramerate.IsChecked = avo.disableFps;
                textBoxFramerate.Text = avo.fps;
                textBoxLength.Text = avo.length;
                textBoxFrameCount.Text = avo.frames;
                checkBoxManualFramerate_Checked(null, null);

                checkBoxManualInputResolution.IsChecked = avo.manualInputRes;
                textBoxInputResX.Text = avo.inputResX.ToString();
                textBoxInputResY.Text = avo.inputResY.ToString();
                checkBoxManualInputResolution_Checked(null, null);

                checkBoxManualAspectRatio.IsChecked = avo.manualAspectRatio;
                textBoxAspectRatio.Text = avo.aspectRatio;
                checkBoxManualAspectRatio_Checked(null, null);

                checkBoxDisableAutocrop.IsChecked = avo.disableAutocrop;
                checkBoxDisableAutocrop_Checked(null, null);

                checkBoxManualCrop.IsChecked = avo.manualCrop;
                textBoxCropBottom.Text = avo.cropBottom.ToString();
                textBoxCropLeft.Text = avo.cropLeft.ToString();
                textBoxCropRight.Text = avo.cropRight.ToString();
                textBoxCropTop.Text = avo.cropTop.ToString();
                checkBoxManualCrop_Checked(null, null);

                checkBoxManualBorders.IsChecked = avo.manualBorders;
                textBoxBorderBottom.Text = avo.borderBottom.ToString();
                textBoxBorderLeft.Text = avo.borderLeft.ToString();
                textBoxBorderRight.Text = avo.borderRight.ToString();
                textBoxBorderTop.Text = avo.borderTop.ToString();
                checkBoxManualBorders_Checked(null, null);

                checkBoxManualResize.IsChecked = avo.manualResize;
                textBoxResizeX.Text = avo.resizeX.ToString();
                textBoxResizeY.Text = avo.resizeY.ToString();

                comboBoxResizeMethod.Items.Clear();
                foreach (string s in GlobalVars.resizeMethods) comboBoxResizeMethod.Items.Add(s);
                if (avo.resizeMethod > -1 && avo.resizeMethod < GlobalVars.resizeMethods.Count) comboBoxResizeMethod.SelectedIndex = avo.resizeMethod;

                checkBoxManualResize_Checked(null, null);

                checkBoxNoMkvDemux.IsChecked = avo.noMkvDemux;
            }
            catch (Exception ex)
            {
                Global.ErrorMsg(ex);
            }
        }
 private void buttonEditAdvancedOptions_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (si.streamType == StreamType.Audio)
         {
             AdvancedAudioOptions aao = new AdvancedAudioOptions();
             if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions))
             {
                 aao = new AdvancedAudioOptions(si.advancedOptions);
             }
             AdvancedAudioOptionsWindow aaow = new AdvancedAudioOptionsWindow(aao);
             aaow.ShowDialog();
             if (aaow.DialogResult == true)
             {
                 si.advancedOptions = new AdvancedAudioOptions(aaow.advancedAudioOptions);
                 UpdateStatusInfo();
             }
         }
         else if (si.streamType == StreamType.Video)
         {
             AdvancedVideoOptions avo = new AdvancedVideoOptions();
             if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedVideoOptions))
             {
                 avo = new AdvancedVideoOptions(si.advancedOptions);
             }
             AdvancedVideoOptionsWindow avow = new AdvancedVideoOptionsWindow(avo);
             avow.ShowDialog();
             if (avow.DialogResult == true)
             {
                 si.advancedOptions = new AdvancedVideoOptions(avow.advancedVideoOptions);
                 UpdateStatusInfo();
             }
         }
         else if (si.streamType == StreamType.Subtitle)
         {
             AdvancedSubtitleOptions aso = new AdvancedSubtitleOptions();
             if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions))
             {
                 aso = new AdvancedSubtitleOptions(si.advancedOptions);
             }
             AdvancedSubtitleOptionsWindow avow = new AdvancedSubtitleOptionsWindow(aso);
             avow.ShowDialog();
             if (avow.DialogResult == true)
             {
                 si.advancedOptions = new AdvancedSubtitleOptions(avow.advancedSubtitleOptions);
                 UpdateStatusInfo();
             }
         }
     }
     catch (Exception)
     {
     }
 }
Beispiel #3
0
 private void menuEditAdvancedOptions_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (comboBoxTitle.SelectedIndex > -1 && listBoxStreams.SelectedIndex > -1)
         {
             StreamInfo si = titleList[comboBoxTitle.SelectedIndex].streams[listBoxStreams.SelectedIndex];
             if (si.streamType == StreamType.Audio)
             {
                 AdvancedAudioOptions aao = null;
                 if (si.advancedOptions.GetType() != typeof(AdvancedAudioOptions))
                 {
                     aao = new AdvancedAudioOptions();
                 }
                 else
                 {
                     aao = new AdvancedAudioOptions(si.advancedOptions);
                 }
                 AdvancedAudioOptionsWindow aaow = new AdvancedAudioOptionsWindow(aao);
                 aaow.ShowDialog();
                 if (aaow.DialogResult == true)
                 {
                     int index = listBoxStreams.SelectedIndex;
                     titleList[comboBoxTitle.SelectedIndex].streams[index].advancedOptions =
                         new AdvancedAudioOptions(aaow.advancedAudioOptions);
                     UpdateStreamList();
                     listBoxStreams.SelectedIndex = index;
                 }
             }
             else if (si.streamType == StreamType.Video)
             {
                 AdvancedVideoOptions avo = null;
                 if (si.advancedOptions.GetType() != typeof(AdvancedVideoOptions))
                 {
                     avo = new AdvancedVideoOptions();
                 }
                 else
                 {
                     avo = new AdvancedVideoOptions(si.advancedOptions);
                 }
                 AdvancedVideoOptionsWindow avow = new AdvancedVideoOptionsWindow(avo);
                 avow.ShowDialog();
                 if (avow.DialogResult == true)
                 {
                     int index = listBoxStreams.SelectedIndex;
                     titleList[comboBoxTitle.SelectedIndex].streams[index].advancedOptions =
                         new AdvancedVideoOptions(avow.advancedVideoOptions);
                     UpdateStreamList();
                     listBoxStreams.SelectedIndex = index;
                 }
             }
             else if (si.streamType == StreamType.Subtitle)
             {
                 AdvancedSubtitleOptions aso = null;
                 if (si.advancedOptions.GetType() != typeof(AdvancedSubtitleOptions))
                 {
                     aso = new AdvancedSubtitleOptions();
                 }
                 else
                 {
                     aso = new AdvancedSubtitleOptions(si.advancedOptions);
                 }
                 AdvancedSubtitleOptionsWindow asow = new AdvancedSubtitleOptionsWindow(aso);
                 asow.ShowDialog();
                 if (asow.DialogResult == true)
                 {
                     int index = listBoxStreams.SelectedIndex;
                     titleList[comboBoxTitle.SelectedIndex].streams[index].advancedOptions =
                         new AdvancedSubtitleOptions(asow.advancedSubtitleOptions);
                     UpdateStreamList();
                     listBoxStreams.SelectedIndex = index;
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }
Beispiel #4
0
        public MuxTool(UserSettings settings, TitleInfo titleInfo)
            : base()
        {
            try
            {
                this.settings = settings;
                this.titleInfo = titleInfo;
                this.Path = settings.mkvmergePath;
                this.Parameter += "--title \"" + settings.movieTitle + "\" -o \"" + settings.targetFolder + "\\" + settings.targetFilename + ".mkv\" ";
                int trackId = 0;
                // video + chapter
                foreach (StreamInfo si in titleInfo.streams)
                {
                    string lan = "";
                    if (settings.preferredAudioLanguages.Count > 0) lan = settings.preferredAudioLanguages[0].languageShort;

                    if (si.streamType == StreamType.Chapter)
                    {
                        if (lan != "") this.Parameter += "--chapter-language " + lan + " ";
                        this.Parameter += "--chapters \"" + si.filename + "\" ";
                    }
                    else if (si.streamType == StreamType.Video)
                    {
                        trackId++;
                        if (settings.disableVideoHeaderCompression)
                        {
                            this.Parameter += headerCompression;
                        }
                        if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedVideoOptions))
                        {
                            avo = new AdvancedVideoOptions(si.advancedOptions);
                        }
                        if (avo != null && avo.manualAspectRatio)
                        {
                            this.Parameter += "--aspect-ratio 0:" + avo.aspectRatio + " ";
                        }
                        if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo))
                        {
                            this.Parameter += "\"" + ((VideoFileInfo)si.extraFileInfo).encodedFile + "\" ";
                        }                        
                    }
                }
                // audio
                bool defaultSet = false;
                foreach (StreamInfo si in titleInfo.streams)
                {
                    if (si.streamType == StreamType.Audio)
                    {
                        trackId++;
                        string st = "";
                        st = getShortAudioLanguage(si.language);
                        if (st != "") this.Parameter += "--language 0" + ":" + st + " ";
                        
                        if (settings.disableAudioHeaderCompression)
                        {
                            this.Parameter += headerCompression;
                        }
                        if (!settings.defaultSubtitle)
                        {
                            this.Parameter += "--default-track 0:no ";
                        }

                        if (settings.preferredAudioLanguages.Count > 0 && settings.preferredAudioLanguages[0].language == si.language)
                        {
                            if (!defaultSet)
                            {
                                if (settings.defaultAudio)
                                {
                                    this.Parameter += "--default-track 0:yes ";
                                }
                                defaultSet = true;
                            }
                        }
                        this.Parameter += "\"" + si.filename + "\" ";

                        // add additional ac3 track
                        if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions))
                        {
                            AdvancedAudioOptions aao = (AdvancedAudioOptions)si.advancedOptions;
                            if (aao.additionalAc3Track && File.Exists(aao.additionalFilename))
                            {
                                trackId++;

                                if (st != "") this.Parameter += "--language 0" + ":" + st + " ";
                                if (settings.disableAudioHeaderCompression)
                                {
                                    this.Parameter += headerCompression;
                                }
                                this.Parameter += "\"" + aao.additionalFilename + "\" ";
                            }
                        }
                        if (settings.addAc3ToAllDts)
                        {
                            // check if already added by advanced audiooptions
                            bool ac3Added = false;
                            if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions) && ((AdvancedAudioOptions)si.advancedOptions).additionalAc3Track)
                            {
                                ac3Added = true;
                            }
                            if (!ac3Added)
                            {
                                if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions))
                                {
                                    AdvancedAudioOptions aao = (AdvancedAudioOptions)si.advancedOptions;
                                    if (File.Exists(aao.additionalFilename))
                                    {
                                        trackId++;

                                        if (st != "") this.Parameter += "--language 0" + ":" + st + " ";
                                        if (settings.disableAudioHeaderCompression)
                                        {
                                            this.Parameter += headerCompression;
                                        }
                                        this.Parameter += "\"" + aao.additionalFilename + "\" ";
                                    }
                                }
                            }
                        }
                    }
                }                

                List<int> subsCount = new List<int>();
                List<int> forcedSubsCount = new List<int>();
                for (int i = 0; i < settings.preferredSubtitleLanguages.Count; i++)
                {
                    subsCount.Add(0);
                    forcedSubsCount.Add(0);
                }

                // hardcode subs? do not mux subtitles even if selected
                bool suptitle = false;

                foreach (StreamInfo si in titleInfo.streams)
                {
                    if (si.streamType == StreamType.Subtitle)
                    {
                        if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions))
                        {
                            if (((AdvancedSubtitleOptions)si.advancedOptions).supTitle)
                            {
                                if (!suptitle)
                                {
                                    suptitle = true;                                    
                                }
                            }
                        }
                    }
                }

                if ((settings.muxSubs > 0 || settings.muxUntouchedSubs) && !suptitle)
                {
                    // subtitle
                    defaultSet = false;
                    foreach (StreamInfo si in titleInfo.streams)
                    {
                        if (si.streamType == StreamType.Subtitle)
                        {                            
                            SubtitleFileInfo sfi = (SubtitleFileInfo)si.extraFileInfo;

                            bool isForced = false;
                            if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions) && ((AdvancedSubtitleOptions)si.advancedOptions).isForced) isForced = true;

                            bool mux = false;
                            bool pgs = false;
                            bool untouched = false;

                            if (settings.muxUntouchedSubs)
                            {
                                if (!sfi.isSecond)
                                {
                                    mux = true;
                                    untouched = true;
                                }
                            }
                            else if (settings.muxSubs == 1)
                            {
                                mux = true;
                            }
                            else if (settings.muxSubs == 2)
                            {
                                if (sfi.forcedIdx != "") mux = true;
                            }
                            else if (settings.muxSubs == 3)
                            {
                                int lang = -1;
                                for (int i = 0; i < settings.preferredSubtitleLanguages.Count; i++)
                                {
                                    if (settings.preferredSubtitleLanguages[i].language == si.language) lang = i;
                                }
                                if (lang > -1)
                                {
                                    if (sfi.normalIdx != "")
                                    {
                                        if (subsCount[lang] == 0)
                                        {
                                            mux = true;
                                            subsCount[lang]++;
                                        }
                                    }
                                    else if (sfi.forcedIdx != "")
                                    {
                                        if (forcedSubsCount[lang] == 0)
                                        {
                                            mux = true;
                                            forcedSubsCount[lang]++;
                                        }
                                    }
                                }
                            }

                            else if (settings.muxSubs == 4)
                            {
                                mux = true;
                                pgs = true;
                            }
                            else if (settings.muxSubs == 5)
                            {
                                if (sfi.forcedSup != "")
                                {
                                    mux = true;
                                    pgs = true;
                                }
                            }
                            else if (settings.muxSubs == 6)
                            {
                                int lang = -1;
                                for (int i = 0; i < settings.preferredSubtitleLanguages.Count; i++)
                                {
                                    if (settings.preferredSubtitleLanguages[i].language == si.language) lang = i;
                                }
                                if (lang > -1)
                                {
                                    if (sfi.normalSup != "")
                                    {
                                        if (subsCount[lang] == 0)
                                        {
                                            mux = true;
                                            pgs = true;
                                            subsCount[lang]++;
                                        }
                                    }
                                    else if (sfi.forcedSup != "")
                                    {
                                        if (forcedSubsCount[lang] == 0)
                                        {
                                            mux = true;
                                            pgs = true;
                                            forcedSubsCount[lang]++;
                                        }
                                    }
                                }
                            }

                            if (mux)
                            {
                                trackId++;
                                string st = "";
                                st = getShortSubLanguage(si.language);
                                if (st != "") this.Parameter += "--language 0" + ":" + st + " ";
                                
                                if (settings.preferredSubtitleLanguages.Count > 0 && settings.preferredSubtitleLanguages[0].language == si.language)
                                {
                                    if (!defaultSet)
                                    {
                                        if (settings.defaultSubtitle)
                                        {
                                            if (!settings.defaultSubtitleForced)
                                            {
                                                this.Parameter += "--default-track 0:yes ";
                                                defaultSet = true;
                                            }
                                            else
                                            {
                                                if (hasForcedSub(si.language))
                                                {
                                                    if (!untouched && !pgs)
                                                    {
                                                        if (sfi.forcedIdx != "")
                                                        {
                                                            this.Parameter += "--default-track 0 ";
                                                            if (settings.defaultForcedFlag)
                                                            {
                                                                this.Parameter += "--forced-track 0 ";
                                                            }
                                                            defaultSet = true;
                                                        }
                                                    }
                                                    else if (!untouched && pgs)
                                                    {
                                                        if (sfi.forcedSup != "")
                                                        {
                                                            this.Parameter += "--default-track 0 ";
                                                            if (settings.defaultForcedFlag)
                                                            {
                                                                this.Parameter += "--forced-track 0 ";
                                                            }
                                                            defaultSet = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (!settings.defaultSubtitle)
                                {
                                    this.Parameter += "--default-track 0:no ";
                                }
                                if (untouched)
                                {
                                    if (si.filename != "")
                                    {
                                        this.Parameter += "\"" + si.filename + "\" ";
                                    }
                                }
                                else if (!settings.muxLowResSubs && !pgs)
                                {
                                    if (sfi.normalIdx != "" && !isForced)
                                    {
                                        this.Parameter += "\"" + sfi.normalIdx + "\" ";
                                    }
                                    else if (sfi.forcedIdx != "")
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.forcedIdx + "\" ";
                                    }
                                    else if (sfi.normalIdx != "" && isForced)
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.normalIdx + "\" ";
                                    }
                                }
                                else if (!settings.muxLowResSubs && pgs)
                                {
                                    if (sfi.normalSup != "" && !isForced)
                                    {
                                        this.Parameter += "\"" + sfi.normalSup + "\" ";
                                    }
                                    else if (sfi.forcedSup != "")
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.forcedSup + "\" ";
                                    }
                                    else if (sfi.normalSup != "")
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.normalSup + "\" ";
                                    }
                                }
                                else
                                {
                                    if (sfi.normalIdxLowRes != "" && !isForced)
                                    {
                                        this.Parameter += "\"" + sfi.normalIdxLowRes + "\" ";
                                    }
                                    else if (sfi.forcedIdxLowRes != "")
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.forcedIdxLowRes + "\" ";
                                    }
                                    else if (sfi.normalIdxLowRes != "" && isForced)
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.normalIdxLowRes + "\" ";
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Info("Exception: " + ex.Message); 
            }
        }
 private void buttonEditAdvancedOptions_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (si.streamType == StreamType.Audio)
         {
             AdvancedAudioOptions aao = new AdvancedAudioOptions();
             if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions)) aao = new AdvancedAudioOptions(si.advancedOptions);
             AdvancedAudioOptionsWindow aaow = new AdvancedAudioOptionsWindow(aao);                    
             aaow.ShowDialog();
             if (aaow.DialogResult == true)
             {
                 si.advancedOptions = new AdvancedAudioOptions(aaow.advancedAudioOptions);
                 UpdateStatusInfo();
             }
         }
         else if (si.streamType == StreamType.Video)
         {
             AdvancedVideoOptions avo = new AdvancedVideoOptions();                    
             if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedVideoOptions)) avo = new AdvancedVideoOptions(si.advancedOptions);
             AdvancedVideoOptionsWindow avow = new AdvancedVideoOptionsWindow(avo);
             avow.ShowDialog();
             if (avow.DialogResult == true)
             {
                 si.advancedOptions = new AdvancedVideoOptions(avow.advancedVideoOptions);
                 UpdateStatusInfo();
             }
         }
         else if (si.streamType == StreamType.Subtitle)
         {
             AdvancedSubtitleOptions aso = new AdvancedSubtitleOptions();
             if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions)) aso = new AdvancedSubtitleOptions(si.advancedOptions);
             AdvancedSubtitleOptionsWindow avow = new AdvancedSubtitleOptionsWindow(aso);
             avow.ShowDialog();
             if (avow.DialogResult == true)
             {
                 si.advancedOptions = new AdvancedSubtitleOptions(avow.advancedSubtitleOptions);
                 UpdateStatusInfo();
             }
         }
     }
     catch (Exception)
     {
     }
 }
Beispiel #6
0
        public MuxTool(UserSettings settings, TitleInfo titleInfo)
            : base()
        {
            try
            {
                this.settings   = settings;
                this.titleInfo  = titleInfo;
                this.Path       = settings.mkvmergePath;
                this.Parameter += "--title \"" + settings.movieTitle + "\" -o \"" + settings.targetFolder + "\\" + settings.targetFilename + ".mkv\" ";
                int trackId = 0;
                // video + chapter
                foreach (StreamInfo si in titleInfo.streams)
                {
                    string lan = "";
                    if (settings.preferredAudioLanguages.Count > 0)
                    {
                        lan = settings.preferredAudioLanguages[0].languageShort;
                    }

                    if (si.streamType == StreamType.Chapter)
                    {
                        if (lan != "")
                        {
                            this.Parameter += "--chapter-language " + lan + " ";
                        }
                        this.Parameter += "--chapters \"" + si.filename + "\" ";
                    }
                    else if (si.streamType == StreamType.Video)
                    {
                        trackId++;
                        if (settings.disableVideoHeaderCompression)
                        {
                            this.Parameter += headerCompression;
                        }
                        if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedVideoOptions))
                        {
                            avo = new AdvancedVideoOptions(si.advancedOptions);
                        }
                        if (avo != null && avo.manualAspectRatio)
                        {
                            this.Parameter += "--aspect-ratio 0:" + avo.aspectRatio + " ";
                        }
                        if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo))
                        {
                            this.Parameter += "\"" + ((VideoFileInfo)si.extraFileInfo).encodedFile + "\" ";
                        }
                    }
                }
                // audio
                bool defaultSet = false;
                foreach (StreamInfo si in titleInfo.streams)
                {
                    if (si.streamType == StreamType.Audio)
                    {
                        trackId++;
                        string st = "";
                        st = getShortAudioLanguage(si.language);
                        if (st != "")
                        {
                            this.Parameter += "--language 0" + ":" + st + " ";
                        }

                        if (settings.disableAudioHeaderCompression)
                        {
                            this.Parameter += headerCompression;
                        }
                        if (!settings.defaultSubtitle)
                        {
                            this.Parameter += "--default-track 0:no ";
                        }

                        if (settings.preferredAudioLanguages.Count > 0 && settings.preferredAudioLanguages[0].language == si.language)
                        {
                            if (!defaultSet)
                            {
                                if (settings.defaultAudio)
                                {
                                    this.Parameter += "--default-track 0:yes ";
                                }
                                defaultSet = true;
                            }
                        }
                        this.Parameter += "\"" + si.filename + "\" ";

                        // add additional ac3 track
                        if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions))
                        {
                            AdvancedAudioOptions aao = (AdvancedAudioOptions)si.advancedOptions;
                            if (aao.additionalAc3Track && File.Exists(aao.additionalFilename))
                            {
                                trackId++;

                                if (st != "")
                                {
                                    this.Parameter += "--language 0" + ":" + st + " ";
                                }
                                if (settings.disableAudioHeaderCompression)
                                {
                                    this.Parameter += headerCompression;
                                }
                                this.Parameter += "\"" + aao.additionalFilename + "\" ";
                            }
                        }
                        if (settings.addAc3ToAllDts)
                        {
                            // check if already added by advanced audiooptions
                            bool ac3Added = false;
                            if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions) && ((AdvancedAudioOptions)si.advancedOptions).additionalAc3Track)
                            {
                                ac3Added = true;
                            }
                            if (!ac3Added)
                            {
                                if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedAudioOptions))
                                {
                                    AdvancedAudioOptions aao = (AdvancedAudioOptions)si.advancedOptions;
                                    if (File.Exists(aao.additionalFilename))
                                    {
                                        trackId++;

                                        if (st != "")
                                        {
                                            this.Parameter += "--language 0" + ":" + st + " ";
                                        }
                                        if (settings.disableAudioHeaderCompression)
                                        {
                                            this.Parameter += headerCompression;
                                        }
                                        this.Parameter += "\"" + aao.additionalFilename + "\" ";
                                    }
                                }
                            }
                        }
                    }
                }

                List <int> subsCount       = new List <int>();
                List <int> forcedSubsCount = new List <int>();
                for (int i = 0; i < settings.preferredSubtitleLanguages.Count; i++)
                {
                    subsCount.Add(0);
                    forcedSubsCount.Add(0);
                }

                // hardcode subs? do not mux subtitles even if selected
                bool suptitle = false;

                foreach (StreamInfo si in titleInfo.streams)
                {
                    if (si.streamType == StreamType.Subtitle)
                    {
                        if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions))
                        {
                            if (((AdvancedSubtitleOptions)si.advancedOptions).supTitle)
                            {
                                if (!suptitle)
                                {
                                    suptitle = true;
                                }
                            }
                        }
                    }
                }

                if ((settings.muxSubs > 0 || settings.muxUntouchedSubs) && !suptitle)
                {
                    // subtitle
                    defaultSet = false;
                    foreach (StreamInfo si in titleInfo.streams)
                    {
                        if (si.streamType == StreamType.Subtitle)
                        {
                            SubtitleFileInfo sfi = (SubtitleFileInfo)si.extraFileInfo;

                            bool isForced = false;
                            if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions) && ((AdvancedSubtitleOptions)si.advancedOptions).isForced)
                            {
                                isForced = true;
                            }

                            bool mux       = false;
                            bool pgs       = false;
                            bool untouched = false;

                            if (settings.muxUntouchedSubs)
                            {
                                if (!sfi.isSecond)
                                {
                                    mux       = true;
                                    untouched = true;
                                }
                            }
                            else if (settings.muxSubs == 1)
                            {
                                mux = true;
                            }
                            else if (settings.muxSubs == 2)
                            {
                                if (sfi.forcedIdx != "")
                                {
                                    mux = true;
                                }
                            }
                            else if (settings.muxSubs == 3)
                            {
                                int lang = -1;
                                for (int i = 0; i < settings.preferredSubtitleLanguages.Count; i++)
                                {
                                    if (settings.preferredSubtitleLanguages[i].language == si.language)
                                    {
                                        lang = i;
                                    }
                                }
                                if (lang > -1)
                                {
                                    if (sfi.normalIdx != "")
                                    {
                                        if (subsCount[lang] == 0)
                                        {
                                            mux = true;
                                            subsCount[lang]++;
                                        }
                                    }
                                    else if (sfi.forcedIdx != "")
                                    {
                                        if (forcedSubsCount[lang] == 0)
                                        {
                                            mux = true;
                                            forcedSubsCount[lang]++;
                                        }
                                    }
                                }
                            }

                            else if (settings.muxSubs == 4)
                            {
                                mux = true;
                                pgs = true;
                            }
                            else if (settings.muxSubs == 5)
                            {
                                if (sfi.forcedSup != "")
                                {
                                    mux = true;
                                    pgs = true;
                                }
                            }
                            else if (settings.muxSubs == 6)
                            {
                                int lang = -1;
                                for (int i = 0; i < settings.preferredSubtitleLanguages.Count; i++)
                                {
                                    if (settings.preferredSubtitleLanguages[i].language == si.language)
                                    {
                                        lang = i;
                                    }
                                }
                                if (lang > -1)
                                {
                                    if (sfi.normalSup != "")
                                    {
                                        if (subsCount[lang] == 0)
                                        {
                                            mux = true;
                                            pgs = true;
                                            subsCount[lang]++;
                                        }
                                    }
                                    else if (sfi.forcedSup != "")
                                    {
                                        if (forcedSubsCount[lang] == 0)
                                        {
                                            mux = true;
                                            pgs = true;
                                            forcedSubsCount[lang]++;
                                        }
                                    }
                                }
                            }

                            if (mux)
                            {
                                trackId++;
                                string st = "";
                                st = getShortSubLanguage(si.language);
                                if (st != "")
                                {
                                    this.Parameter += "--language 0" + ":" + st + " ";
                                }

                                if (settings.preferredSubtitleLanguages.Count > 0 && settings.preferredSubtitleLanguages[0].language == si.language)
                                {
                                    if (!defaultSet)
                                    {
                                        if (settings.defaultSubtitle)
                                        {
                                            if (!settings.defaultSubtitleForced)
                                            {
                                                this.Parameter += "--default-track 0:yes ";
                                                defaultSet      = true;
                                            }
                                            else
                                            {
                                                if (hasForcedSub(si.language))
                                                {
                                                    if (!untouched && !pgs)
                                                    {
                                                        if (sfi.forcedIdx != "")
                                                        {
                                                            this.Parameter += "--default-track 0 ";
                                                            if (settings.defaultForcedFlag)
                                                            {
                                                                this.Parameter += "--forced-track 0 ";
                                                            }
                                                            defaultSet = true;
                                                        }
                                                    }
                                                    else if (!untouched && pgs)
                                                    {
                                                        if (sfi.forcedSup != "")
                                                        {
                                                            this.Parameter += "--default-track 0 ";
                                                            if (settings.defaultForcedFlag)
                                                            {
                                                                this.Parameter += "--forced-track 0 ";
                                                            }
                                                            defaultSet = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (!settings.defaultSubtitle)
                                {
                                    this.Parameter += "--default-track 0:no ";
                                }
                                if (untouched)
                                {
                                    if (si.filename != "")
                                    {
                                        this.Parameter += "\"" + si.filename + "\" ";
                                    }
                                }
                                else if (!settings.muxLowResSubs && !pgs)
                                {
                                    if (sfi.normalIdx != "" && !isForced)
                                    {
                                        this.Parameter += "\"" + sfi.normalIdx + "\" ";
                                    }
                                    else if (sfi.forcedIdx != "")
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.forcedIdx + "\" ";
                                    }
                                    else if (sfi.normalIdx != "" && isForced)
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.normalIdx + "\" ";
                                    }
                                }
                                else if (!settings.muxLowResSubs && pgs)
                                {
                                    if (sfi.normalSup != "" && !isForced)
                                    {
                                        this.Parameter += "\"" + sfi.normalSup + "\" ";
                                    }
                                    else if (sfi.forcedSup != "")
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.forcedSup + "\" ";
                                    }
                                    else if (sfi.normalSup != "")
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.normalSup + "\" ";
                                    }
                                }
                                else
                                {
                                    if (sfi.normalIdxLowRes != "" && !isForced)
                                    {
                                        this.Parameter += "\"" + sfi.normalIdxLowRes + "\" ";
                                    }
                                    else if (sfi.forcedIdxLowRes != "")
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.forcedIdxLowRes + "\" ";
                                    }
                                    else if (sfi.normalIdxLowRes != "" && isForced)
                                    {
                                        this.Parameter += " --track-name 0:Forced ";
                                        this.Parameter += "\"" + sfi.normalIdxLowRes + "\" ";
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Info("Exception: " + ex.Message);
            }
        }
Beispiel #7
0
        private bool IndexCrop()
        {
            try
            {
                DoPlugin(PluginType.BeforeAutoCrop);

                string filename          = "";
                AdvancedVideoOptions avo = null;
                foreach (StreamInfo si in demuxedStreamList.streams)
                {
                    if (si.streamType == StreamType.Video)
                    {
                        filename = si.filename;
                        if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedVideoOptions))
                        {
                            avo = (AdvancedVideoOptions)si.advancedOptions;
                        }
                        break;
                    }
                }

                string fps    = "";
                string resX   = "";
                string resY   = "";
                string length = "";
                string frames = "";

                try
                {
                    MediaInfoLib.MediaInfo mi2 = new MediaInfoLib.MediaInfo();
                    mi2.Open(filename);
                    mi2.Option("Complete", "1");
                    string[] tmpstr = mi2.Inform().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string s in tmpstr)
                    {
                        logWindow.MessageCrop(s.Trim());
                    }
                    if (mi2.Count_Get(StreamKind.Video) > 0)
                    {
                        fps    = mi2.Get(StreamKind.Video, 0, "FrameRate");
                        resX   = mi2.Get(StreamKind.Video, 0, "Width");
                        resY   = mi2.Get(StreamKind.Video, 0, "Height");
                        length = mi2.Get(StreamKind.Video, 0, "Duration");
                        frames = mi2.Get(StreamKind.Video, 0, "FrameCount");
                    }
                    mi2.Close();
                }
                catch (Exception ex)
                {
                    logWindow.MessageCrop(Global.Res("ErrorMediaInfo") + " " + ex.Message);
                    return(false);
                }

                if (avo != null && avo.disableFps)
                {
                    logWindow.MessageCrop(Global.Res("InfoManualFps"));
                    fps    = avo.fps;
                    length = avo.length;
                    frames = avo.frames;
                }

                if (fps == "")
                {
                    logWindow.MessageCrop(Global.Res("ErrorFramerate"));
                    foreach (StreamInfo si in demuxedStreamList.streams)
                    {
                        if (si.streamType == StreamType.Video)
                        {
                            if (si.desc.Contains("24 /1.001"))
                            {
                                logWindow.MessageCrop(Global.ResFormat("InfoFps", " 23.976"));
                                fps = "23.976";
                                break;
                            }
                            else if (si.desc.Contains("1080p24 (16:9)"))
                            {
                                logWindow.MessageCrop(Global.ResFormat("InfoFps", " 24"));
                                fps = "24";
                                break;
                            }
                            // add other framerates here
                        }
                    }
                    if (fps == "")
                    {
                        logWindow.MessageCrop(Global.Res("ErrorNoFramerate"));
                        return(false);
                    }
                }

                if (frames == "" || length == "")
                {
                    logWindow.MessageCrop(Global.Res("InfoFrames"));
                }

                CropInfo cropInfo = new CropInfo();
                if (!settings.untouchedVideo)
                {
                    if (settings.cropInput == 1 || settings.encodeInput == 1)
                    {
                        bool skip = false;
                        if (File.Exists(filename + ".ffindex") && !settings.deleteIndex)
                        {
                            skip = true;
                        }
                        if (!skip)
                        {
                            it            = new IndexTool(settings, filename, IndexType.ffmsindex);
                            it.OnInfoMsg += new ExternalTool.InfoEventHandler(IndexMsg);
                            it.OnLogMsg  += new ExternalTool.LogEventHandler(IndexMsg);
                            it.Start();
                            it.WaitForExit();
                            if (it == null || !it.Successfull)
                            {
                                logWindow.MessageCrop(Global.Res("ErrorIndex"));
                                return(false);
                            }
                        }
                    }

                    if (settings.cropInput == 2 || settings.encodeInput == 2)
                    {
                        string output = System.IO.Path.ChangeExtension(filename, "dgi");

                        bool skip = false;
                        if (File.Exists(output) && !settings.deleteIndex)
                        {
                            skip = true;
                        }
                        if (!skip)
                        {
                            it            = new IndexTool(settings, filename, IndexType.dgindex);
                            it.OnInfoMsg += new ExternalTool.InfoEventHandler(IndexMsg);
                            it.OnLogMsg  += new ExternalTool.LogEventHandler(IndexMsg);
                            it.Start();
                            it.WaitForExit();
                            if (!it.Successfull)
                            {
                                logWindow.MessageCrop(Global.Res("ErrorIndex"));
                                return(false);
                            }
                        }
                    }

                    if (avo == null || !avo.disableAutocrop)
                    {
                        if (settings.cropInput == 0)
                        {
                            File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs",
                                              "DirectShowSource(\"" + filename + "\")");
                        }
                        else if (settings.cropInput == 1)
                        {
                            string data   = "";
                            string dlldir = System.IO.Path.GetDirectoryName(settings.ffmsindexPath);
                            if (File.Exists(dlldir + "\\ffms2.dll"))
                            {
                                data = "LoadPlugin(\"" + dlldir + "\\ffms2.dll" + "\")\r\n";
                            }
                            data += "FFVideoSource(\"" + filename + "\")";
                            File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs", data);
                        }
                        else if (settings.cropInput == 2)
                        {
                            string output = System.IO.Path.ChangeExtension(filename, "dgi");
                            string data   = "";
                            string dlldir = System.IO.Path.GetDirectoryName(settings.dgindexnvPath);
                            if (File.Exists(dlldir + "\\DGDecodeNV.dll"))
                            {
                                data = "LoadPlugin(\"" + dlldir + "\\DGDecodeNV.dll" + "\")\r\n";
                            }
                            data += "DGSource(\"" + output + "\")";
                            File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs", data);
                        }
                        logWindow.MessageCrop(Global.Res("InfoStartCrop"));

                        AutoCrop ac = new AutoCrop(settings.workingDir + "\\" + settings.filePrefix + "_cropTemp.avs", settings, ref cropInfo);

                        if (cropInfo.error)
                        {
                            logWindow.MessageCrop(Global.Res("ErrorException") + " " + cropInfo.errorStr);
                            return(false);
                        }

                        if (settings.minimizeAutocrop && !settings.manualCrop)
                        {
                            ac.WindowState = FormWindowState.Minimized;
                        }

                        ac.NrFrames   = settings.nrFrames;
                        ac.BlackValue = settings.blackValue;
                        ac.ShowDialog();

                        if (cropInfo.error)
                        {
                            logWindow.MessageCrop(Global.Res("ErrorException") + " " + cropInfo.errorStr);
                            return(false);
                        }
                        cropInfo.resizeMethod = settings.resizeMethod;
                    }
                    else
                    {
                        cropInfo.border       = avo.manualBorders;
                        cropInfo.borderBottom = avo.borderBottom;
                        cropInfo.borderTop    = avo.borderTop;
                        cropInfo.resize       = avo.manualResize;
                        cropInfo.resizeX      = avo.resizeX;
                        cropInfo.resizeY      = avo.resizeY;
                        cropInfo.resizeMethod = avo.resizeMethod;
                        cropInfo.error        = false;
                        if (avo.manualCrop)
                        {
                            cropInfo.cropBottom = avo.cropBottom;
                            cropInfo.cropTop    = avo.cropTop;
                        }
                        else
                        {
                            cropInfo.cropBottom = 0;
                            cropInfo.cropTop    = 0;
                        }
                    }

                    logWindow.MessageCrop("");
                    logWindow.MessageCrop(Global.ResFormat("InfoCropTop", cropInfo.cropTop));
                    logWindow.MessageCrop(Global.ResFormat("InfoCropBottom", cropInfo.cropBottom));
                    if (cropInfo.border)
                    {
                        logWindow.MessageCrop(Global.ResFormat("InfoBorderTop", cropInfo.borderTop));
                        logWindow.MessageCrop(Global.ResFormat("InfoBorderBottom", cropInfo.borderBottom));
                    }
                    if (cropInfo.resize)
                    {
                        logWindow.MessageCrop(Global.ResFormat("InfoResize", cropInfo.resizeX, cropInfo.resizeY));
                    }
                }
                foreach (StreamInfo si in demuxedStreamList.streams)
                {
                    if (si.streamType == StreamType.Video)
                    {
                        if (si.extraFileInfo.GetType() != typeof(VideoFileInfo))
                        {
                            si.extraFileInfo = new VideoFileInfo();
                        }

                        ((VideoFileInfo)si.extraFileInfo).fps    = fps;
                        ((VideoFileInfo)si.extraFileInfo).length = length;
                        ((VideoFileInfo)si.extraFileInfo).frames = frames;

                        ((VideoFileInfo)si.extraFileInfo).cropInfo = new CropInfo(cropInfo);
                    }
                }

                DoPlugin(PluginType.AfterAutoCrop);

                TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");
                demuxedStreamsWindow.UpdateDemuxedStreams();
                return(true);
            }
            catch (Exception ex)
            {
                logWindow.MessageCrop(Global.Res("ErrorException") + " " + ex.Message);
                return(false);
            }
            finally
            {
            }
        }
Beispiel #8
0
        public AdvancedVideoOptionsWindow(AdvancedVideoOptions avo)
        {
            try
            {
                InitializeComponent();
                this.avo = new AdvancedVideoOptions(avo);

                checkBoxManualFramerate.IsChecked = avo.disableFps;
                textBoxFramerate.Text             = avo.fps;
                textBoxLength.Text     = avo.length;
                textBoxFrameCount.Text = avo.frames;
                checkBoxManualFramerate_Checked(null, null);

                checkBoxManualInputResolution.IsChecked = avo.manualInputRes;
                textBoxInputResX.Text = avo.inputResX.ToString();
                textBoxInputResY.Text = avo.inputResY.ToString();
                checkBoxManualInputResolution_Checked(null, null);

                checkBoxManualAspectRatio.IsChecked = avo.manualAspectRatio;
                textBoxAspectRatio.Text             = avo.aspectRatio;
                checkBoxManualAspectRatio_Checked(null, null);

                checkBoxDisableAutocrop.IsChecked = avo.disableAutocrop;
                checkBoxDisableAutocrop_Checked(null, null);

                checkBoxManualCrop.IsChecked = avo.manualCrop;
                textBoxCropBottom.Text       = avo.cropBottom.ToString();
                textBoxCropLeft.Text         = avo.cropLeft.ToString();
                textBoxCropRight.Text        = avo.cropRight.ToString();
                textBoxCropTop.Text          = avo.cropTop.ToString();
                checkBoxManualCrop_Checked(null, null);

                checkBoxManualBorders.IsChecked = avo.manualBorders;
                textBoxBorderBottom.Text        = avo.borderBottom.ToString();
                textBoxBorderLeft.Text          = avo.borderLeft.ToString();
                textBoxBorderRight.Text         = avo.borderRight.ToString();
                textBoxBorderTop.Text           = avo.borderTop.ToString();
                checkBoxManualBorders_Checked(null, null);

                checkBoxManualResize.IsChecked = avo.manualResize;
                textBoxResizeX.Text            = avo.resizeX.ToString();
                textBoxResizeY.Text            = avo.resizeY.ToString();

                comboBoxResizeMethod.Items.Clear();
                foreach (string s in GlobalVars.resizeMethods)
                {
                    comboBoxResizeMethod.Items.Add(s);
                }
                if (avo.resizeMethod > -1 && avo.resizeMethod < GlobalVars.resizeMethods.Count)
                {
                    comboBoxResizeMethod.SelectedIndex = avo.resizeMethod;
                }

                checkBoxManualResize_Checked(null, null);

                checkBoxNoMkvDemux.IsChecked = avo.noMkvDemux;
            }
            catch (Exception ex)
            {
                Global.ErrorMsg(ex);
            }
        }