Beispiel #1
0
        public static bool SaveStreamInfoFile(TitleInfo ti, string filename)
        {
            MemoryStream ms = null;
            FileStream fs = null;
            XmlSerializer xs = null;

            try
            {
                ms = new MemoryStream();
                fs = new FileStream(filename, FileMode.Create, FileAccess.Write);

                xs = new XmlSerializer(typeof(TitleInfo));
                xs.Serialize(ms, ti);
                ms.Seek(0, SeekOrigin.Begin);

                fs.Write(ms.ToArray(), 0, (int)ms.Length);
                ms.Close();
                fs.Close();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                if (ms != null) ms.Close();
                if (fs != null) fs.Close();
            }
        }
Beispiel #2
0
        private void buttonGetStreamInfo_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!Directory.Exists(settings.lastBluRayPath))
                {
                    logWindow.MessageDemux(Global.Res("ErrorBlurayPath"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorBlurayPath"));
                    }
                    return;
                }
                if (!checkEac3to())
                {
                    return;
                }
                DisableControls();
                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarStreamInfo"));

                comboBoxTitle.Items.Clear();
                listBoxStreams.ItemsSource = null;
                m2tsList.Clear();

                sit            = new StreamInfoTool(settings, ref titleList, settings.lastBluRayPath, GlobalVars.videoTypes, GlobalVars.ac3AudioTypes, GlobalVars.dtsAudioTypes);
                sit.OnInfoMsg += new ExternalTool.InfoEventHandler(DemuxMsg);
                sit.OnLogMsg  += new ExternalTool.LogEventHandler(DemuxMsg);
                sit.Start();
                sit.WaitForExit();
                if (sit == null || !sit.Successfull)
                {
                    titleList.Clear();
                }

                UpdateTitleList();

                demuxedStreamList = new TitleInfo();
                demuxedStreamsWindow.UpdateDemuxedStreams();
            }
            catch (Exception ex)
            {
                logWindow.MessageDemux(Global.Res("ErrorException") + " " + ex.Message);
            }
            finally
            {
                EnableControls();

                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarReady"));
            }
        }
Beispiel #3
0
 public TitleInfo(TitleInfo orig)
 {
     this.desc         = orig.desc;
     this.streamNumber = orig.streamNumber;
     this.streams.Clear();
     foreach (StreamInfo si in orig.streams)
     {
         this.streams.Add(new StreamInfo(si));
     }
     files.Clear();
     foreach (string s in orig.files)
     {
         this.files.Add(s);
     }
 }
Beispiel #4
0
 public TitleInfo(TitleInfo orig)
 {
     this.desc = orig.desc;
     this.streamNumber = orig.streamNumber;
     this.streams.Clear();
     foreach (StreamInfo si in orig.streams)
     {
         this.streams.Add(new StreamInfo(si));
     }
     files.Clear();
     foreach (string s in orig.files)
     {
         this.files.Add(s);
     }
 }
 private void buttonSave_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         SaveFileDialog sfd = new SaveFileDialog();
         sfd.Filter = "*_streamInfo.xml|*.xml";
         if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             TitleInfo.SaveStreamInfoFile(mainWindow.DemuxedStreams, sfd.FileName);
         }
     }
     catch (Exception)
     {
     }
 }
 private void buttonLoadDemuxedStreams_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         OpenFileDialog ofd = new OpenFileDialog();
         ofd.Filter = "*_streamInfo.xml|*.xml";
         if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             TitleInfo ti = new TitleInfo();
             TitleInfo.LoadSettingsFile(ref ti, ofd.FileName);
             mainWindow.DemuxedStreams = new TitleInfo(ti);
             UpdateDemuxedStreams();
         }
     }
     catch (Exception)
     {
     }
 }
Beispiel #7
0
 public Project(UserSettings settings, TitleInfo streamList, List<TitleInfo> titleList, int titleIndex, List<string> m2tsList)
 {
     try
     {
         this.settings = new UserSettings(settings);
         this.demuxedStreamList = new TitleInfo(streamList);
         this.titleList.Clear();
         foreach (TitleInfo ti in titleList)
         {
             this.titleList.Add(new TitleInfo(ti));
         }
         this.titleIndex = titleIndex;
         this.m2tsList.Clear();
         foreach (string s in m2tsList)
         {
             this.m2tsList.Add(s);
         }
     }
     catch (Exception)
     {
     }
 }
Beispiel #8
0
 public Project(UserSettings settings, TitleInfo streamList, List <TitleInfo> titleList, int titleIndex, List <string> m2tsList)
 {
     try
     {
         this.settings          = new UserSettings(settings);
         this.demuxedStreamList = new TitleInfo(streamList);
         this.titleList.Clear();
         foreach (TitleInfo ti in titleList)
         {
             this.titleList.Add(new TitleInfo(ti));
         }
         this.titleIndex = titleIndex;
         this.m2tsList.Clear();
         foreach (string s in m2tsList)
         {
             this.m2tsList.Add(s);
         }
     }
     catch (Exception)
     {
     }
 }
Beispiel #9
0
        private void DoM2tsInfo()
        {
            try
            {
                DisableControls();
                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarM2tsInfo"));

                comboBoxTitle.Items.Clear();
                listBoxStreams.ItemsSource = null;

                mit            = new M2tsInfoTool(settings, ref titleList, m2tsList, GlobalVars.videoTypes, GlobalVars.ac3AudioTypes, GlobalVars.dtsAudioTypes);
                mit.OnInfoMsg += new ExternalTool.InfoEventHandler(DemuxMsg);
                mit.OnLogMsg  += new ExternalTool.LogEventHandler(DemuxMsg);
                mit.Start();
                mit.WaitForExit();
                if (mit == null || !mit.Successfull)
                {
                    titleList.Clear();
                }

                UpdateTitleList();

                demuxedStreamList = new TitleInfo();
                demuxedStreamsWindow.UpdateDemuxedStreams();
            }
            catch (Exception ex)
            {
                logWindow.MessageDemux(Global.Res("ErrorException") + " " + ex.Message);
            }
            finally
            {
                EnableControls();

                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarReady"));
            }
        }
Beispiel #10
0
        public static bool SaveStreamInfoFile(TitleInfo ti, string filename)
        {
            MemoryStream  ms = null;
            FileStream    fs = null;
            XmlSerializer xs = null;

            try
            {
                ms = new MemoryStream();
                fs = new FileStream(filename, FileMode.Create, FileAccess.Write);

                xs = new XmlSerializer(typeof(TitleInfo));
                xs.Serialize(ms, ti);
                ms.Seek(0, SeekOrigin.Begin);

                fs.Write(ms.ToArray(), 0, (int)ms.Length);
                ms.Close();
                fs.Close();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                if (ms != null)
                {
                    ms.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Beispiel #11
0
        public DemuxTool(UserSettings settings, List<string> m2tsFiles, List<string> videoTypes, List<string> ac3AudioTypes, 
            List<string> dtsAudioTypes, TitleInfo streamList, ref TitleInfo demuxedStreamList, string ac3Bitrate, string dtsBitrate)
            : base()
        {
            try
            {
                this.settings = settings;
                this.m2tsFiles = m2tsFiles;
                this.videoTypes = videoTypes;
                this.ac3AudioTypes = ac3AudioTypes;
                this.dtsAudioTypes = dtsAudioTypes;
                this.streamList = streamList;
                demuxedStreamList = new TitleInfo();
                this.demuxedStreamList = demuxedStreamList;
                this.ac3Bitrate = ac3Bitrate;
                this.dtsBitrate = dtsBitrate;
                this.Path = settings.eac3toPath;

                Init();
            }
            catch (Exception)
            {
            }
        }
Beispiel #12
0
        public DemuxTool(UserSettings settings, List <string> m2tsFiles, List <string> videoTypes, List <string> ac3AudioTypes,
                         List <string> dtsAudioTypes, TitleInfo streamList, ref TitleInfo demuxedStreamList, string ac3Bitrate, string dtsBitrate)
            : base()
        {
            try
            {
                this.settings          = settings;
                this.m2tsFiles         = m2tsFiles;
                this.videoTypes        = videoTypes;
                this.ac3AudioTypes     = ac3AudioTypes;
                this.dtsAudioTypes     = dtsAudioTypes;
                this.streamList        = streamList;
                demuxedStreamList      = new TitleInfo();
                this.demuxedStreamList = demuxedStreamList;
                this.ac3Bitrate        = ac3Bitrate;
                this.dtsBitrate        = dtsBitrate;
                this.Path = settings.eac3toPath;

                Init();
            }
            catch (Exception)
            {
            }
        }
Beispiel #13
0
        private void DoM2tsInfo()
        {
            try
            {
                DisableControls();
                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarM2tsInfo"));
                                
                comboBoxTitle.Items.Clear();
                listBoxStreams.ItemsSource = null;

                mit = new M2tsInfoTool(settings, ref titleList, m2tsList, GlobalVars.videoTypes, GlobalVars.ac3AudioTypes, GlobalVars.dtsAudioTypes);
                mit.OnInfoMsg += new ExternalTool.InfoEventHandler(DemuxMsg);
                mit.OnLogMsg += new ExternalTool.LogEventHandler(DemuxMsg);
                mit.Start();
                mit.WaitForExit();
                if (mit == null || !mit.Successfull)
                {
                    titleList.Clear();
                }

                UpdateTitleList();

                demuxedStreamList = new TitleInfo();
                demuxedStreamsWindow.UpdateDemuxedStreams();
            }
            catch (Exception ex)
            {
                logWindow.MessageDemux(Global.Res("ErrorException") + " " + ex.Message);
            }
            finally
            {
                EnableControls();

                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarReady"));
            }
        }
Beispiel #14
0
        public static bool LoadSettingsFile(ref TitleInfo ti, string filename)
        {
            MemoryStream ms = null;

            try
            {
                if (!File.Exists(filename)) return false;
                byte[] data = File.ReadAllBytes(filename);
                XmlSerializer xs = new XmlSerializer(typeof(TitleInfo));
                ms = new MemoryStream(data);
                ms.Seek(0, SeekOrigin.Begin);

                ti = (TitleInfo)xs.Deserialize(ms);
                ms.Close();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                if (ms != null) ms.Close();
            }
        }
Beispiel #15
0
        private bool DoDemux()
        {
            try
            {
                DoPlugin(PluginType.BeforeDemux);

                if (!Directory.Exists(settings.workingDir))
                {
                    logWindow.MessageDemux(Global.Res("ErrorWorkingDirectory"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorWorkingDirectory"));
                    }
                    return(false);
                }
                if (comboBoxTitle.SelectedIndex == -1)
                {
                    logWindow.MessageDemux(Global.Res("ErrorNoTitle"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorNoTitle"));
                    }
                    return(false);
                }
                int videoCount = 0;
                int audioCount = 0;
                int unknown    = 0;
                foreach (StreamInfo si in titleList[comboBoxTitle.SelectedIndex].streams)
                {
                    if (si.streamType == StreamType.Audio && si.selected)
                    {
                        audioCount++;
                    }
                    if (si.streamType == StreamType.Video && si.selected)
                    {
                        videoCount++;
                    }
                    if (si.streamType == StreamType.Unknown && si.selected)
                    {
                        unknown++;
                    }
                }
                if (audioCount < 1)
                {
                    logWindow.MessageDemux(Global.Res("ErrorNoAudio"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorNoAudio"));
                    }
                    return(false);
                }
                if (videoCount != 1)
                {
                    logWindow.MessageDemux(Global.Res("ErrorNoVideo"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorNoVideo"));
                    }
                    return(false);
                }
                if (unknown > 0)
                {
                    logWindow.MessageDemux(Global.Res("ErrorUnknownTracks"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorUnknownTracks"));
                    }
                    return(false);
                }

                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarDemux"));
                DisableControls();

                string dtsBitrate = "1536";
                string ac3Bitrate = "640";
                if (settings.downmixDTSIndex >= 0 && settings.downmixDTSIndex < GlobalVars.dtsBitrates.Count)
                {
                    dtsBitrate = GlobalVars.dtsBitrates[settings.downmixDTSIndex];
                }
                if (settings.downmixAc3Index >= 0 && settings.downmixAc3Index < GlobalVars.ac3Bitrates.Count)
                {
                    ac3Bitrate = GlobalVars.ac3Bitrates[settings.downmixAc3Index];
                }

                dt = new DemuxTool(settings, m2tsList, GlobalVars.videoTypes, GlobalVars.ac3AudioTypes, GlobalVars.dtsAudioTypes,
                                   titleList[comboBoxTitle.SelectedIndex], ref demuxedStreamList, ac3Bitrate, dtsBitrate);

                dt.OnInfoMsg += new ExternalTool.InfoEventHandler(DemuxMsg);
                dt.OnLogMsg  += new ExternalTool.LogEventHandler(DemuxMsg);

                dt.Start();
                dt.WaitForExit();

                DoPlugin(PluginType.AfterDemux);

                TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");
                demuxedStreamsWindow.UpdateDemuxedStreams();

                if (dt == null)
                {
                    return(false);
                }
                else
                {
                    return(dt.Successfull);
                }
            }
            catch (Exception ex)
            {
                logWindow.MessageDemux(Global.Res("ErrorException") + " " + ex.Message);
                return(false);
            }
            finally
            {
                EnableControls();

                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarReady"));
            }
        }
Beispiel #16
0
        public void ProcessQueue()
        {
            try
            {
                silent = true;
                abort = false;

                foreach (Project project in projectQueue)
                {
                    logWindow.ClearAll();

                    logWindow.MessageMain(Global.ResFormat("InfoQueueStart", (projectQueue.IndexOf(project) + 1), projectQueue.Count));

                    if (!abort)
                    {
                        logWindow.MessageMain(Global.ResFormat("InfoQueueProjectStart", project.settings.movieTitle));
                        settings = new UserSettings(project.settings);
                        titleList.Clear();
                        foreach (TitleInfo ti in project.titleList)
                        {
                            titleList.Add(new TitleInfo(ti));
                        }
                        UpdateTitleList();
                        comboBoxTitle.SelectedIndex = project.titleIndex;
                        demuxedStreamList = new TitleInfo(project.demuxedStreamList);

                        m2tsList.Clear();
                        foreach (string s in project.m2tsList)
                        {
                            m2tsList.Add(s);
                        }

                        UpdateFromSettings(true);
                        demuxedStreamsWindow.UpdateDemuxedStreams();

                        StartAll();
                    }
                    else
                    {
                        logWindow.MessageMain(Global.Res("InfoQueueCancel"));
                    }
                    logWindow.MessageMain(Global.Res("InfoQueueDone"));

                    if (projectQueue.IndexOf(project) != projectQueue.Count - 1)
                    {
                        ShutdownWindow sw = new ShutdownWindow("CaptionShutdownWindowQueue", "LabelShutdownCounterQueue", 20);
                        sw.ShowDialog();
                        if (sw.DialogResult == false) break;
                    }
                }

                if (queueWindow.checkBoxQueueShutdown.IsChecked == true)
                {
                    ShutdownWindow sw = new ShutdownWindow();
                    sw.ShowDialog();
                    if (sw.DialogResult == true)
                    {
                        System.Diagnostics.Process.Start("ShutDown", "-s -f");
                    }
                }
            }
            catch (Exception ex)
            {
                logWindow.MessageMain(Global.Res("ErrorException") + " " + ex.Message);
            }
            finally
            {
                silent = false;
            }
        }
Beispiel #17
0
        private void DoPlugin(PluginType pluginType)
        {
            try
            {
                foreach (PluginBase plugin in pluginList)
                {
                    if (plugin.Settings.activated && plugin.getPluginType() == pluginType)
                    {
                        Project project = new Project(settings, demuxedStreamList, titleList, comboBoxTitle.SelectedIndex, m2tsList);
                        plugin.Init(project);
                        plugin.Process();

                        settings = new UserSettings(plugin.project.settings);
                        titleList.Clear();
                        foreach (TitleInfo ti in plugin.project.titleList)
                        {
                            titleList.Add(new TitleInfo(ti));
                        }
                        UpdateTitleList();
                        comboBoxTitle.SelectedIndex = plugin.project.titleIndex;
                        demuxedStreamList = new TitleInfo(plugin.project.demuxedStreamList);

                        m2tsList.Clear();
                        foreach (string s in plugin.project.m2tsList)
                        {
                            m2tsList.Add(s);
                        }

                        UpdateFromSettings(true);
                        demuxedStreamsWindow.UpdateDemuxedStreams();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #18
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 #19
0
        protected override void Process()
        {
            try
            {
                TitleInfo tmpList2 = new TitleInfo();
                tmpList2.desc = streamList.desc;

                foreach (StreamInfo si in streamList.streams)
                {
                    if (si.selected)
                    {
                        tmpList2.streams.Add(new StreamInfo(si));
                    }
                }
                //TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");


                // sort streamlist
                TitleInfo tmpList = new TitleInfo();
                tmpList.desc = tmpList2.desc;

                // chapter first
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Chapter)
                    {
                        tmpList.streams.Add(new StreamInfo(si));
                    }
                }
                // video
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Video)
                    {
                        if (settings.untouchedVideo)
                        {
                            if (si.extraFileInfo.GetType() != typeof(VideoFileInfo))
                            {
                                si.extraFileInfo = new VideoFileInfo();
                            }
                            ((VideoFileInfo)si.extraFileInfo).encodedFile = si.filename;
                        }
                        tmpList.streams.Add(new StreamInfo(si));
                    }
                }
                // audio
                foreach (LanguageInfo li in settings.preferredAudioLanguages)
                {
                    foreach (StreamInfo si in tmpList2.streams)
                    {
                        if (si.streamType == StreamType.Audio)
                        {
                            if (si.language == li.language)
                            {
                                tmpList.streams.Add(new StreamInfo(si));
                            }
                        }
                    }
                }
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Audio)
                    {
                        if (!HasLanguage(si.language))
                        {
                            tmpList.streams.Add(new StreamInfo(si));
                        }
                    }
                }
                // subtitle
                foreach (LanguageInfo li in settings.preferredAudioLanguages)
                {
                    foreach (StreamInfo si in tmpList2.streams)
                    {
                        if (si.streamType == StreamType.Subtitle)
                        {
                            if (si.language == li.language)
                            {
                                tmpList.streams.Add(new StreamInfo(si));
                            }
                        }
                    }
                }
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Subtitle)
                    {
                        if (!HasLanguage(si.language))
                        {
                            tmpList.streams.Add(new StreamInfo(si));
                        }
                    }
                }
                TitleInfo.SaveStreamInfoFile(tmpList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");

                foreach (StreamInfo si in tmpList.streams) demuxedStreamList.streams.Add(si);
                demuxedStreamList.desc = tmpList.desc;

                string res = Output;
                res = res.Replace("\b", "");
                res = res.Replace("\r", "");
                string[] tmp = res.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < tmp.Length; i++)
                {
                    tmp[i] = tmp[i].Trim();
                }
                for (int i = 0; i < tmp.Length; i++)
                {
                    if (tmp[i].IndexOf("Subtitle track") != -1)
                    {
                       if (tmp[i].IndexOf("forced captions") != -1)
                       {
                           try
                           {
                               int startPos = tmp[i].IndexOf("Subtitle track") + 14;
                               int endPos = tmp[i].IndexOf("contains", startPos);
                               int subtitleNumber = Convert.ToInt32(tmp[i].Substring(startPos, endPos - startPos).Trim());
                               foreach (StreamInfo si in demuxedStreamList.streams)
                               {
                                   if (si.number == subtitleNumber)
                                   {
                                       if (si.streamType == StreamType.Subtitle)
                                       {
                                           SubtitleFileInfo sfi = new SubtitleFileInfo();
                                           if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(SubtitleFileInfo)) sfi = new SubtitleFileInfo(si.extraFileInfo);
                                           sfi.containsForced = true;
                                           si.extraFileInfo = new SubtitleFileInfo(sfi);
                                       }
                                   }
                               }
                           } catch {}
                       }

                   } else if (tmp[i].IndexOf("Video track") != -1)
                    {
                        try
                        {
                            int startPos = tmp[i].IndexOf("Video track") + 11;
                            int endPos = tmp[i].IndexOf("contains", startPos);
                            int videoNumber = Convert.ToInt32(tmp[i].Substring(startPos, endPos - startPos).Trim());
                            startPos = tmp[i].IndexOf("contains") + 8;
                            endPos = tmp[i].IndexOf("frames", startPos);
                            string videoFrames = tmp[i].Substring(startPos, endPos - startPos).Trim();

                            foreach (StreamInfo si in demuxedStreamList.streams)
                            {
                                if (si.number == videoNumber)
                                {
                                    if (si.streamType == StreamType.Video)
                                    {
                                        VideoFileInfo sfi = new VideoFileInfo();
                                        if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo)) sfi = new VideoFileInfo(si.extraFileInfo);
                                        sfi.frames = videoFrames;
                                        si.extraFileInfo = new VideoFileInfo(sfi);
                                    }
                                }
                            }
                        }
                        catch { }
                    }
                }

                successfull = true;
            }
            catch (Exception)
            {
            }
        }
Beispiel #20
0
        protected override void Process()
        {
            try
            {
                TitleInfo tmpList2 = new TitleInfo();
                tmpList2.desc = streamList.desc;

                foreach (StreamInfo si in streamList.streams)
                {
                    if (si.selected)
                    {
                        tmpList2.streams.Add(new StreamInfo(si));
                    }
                }
                //TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");


                // sort streamlist
                TitleInfo tmpList = new TitleInfo();
                tmpList.desc = tmpList2.desc;

                // chapter first
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Chapter)
                    {
                        tmpList.streams.Add(new StreamInfo(si));
                    }
                }
                // video
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Video)
                    {
                        if (settings.untouchedVideo)
                        {
                            if (si.extraFileInfo.GetType() != typeof(VideoFileInfo))
                            {
                                si.extraFileInfo = new VideoFileInfo();
                            }
                            ((VideoFileInfo)si.extraFileInfo).encodedFile = si.filename;
                        }
                        tmpList.streams.Add(new StreamInfo(si));
                    }
                }
                // audio
                foreach (LanguageInfo li in settings.preferredAudioLanguages)
                {
                    foreach (StreamInfo si in tmpList2.streams)
                    {
                        if (si.streamType == StreamType.Audio)
                        {
                            if (si.language == li.language)
                            {
                                tmpList.streams.Add(new StreamInfo(si));
                            }
                        }
                    }
                }
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Audio)
                    {
                        if (!HasLanguage(si.language))
                        {
                            tmpList.streams.Add(new StreamInfo(si));
                        }
                    }
                }
                // subtitle
                foreach (LanguageInfo li in settings.preferredAudioLanguages)
                {
                    foreach (StreamInfo si in tmpList2.streams)
                    {
                        if (si.streamType == StreamType.Subtitle)
                        {
                            if (si.language == li.language)
                            {
                                tmpList.streams.Add(new StreamInfo(si));
                            }
                        }
                    }
                }
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Subtitle)
                    {
                        if (!HasLanguage(si.language))
                        {
                            tmpList.streams.Add(new StreamInfo(si));
                        }
                    }
                }
                TitleInfo.SaveStreamInfoFile(tmpList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");

                foreach (StreamInfo si in tmpList.streams)
                {
                    demuxedStreamList.streams.Add(si);
                }
                demuxedStreamList.desc = tmpList.desc;

                successfull = true;
            }
            catch (Exception)
            {
            }
        }
 private void buttonLoadDemuxedStreams_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         OpenFileDialog ofd = new OpenFileDialog();
         ofd.Filter = "*_streamInfo.xml|*.xml";
         if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             TitleInfo ti = new TitleInfo();
             TitleInfo.LoadSettingsFile(ref ti, ofd.FileName);
             mainWindow.DemuxedStreams = new TitleInfo(ti);
             UpdateDemuxedStreams();
         }
     }
     catch (Exception)
     {
     }
 }
Beispiel #22
0
        protected override void Process()
        {
            try
            {
                string res = Output;
                res = res.Replace("\b", "");
                res = res.Replace("\r", "");

                string[] tmp = res.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < tmp.Length; i++)
                {
                    tmp[i] = tmp[i].Trim();
                }

                if (res.Trim() == "")
                {
                    Info("Failed to get stream infos");
                    return;
                }

                TitleInfo ti = new TitleInfo();

                if (tmp[0][0] == '-')
                {
                    int length = 0;
                    for (int i = 0; i < tmp[0].Length; i++)
                    {
                        if (tmp[0][i] == '-')
                        {
                            length++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    tmp[0]  = tmp[0].Substring(length, tmp[0].Length - length);
                    tmp[0]  = tmp[0].Trim();
                    ti.desc = tmp[0];
                }

                for (int i = 0; i < tmp.Length; i++)
                {
                    if (Regex.IsMatch(tmp[i], "^[0-9.*].*:"))
                    {
                        StreamInfo sr = new StreamInfo();
                        sr.desc = tmp[i];
                        if (i < tmp.Length - 1)
                        {
                            if (!Regex.IsMatch(tmp[i + 1], "^[0-9.*].*:"))
                            {
                                if (!tmp[i + 1].StartsWith("v0"))
                                {
                                    sr.addInfo = tmp[i + 1];
                                }
                            }
                        }

                        int    pos    = tmp[i].IndexOf(':');
                        string substr = tmp[i].Substring(0, pos);
                        sr.number = Convert.ToInt32(substr);

                        substr = tmp[i].Substring(pos + 1).Trim();
                        string[] tmpInfo = substr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        if (tmpInfo.Length > 0)
                        {
                            sr.typeDesc = tmpInfo[0];
                            if (tmpInfo[0] == "Chapters")
                            {
                                sr.streamType = StreamType.Chapter;
                            }
                            else if (videoTypes.Contains(tmpInfo[0]))
                            {
                                sr.streamType = StreamType.Video;
                            }
                            else if (ac3AudioTypes.Contains(tmpInfo[0]))
                            {
                                sr.streamType = StreamType.Audio;
                                if (tmpInfo.Length > 1)
                                {
                                    sr.language = tmpInfo[1].Trim();
                                }
                            }
                            else if (dtsAudioTypes.Contains(tmpInfo[0]))
                            {
                                sr.streamType = StreamType.Audio;
                                if (tmpInfo.Length > 1)
                                {
                                    sr.language = tmpInfo[1].Trim();
                                }
                            }
                            else if (tmpInfo[0] == "Subtitle (PGS)")
                            {
                                sr.streamType = StreamType.Subtitle;
                                if (tmpInfo.Length > 1)
                                {
                                    sr.language = tmpInfo[1].Trim();
                                }
                            }
                            else
                            {
                                sr.streamType = StreamType.Unknown;
                            }
                        }
                        else
                        {
                            sr.typeDesc   = "Unknown";
                            sr.streamType = StreamType.Unknown;
                        }

                        ti.streams.Add(sr);
                    }
                }

                result.Add(ti);
                successfull = true;
            }
            catch (Exception)
            {
            }
        }
Beispiel #23
0
        private bool DoEncode()
        {
            try
            {
                if (!Directory.Exists(settings.workingDir))
                {
                    logWindow.MessageDemux(Global.Res("ErrorWorkingDirectory"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorWorkingDirectory"));
                    }
                    return(false);
                }
                if (settings.encodedMovieDir != "")
                {
                    if (!Directory.Exists(settings.encodedMovieDir))
                    {
                        logWindow.MessageDemux(Global.Res("ErrorEncodedMovieDirectory"));
                        if (!silent)
                        {
                            Global.ErrorMsg(Global.Res("ErrorEncodedMovieDirectory"));
                        }
                        return(false);
                    }
                }
                if (demuxedStreamList.streams.Count == 0)
                {
                    logWindow.MessageSubtitle(Global.Res("ErrorNoDemuxedStreams"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorNoDemuxedStreams"));
                    }
                    return(false);
                }

                VideoFileInfo vfi            = null;
                StreamInfo    vsi            = null;
                bool          suptitle       = false;
                bool          suptitleForced = false;
                StreamInfo    ssi            = null;

                foreach (StreamInfo si in demuxedStreamList.streams)
                {
                    if (si.streamType == StreamType.Video)
                    {
                        vsi = si;
                        if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(VideoFileInfo))
                        {
                            vfi = (VideoFileInfo)si.extraFileInfo;
                        }
                    }
                    else if (si.streamType == StreamType.Subtitle)
                    {
                        if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions))
                        {
                            if (((AdvancedSubtitleOptions)si.advancedOptions).supTitle)
                            {
                                // take first hardcode track
                                if (!suptitle)
                                {
                                    suptitle       = true;
                                    suptitleForced = ((AdvancedSubtitleOptions)si.advancedOptions).supTitleOnlyForced;
                                    ssi            = si;
                                }
                            }
                        }
                    }
                }

                if (vfi == null || vfi.cropInfo == null)
                {
                    logWindow.MessageEncode(Global.Res("ErrorCropInfoNotSet"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorCropInfoNotSet"));
                    }
                    return(false);
                }
                else
                {
                    vfi.encodeAvs = settings.workingDir + "\\" + settings.filePrefix + "_encode.avs";

                    string filename = vsi.filename;

                    CropInfo cropInfo = vfi.cropInfo;

                    logWindow.MessageEncode("");
                    logWindow.MessageEncode(Global.ResFormat("InfoCropTop", cropInfo.cropTop));
                    logWindow.MessageEncode(Global.ResFormat("InfoCropBottom", cropInfo.cropBottom));
                    if (cropInfo.border)
                    {
                        logWindow.MessageEncode(Global.ResFormat("InfoBorderTop", cropInfo.borderTop));
                        logWindow.MessageEncode(Global.ResFormat("InfoBorderBottom", cropInfo.borderBottom));
                    }
                    if (cropInfo.resize)
                    {
                        logWindow.MessageEncode(Global.ResFormat("InfoResize", cropInfo.resizeX, cropInfo.resizeY));
                    }

                    string encode = "";
                    if (suptitle)
                    {
                        if (File.Exists(settings.suptitlePath))
                        {
                            encode += "LoadPlugin(\"" + settings.suptitlePath + "\")\r\n";
                        }
                    }
                    if (settings.encodeInput == 0)
                    {
                        encode = "DirectShowSource(\"" + filename + "\")\r\n";
                    }
                    else if (settings.encodeInput == 1)
                    {
                        string dlldir = System.IO.Path.GetDirectoryName(settings.ffmsindexPath);
                        if (File.Exists(dlldir + "\\ffms2.dll"))
                        {
                            encode += "LoadPlugin(\"" + dlldir + "\\ffms2.dll" + "\")\r\n";
                        }
                        encode += "FFVideoSource(\"" + filename + "\")\r\n";
                    }
                    else if (settings.encodeInput == 2)
                    {
                        string output = System.IO.Path.ChangeExtension(filename, "dgi");
                        string dlldir = System.IO.Path.GetDirectoryName(settings.dgindexnvPath);
                        if (File.Exists(dlldir + "\\DGDecodeNV.dll"))
                        {
                            encode += "LoadPlugin(\"" + dlldir + "\\DGDecodeNV.dll" + "\")\r\n";
                        }
                        encode += "DGSource(\"" + output + "\")\r\n";
                    }
                    if (cropInfo.cropTop != 0 || cropInfo.cropBottom != 0)
                    {
                        encode += "Crop(0," + cropInfo.cropTop.ToString() + ",-0,-" + cropInfo.cropBottom.ToString() + ")\r\n";
                    }
                    if (cropInfo.border)
                    {
                        encode += "AddBorders(0," + cropInfo.borderTop + ",0," + cropInfo.borderBottom + ")\r\n";
                    }
                    else
                    {
                        logWindow.MessageEncode(Global.Res("InfoNoBorder"));
                    }
                    if (suptitle && ssi != null)
                    {
                        if (!suptitleForced)
                        {
                            if (File.Exists(ssi.filename))
                            {
                                string forced = "false";
                                encode += "SupTitle(\"" + ssi.filename + "\", forcedOnly=" +
                                          forced + ", swapCbCr=false, relocate=true, relocOffset=\"0," +
                                          cropInfo.cropTop.ToString() + ",0," + cropInfo.cropBottom.ToString() + "\")\r\n";
                            }
                        }
                        else
                        {
                            if (File.Exists(ssi.filename))
                            {
                                string forced = "true";
                                encode += "SupTitle(\"" + ssi.filename + "\", forcedOnly=" +
                                          forced + ", swapCbCr=false, relocate=true, relocOffset=\"0," +
                                          cropInfo.cropTop.ToString() + ",0," + cropInfo.cropBottom.ToString() + "\")\r\n";
                            }
                        }
                    }
                    if (cropInfo.resize)
                    {
                        if (cropInfo.resizeMethod > -1 && cropInfo.resizeMethod < GlobalVars.resizeMethods.Count)
                        {
                            encode += GlobalVars.resizeMethods[cropInfo.resizeMethod] + "(" + cropInfo.resizeX.ToString() + "," + cropInfo.resizeY.ToString() + ")\r\n";
                        }
                        else
                        {
                            encode += "LanczosResize(" + cropInfo.resizeX.ToString() + "," + cropInfo.resizeY.ToString() + ")\r\n";
                        }
                    }
                    else
                    {
                        logWindow.MessageEncode(Global.Res("InfoNoResize"));
                    }

                    int index = settings.lastAvisynthProfile;
                    if (index > -1 && index < settings.avisynthSettings.Count)
                    {
                        string[] tmp = settings.avisynthSettings[index].commands.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string s in tmp)
                        {
                            encode += s.Trim() + "\r\n";
                        }
                    }

                    File.WriteAllText(settings.workingDir + "\\" + settings.filePrefix + "_encode.avs", encode);

                    logWindow.MessageEncode("");
                    logWindow.MessageEncode(Global.Res("InfoAvsContent"));
                    logWindow.MessageEncode("");
                    string[] tmpstr2 = encode.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string s in tmpstr2)
                    {
                        logWindow.MessageEncode(s);
                    }
                }


                if (vfi == null || vfi.encodeAvs == "")
                {
                    logWindow.MessageEncode(Global.Res("ErrorEncodeAvsNotSet"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorEncodeAvsNotSet"));
                    }
                    //return false;
                }

                int profile = settings.lastProfile;
                if (profile < 0)
                {
                    logWindow.MessageEncode(Global.Res("ErrorEncodingProfileNotSet"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorEncodingProfileNotSet"));
                    }
                    return(false);
                }

                UpdateStatus(Global.Res("StatusBar") + " " + Global.ResFormat("StatusBarEncode", ""));
                DisableControls();

                lastMsg    = "";
                secondPass = false;

                if (settings.use64bit && GetMaxFrames() > 0)
                {
                    if (!settings.encodingSettings[profile].pass2)
                    {
                        maxProgressValue = GetMaxFrames();
                    }
                    else
                    {
                        maxProgressValue = 2 * GetMaxFrames();
                    }
                    progressBarMain.IsIndeterminate = false;
                    progressBarMain.Maximum         = 100;
                    progressBarMain.Minimum         = 0;
                }
                else if (!settings.use64bit)
                {
                    if (!settings.encodingSettings[profile].pass2)
                    {
                        maxProgressValue = 100;
                    }
                    else
                    {
                        maxProgressValue = 200;
                    }
                    progressBarMain.IsIndeterminate = false;
                    progressBarMain.Maximum         = 100;
                    progressBarMain.Minimum         = 0;
                }

                UpdateStatusBar(0);

                et            = new EncodeTool(settings, demuxedStreamList, profile, false, vfi);
                et.OnInfoMsg += new ExternalTool.InfoEventHandler(EncodeMsg);
                et.OnLogMsg  += new ExternalTool.LogEventHandler(EncodeMsg);
                et.Start();
                et.WaitForExit();

                if (et == null || !et.Successfull)
                {
                    vfi.encodedFile = "";
                    logWindow.MessageEncode(Global.Res("ErrorEncodeFailed"));
                    return(false);
                }
                if (settings.encodingSettings[profile].pass2)
                {
                    secondPass    = true;
                    et            = new EncodeTool(settings, demuxedStreamList, profile, true, vfi);
                    et.OnInfoMsg += new ExternalTool.InfoEventHandler(EncodeMsg);
                    et.OnLogMsg  += new ExternalTool.LogEventHandler(EncodeMsg);
                    et.Start();
                    et.WaitForExit();
                    if (et == null || !et.Successfull)
                    {
                        vfi.encodedFile = "";
                        logWindow.MessageEncode(Global.Res("ErrorEncode2passFailed"));
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                logWindow.MessageEncode(Global.Res("ErrorException") + " " + ex.Message);
                return(false);
            }
            finally
            {
                progressBarMain.IsIndeterminate = true;
                if (isWindows7)
                {
                    WPFExtensions.SetTaskbarProgressState(this, Windows7Taskbar.ThumbnailProgressState.NoProgress);
                }

                TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");
                EnableControls();

                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarReady"));
            }
        }
Beispiel #24
0
        private void buttonGetStreamInfo_Click(object sender, RoutedEventArgs e)
        {
            try
            {                
                if (!Directory.Exists(settings.lastBluRayPath))
                {
                    logWindow.MessageDemux(Global.Res("ErrorBlurayPath"));
                    if (!silent) Global.ErrorMsg(Global.Res("ErrorBlurayPath"));
                    return;
                }
                if (!checkEac3to()) return;
                DisableControls();
                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarStreamInfo"));
                
                comboBoxTitle.Items.Clear();
                listBoxStreams.ItemsSource = null;
                m2tsList.Clear();

                sit = new StreamInfoTool(settings, ref titleList, settings.lastBluRayPath, GlobalVars.videoTypes, GlobalVars.ac3AudioTypes, GlobalVars.dtsAudioTypes);
                sit.OnInfoMsg += new ExternalTool.InfoEventHandler(DemuxMsg);
                sit.OnLogMsg += new ExternalTool.LogEventHandler(DemuxMsg);
                sit.Start();
                sit.WaitForExit();
                if (sit == null || !sit.Successfull)
                {
                    titleList.Clear();
                }

                UpdateTitleList();

                demuxedStreamList = new TitleInfo();
                demuxedStreamsWindow.UpdateDemuxedStreams();
            }
            catch (Exception ex)
            {
                logWindow.MessageDemux(Global.Res("ErrorException") + " " + ex.Message);
            }
            finally
            {
                EnableControls();

                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarReady"));
            }
        }        
Beispiel #25
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 #26
0
        protected override void Process()
        {
            try
            {
                TitleInfo tmpList2 = new TitleInfo();
                tmpList2.desc = streamList.desc;

                foreach (StreamInfo si in streamList.streams)
                {
                    if (si.selected)
                    {
                        tmpList2.streams.Add(new StreamInfo(si));
                    }
                }
                //TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");


                // sort streamlist
                TitleInfo tmpList = new TitleInfo();
                tmpList.desc = tmpList2.desc;

                // chapter first
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Chapter)
                    {
                        tmpList.streams.Add(new StreamInfo(si));
                    }
                }
                // video
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Video)
                    {
                        if (settings.untouchedVideo)
                        {
                            if (si.extraFileInfo.GetType() != typeof(VideoFileInfo))
                            {
                                si.extraFileInfo = new VideoFileInfo();
                            }
                            ((VideoFileInfo)si.extraFileInfo).encodedFile = si.filename;
                        }
                        tmpList.streams.Add(new StreamInfo(si));
                    }
                }
                // audio
                foreach (LanguageInfo li in settings.preferredAudioLanguages)
                {
                    foreach (StreamInfo si in tmpList2.streams)
                    {
                        if (si.streamType == StreamType.Audio)
                        {
                            if (si.language == li.language)
                            {
                                tmpList.streams.Add(new StreamInfo(si));
                            }
                        }
                    }
                }
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Audio)
                    {
                        if (!HasLanguage(si.language))
                        {
                            tmpList.streams.Add(new StreamInfo(si));
                        }
                    }
                }
                // subtitle
                foreach (LanguageInfo li in settings.preferredAudioLanguages)
                {
                    foreach (StreamInfo si in tmpList2.streams)
                    {
                        if (si.streamType == StreamType.Subtitle)
                        {
                            if (si.language == li.language)
                            {
                                tmpList.streams.Add(new StreamInfo(si));
                            }
                        }
                    }
                }
                foreach (StreamInfo si in tmpList2.streams)
                {
                    if (si.streamType == StreamType.Subtitle)
                    {
                        if (!HasLanguage(si.language))
                        {
                            tmpList.streams.Add(new StreamInfo(si));
                        }
                    }
                }
                TitleInfo.SaveStreamInfoFile(tmpList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");

                foreach (StreamInfo si in tmpList.streams) demuxedStreamList.streams.Add(si);
                demuxedStreamList.desc = tmpList.desc;

                successfull = true;
            }
            catch (Exception)
            {
            }
        }
Beispiel #27
0
        private void menuItemFileOpen_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = Global.Res("ProjectFileFilter");
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Project project = new Project();
                    if (Project.LoadProjectFile(ref project, ofd.FileName))
                    {
                        settings = new UserSettings(project.settings);
                        titleList.Clear();
                        foreach (TitleInfo ti in project.titleList)
                        {
                            titleList.Add(new TitleInfo(ti));
                        }
                        UpdateTitleList();
                        comboBoxTitle.SelectedIndex = project.titleIndex;
                        demuxedStreamList = new TitleInfo(project.demuxedStreamList);

                        m2tsList.Clear();
                        foreach (string s in project.m2tsList)
                        {
                            m2tsList.Add(s);
                        }

                        UpdateFromSettings(true);
                        demuxedStreamsWindow.UpdateDemuxedStreams();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #28
0
        public EncodeTool(UserSettings settings, TitleInfo titleInfo, int profile, bool secondPass, VideoFileInfo vfi)
            : base()
        {
            try
            {
                this.settings   = settings;
                this.secondPass = secondPass;
                this.Priority   = settings.x264Priority;
                this.vfi        = vfi;
                this.titleInfo  = titleInfo;
                this.profile    = profile;

                bool is2pass = settings.encodingSettings[profile].pass2;

                if (settings.encodingSettings[profile].pass2)
                {
                    if (settings.encodingSettings[profile].sizeType == SizeType.Bitrate)
                    {
                        bitrate = (int)settings.encodingSettings[profile].sizeValue;
                    }
                    else if (settings.encodingSettings[profile].sizeType == SizeType.Size)
                    {
                        try
                        {
                            length = Convert.ToInt32(vfi.length);
                            length = (int)(length / 1000);
                        }
                        catch (Exception)
                        {
                        }

                        try
                        {
                            frames = Convert.ToInt32(vfi.frames);
                        }
                        catch (Exception)
                        {
                        }

                        // use frame count to calculate overhead
                        // to be done...

                        totalSize  = GetSize();
                        targetSize = Convert.ToInt64(settings.encodingSettings[profile].sizeValue * 1024.0 * 1024.0);
                        bitrate    = (int)((targetSize - totalSize) / 1024 / length); //kbyte/s
                        bitrate   *= 8;                                               //kbit/s

                        // no mkv overhead used yet
                    }
                }

                string outdir = settings.workingDir;
                if (settings.encodedMovieDir != "")
                {
                    outdir = settings.encodedMovieDir;
                }

                string statsFile = outdir + "\\" + settings.filePrefix + "_stats";

                if (!secondPass)
                {
                    if (!settings.encodingSettings[profile].pass2)
                    {
                        if (!settings.use64bit)
                        {
                            this.Path      = settings.x264Path;
                            this.Parameter = settings.encodingSettings[profile].GetParam + " \"" + vfi.encodeAvs + "\" -o \"" + outdir +
                                             "\\" + settings.filePrefix + "_video.mkv\"";
                        }
                        else
                        {
                            this.Path      = "cmd.exe";
                            this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                                             settings.x264x64Path + "\" " + settings.encodingSettings[profile].GetParam + " --fps " + vfi.fps + " " +
                                             " -o \"" + outdir + "\\" +
                                             settings.filePrefix + "_video.mkv\"" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                        }
                    }
                    else
                    {
                        if (!settings.use64bit)
                        {
                            this.Path      = settings.x264Path;
                            this.Parameter = string.Format(settings.encodingSettings[profile].GetParam, bitrate, statsFile) + " \"" + vfi.encodeAvs + "\" -o NUL";
                        }
                        else
                        {
                            this.Path      = "cmd.exe";
                            this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                                             settings.x264x64Path + "\" " + string.Format(settings.encodingSettings[profile].GetParam, bitrate, statsFile) + " --fps " + vfi.fps +
                                             " -o NUL" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                        }
                    }
                }
                else
                {
                    if (!settings.use64bit)
                    {
                        this.Path      = settings.x264Path;
                        this.Parameter = string.Format(settings.encodingSettings[profile].GetSecondParam, bitrate, statsFile) + " \"" + vfi.encodeAvs + "\" -o \"" + outdir +
                                         "\\" + settings.filePrefix + "_video.mkv\"";
                    }
                    else
                    {
                        this.Path      = "cmd.exe";
                        this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                                         settings.x264x64Path + "\" " + string.Format(settings.encodingSettings[profile].GetSecondParam, bitrate, statsFile) + " --fps " + vfi.fps + " -o \"" + outdir + "\\" +
                                         settings.filePrefix + "_video.mkv\"" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #29
0
        protected override void Process()
        {
            try
            {
                string res = Output;
                res = res.Replace("\b", "");
                res = res.Replace("\r", "");

                string[] tmp = res.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < tmp.Length; i++)
                {
                    tmp[i] = tmp[i].Trim();
                }

                if (res.Trim() == "")
                {
                    Info("Failed to get stream infos");
                    return;
                }

                TitleInfo ti = new TitleInfo();
                if (files != null)
                {
                    ti.files.Clear();
                    foreach (string s in files) ti.files.Add(s);
                }

                if (tmp[0][0] == '-')
                {
                    int length = 0;
                    for (int i = 0; i < tmp[0].Length; i++)
                    {
                        if (tmp[0][i] == '-')
                        {
                            length++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    tmp[0] = tmp[0].Substring(length, tmp[0].Length - length);
                    tmp[0] = tmp[0].Trim();
                    ti.desc = tmp[0];
                    ti.streamNumber = streamNumber;
                }

                for (int i = 0; i < tmp.Length; i++)
                {
                    if (Regex.IsMatch(tmp[i], "^[0-9.*].*:"))
                    {
                        StreamInfo sr = new StreamInfo();
                        sr.desc = tmp[i];
                        if (i < tmp.Length - 1)
                        {
                            if (!Regex.IsMatch(tmp[i + 1], "^[0-9.*].*:"))
                            {
                                sr.addInfo = tmp[i + 1];

                            }
                        }

                        int pos = tmp[i].IndexOf(':');
                        string substr = tmp[i].Substring(0, pos);
                        sr.number = Convert.ToInt32(substr);

                        substr = tmp[i].Substring(pos + 1).Trim();
                        string[] tmpInfo = substr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        if (tmpInfo.Length > 0)
                        {
                            sr.typeDesc = tmpInfo[0];
                            if (tmpInfo[0] == "Chapters")
                            {
                                sr.streamType = StreamType.Chapter;
                            }
                            else if (videoTypes.Contains(tmpInfo[0]))
                            {
                                sr.streamType = StreamType.Video;
                            }
                            else if (ac3AudioTypes.Contains(tmpInfo[0]))
                            {
                                sr.streamType = StreamType.Audio;
                                if (tmpInfo.Length > 1)
                                {
                                    sr.language = tmpInfo[1].Trim();
                                }
                                else
                                {
                                    sr.language = "undef";
                                }
                            }
                            else if (dtsAudioTypes.Contains(tmpInfo[0]))
                            {
                                sr.streamType = StreamType.Audio;
                                if (tmpInfo.Length > 1)
                                {
                                    sr.language = tmpInfo[1].Trim();
                                }
                                else
                                {
                                    sr.language = "undef";
                                }
                            }
                            else if (tmpInfo[0] == "Subtitle (PGS)")
                            {
                                sr.streamType = StreamType.Subtitle;
                                if (tmpInfo.Length > 1)
                                {
                                    sr.language = tmpInfo[1].Trim();
                                }
                                else
                                {
                                    sr.language = "undef";
                                }
                            }
                            else
                            {
                                sr.streamType = StreamType.Unknown;
                            }
                        }
                        else
                        {
                            sr.typeDesc = "Unknown";
                            sr.streamType = StreamType.Unknown;
                        }

                        ti.streams.Add(sr);
                    }
                }

                result.Add(ti);
                successfull = true;
            }
            catch (Exception)
            {
            }
        }
Beispiel #30
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 #31
0
        private bool DoSubtitle()
        {
            try
            {
                DoPlugin(PluginType.BeforeSubtitle);

                if (!Directory.Exists(settings.workingDir))
                {
                    logWindow.MessageDemux(Global.Res("ErrorWorkingDirectory"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorWorkingDirectory"));
                    }
                    return(false);
                }

                if (demuxedStreamList.streams.Count == 0)
                {
                    logWindow.MessageSubtitle(Global.Res("ErrorNoDemuxedStreams"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorNoDemuxedStreams"));
                    }
                    return(false);
                }

                string fps = "";
                foreach (StreamInfo si in demuxedStreamList.streams)
                {
                    if (si.streamType == StreamType.Video)
                    {
                        if (si.extraFileInfo.GetType() == typeof(VideoFileInfo))
                        {
                            fps = ((VideoFileInfo)si.extraFileInfo).fps;
                            break;
                        }
                    }
                }
                if (fps == "")
                {
                    logWindow.MessageSubtitle(Global.Res("ErrorSetFramerate"));
                    if (!silent)
                    {
                        Global.ErrorMsg(Global.Res("ErrorSetFramerate"));
                    }
                    return(false);
                }

                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarSubtitle"));

                int subtitleCount = 0;
                foreach (StreamInfo si in demuxedStreamList.streams)
                {
                    if (si.streamType == StreamType.Subtitle)
                    {
                        subtitleCount++;
                        if (si.extraFileInfo == null || si.extraFileInfo.GetType() != typeof(SubtitleFileInfo))
                        {
                            si.extraFileInfo = new SubtitleFileInfo();
                        }
                    }
                }

                if (subtitleCount == 0)
                {
                    logWindow.MessageSubtitle(Global.Res("InfoNoSubtitles"));
                    return(true);
                }

                bool suptitle = false;

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

                int muxSubs = settings.muxSubs;
                if (suptitle)
                {
                    muxSubs = 0;
                }

                // do not mux and copy subs
                if (muxSubs == 0 && settings.copySubs == 0)
                {
                    logWindow.MessageSubtitle(Global.Res("InfoNoSubtitlesProcessing"));
                    return(true);
                }
                // only untouched subs
                else if (settings.muxUntouchedSubs && settings.copyUntouchedSubs)
                {
                    logWindow.MessageSubtitle(Global.Res("InfoNoSubtitlesProcessing"));
                    return(true);
                }
                else if (settings.muxUntouchedSubs && settings.copySubs == 0)
                {
                    logWindow.MessageSubtitle(Global.Res("InfoNoSubtitlesProcessing"));
                    return(true);
                }
                else if (muxSubs == 0 && settings.copyUntouchedSubs)
                {
                    logWindow.MessageSubtitle(Global.Res("InfoNoSubtitlesProcessing"));
                    return(true);
                }

                DisableControls();

                bool sub = false;
                bool sup = false;

                if (settings.muxSubs > 0 && settings.muxSubs < 4)
                {
                    sub = true;
                }
                else if (settings.muxSubs >= 4)
                {
                    sup = true;
                }

                if (settings.copySubs > 0 && settings.copySubs < 4)
                {
                    sub = true;
                }
                else if (settings.copySubs >= 4)
                {
                    sup = true;
                }

                bool error    = false;
                int  subtitle = 0;
                for (int i = 0; i < demuxedStreamList.streams.Count; i++)
                {
                    if (demuxedStreamList.streams[i].streamType == StreamType.Subtitle)
                    {
                        if (demuxedStreamList.streams[i].extraFileInfo != null && demuxedStreamList.streams[i].extraFileInfo.GetType() == typeof(SubtitleFileInfo) &&
                            ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).isSecond)
                        {
                            continue;
                        }

                        subtitle++;
                        StreamInfo si = demuxedStreamList.streams[i];
                        if (sub)
                        {
                            UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleNormal"), subtitle, subtitleCount));
                            st            = new SubtitleTool(settings, fps, ref si, false, false, false);
                            st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg);
                            st.OnLogMsg  += new ExternalTool.LogEventHandler(SubtitleMsg);
                            st.Start();
                            st.WaitForExit();
                            if (st == null || !st.Successfull)
                            {
                                error = true;
                            }

                            UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleForced"), subtitle, subtitleCount));
                            st            = new SubtitleTool(settings, fps, ref si, true, false, false);
                            st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg);
                            st.OnLogMsg  += new ExternalTool.LogEventHandler(SubtitleMsg);
                            st.Start();
                            st.WaitForExit();
                            if (st == null || !st.Successfull)
                            {
                                error = true;
                            }
                        }
                        if (sup)
                        {
                            UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleNormalPgs"), subtitle, subtitleCount));
                            st            = new SubtitleTool(settings, fps, ref si, false, false, true);
                            st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg);
                            st.OnLogMsg  += new ExternalTool.LogEventHandler(SubtitleMsg);
                            st.Start();
                            st.WaitForExit();
                            if (st == null || !st.Successfull)
                            {
                                error = true;
                            }

                            UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleForcedPgs"), subtitle, subtitleCount));
                            st            = new SubtitleTool(settings, fps, ref si, true, false, true);
                            st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg);
                            st.OnLogMsg  += new ExternalTool.LogEventHandler(SubtitleMsg);
                            st.Start();
                            st.WaitForExit();
                            if (st == null || !st.Successfull)
                            {
                                error = true;
                            }
                        }

                        if (settings.muxLowResSubs && (settings.muxSubs > 0 && settings.muxSubs < 4))
                        {
                            UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleLowresNormal"), subtitle, subtitleCount));
                            si            = demuxedStreamList.streams[i];
                            st            = new SubtitleTool(settings, fps, ref si, false, true, false);
                            st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg);
                            st.OnLogMsg  += new ExternalTool.LogEventHandler(SubtitleMsg);
                            st.Start();
                            st.WaitForExit();
                            if (st == null || !st.Successfull)
                            {
                                error = true;
                            }

                            UpdateStatus(Global.Res("StatusBar") + " " + String.Format(Global.Res("StatusBarSubtitleLowresForced"), subtitle, subtitleCount));
                            st            = new SubtitleTool(settings, fps, ref si, true, true, false);
                            st.OnInfoMsg += new ExternalTool.InfoEventHandler(SubtitleMsg);
                            st.OnLogMsg  += new ExternalTool.LogEventHandler(SubtitleMsg);
                            st.Start();
                            st.WaitForExit();
                            if (st == null || !st.Successfull)
                            {
                                error = true;
                            }
                        }

                        if (!error)
                        {
                            if (si.extraFileInfo != null && si.extraFileInfo.GetType() == typeof(SubtitleFileInfo))
                            {
                                SubtitleFileInfo sfi = (SubtitleFileInfo)si.extraFileInfo;
                                if ((sfi.forcedIdx != "" && sfi.normalIdx != "") || (sfi.forcedSup != "" && sfi.normalSup != ""))
                                {
                                    StreamInfo si2 = new StreamInfo(demuxedStreamList.streams[i]);
                                    if (demuxedStreamList.streams[i].extraFileInfo != null && demuxedStreamList.streams[i].extraFileInfo.GetType() == typeof(SubtitleFileInfo))
                                    {
                                        ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).forcedIdx       = "";
                                        ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).forcedSub       = "";
                                        ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).forcedSup       = "";
                                        ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).forcedIdxLowRes = "";
                                        ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).forcedSubLowRes = "";
                                        ((SubtitleFileInfo)demuxedStreamList.streams[i].extraFileInfo).isSecond        = false;
                                    }
                                    si2.desc += " (only forced)";;
                                    if (si2.extraFileInfo != null && si2.extraFileInfo.GetType() == typeof(SubtitleFileInfo))
                                    {
                                        ((SubtitleFileInfo)si2.extraFileInfo).normalIdx       = "";
                                        ((SubtitleFileInfo)si2.extraFileInfo).normalSub       = "";
                                        ((SubtitleFileInfo)si2.extraFileInfo).normalSup       = "";
                                        ((SubtitleFileInfo)si2.extraFileInfo).normalIdxLowRes = "";
                                        ((SubtitleFileInfo)si2.extraFileInfo).normalSubLowRes = "";
                                        ((SubtitleFileInfo)si2.extraFileInfo).isSecond        = true;
                                    }
                                    bool add = true;
                                    if (demuxedStreamList.streams.Count > i + 1)
                                    {
                                        if (demuxedStreamList.streams[i + 1].extraFileInfo != null && demuxedStreamList.streams[i + 1].extraFileInfo.GetType() == typeof(SubtitleFileInfo))
                                        {
                                            SubtitleFileInfo stfi = (SubtitleFileInfo)demuxedStreamList.streams[i + 1].extraFileInfo;
                                            if (stfi.normalIdx == ((SubtitleFileInfo)si2.extraFileInfo).normalIdx &&
                                                stfi.normalSub == ((SubtitleFileInfo)si2.extraFileInfo).normalSub &&
                                                stfi.normalSup == ((SubtitleFileInfo)si2.extraFileInfo).normalSup &&
                                                stfi.normalIdxLowRes == ((SubtitleFileInfo)si2.extraFileInfo).normalIdxLowRes &&
                                                stfi.normalSubLowRes == ((SubtitleFileInfo)si2.extraFileInfo).normalSubLowRes &&
                                                stfi.forcedIdx == ((SubtitleFileInfo)si2.extraFileInfo).forcedIdx &&
                                                stfi.forcedSub == ((SubtitleFileInfo)si2.extraFileInfo).forcedSub &&
                                                stfi.forcedSup == ((SubtitleFileInfo)si2.extraFileInfo).forcedSup &&
                                                stfi.forcedIdxLowRes == ((SubtitleFileInfo)si2.extraFileInfo).forcedIdxLowRes &&
                                                stfi.forcedSubLowRes == ((SubtitleFileInfo)si2.extraFileInfo).forcedSubLowRes &&
                                                demuxedStreamList.streams[i + 1].filename == si2.filename)
                                            {
                                                add = false;
                                            }
                                        }
                                    }
                                    if (add)
                                    {
                                        demuxedStreamList.streams.Insert(i + 1, si2);
                                        i++;
                                    }
                                }
                                // treat track as forced track even if it doesn't contain forced subs
                                else if (sfi.normalIdx != "" || sfi.normalSup != "")
                                {
                                    if (si.advancedOptions != null && si.advancedOptions.GetType() == typeof(AdvancedSubtitleOptions))
                                    {
                                        if (((AdvancedSubtitleOptions)si.advancedOptions).isForced)
                                        {
                                            sfi.forcedIdx = sfi.normalIdx;
                                            sfi.forcedSub = sfi.normalSub;
                                            sfi.forcedSup = sfi.normalSup;

                                            sfi.forcedIdxLowRes = sfi.normalIdxLowRes;
                                            sfi.forcedSubLowRes = sfi.normalSubLowRes;

                                            sfi.normalIdx = "";
                                            sfi.normalSub = "";
                                            sfi.normalSup = "";

                                            sfi.normalIdxLowRes = "";
                                            sfi.normalSubLowRes = "";
                                        }
                                    }
                                }
                            }
                        }
                    }
                    demuxedStreamsWindow.UpdateDemuxedStreams();
                }

                if (error)
                {
                    logWindow.MessageSubtitle(Global.Res("ErrorSubtitle"));
                    return(false);
                }

                DoPlugin(PluginType.AfterSubtitle);

                TitleInfo.SaveStreamInfoFile(demuxedStreamList, settings.workingDir + "\\" + settings.filePrefix + "_streamInfo.xml");
                demuxedStreamsWindow.UpdateDemuxedStreams();

                return(true);
            }
            catch (Exception ex)
            {
                logWindow.MessageSubtitle(Global.Res("ErrorException") + " " + ex.Message);
                return(false);
            }
            finally
            {
                EnableControls();
                UpdateStatus(Global.Res("StatusBar") + " " + Global.Res("StatusBarReady"));
            }
        }
Beispiel #32
0
        public EncodeTool(UserSettings settings, TitleInfo titleInfo, int profile, bool secondPass, VideoFileInfo vfi)
            : base()
        {
            try
            {
                this.settings = settings;
                this.secondPass = secondPass;
                this.Priority = settings.x264Priority;
                this.vfi = vfi;
                this.titleInfo = titleInfo;
                this.profile = profile;

                bool is2pass = settings.encodingSettings[profile].pass2;
                
                if (settings.encodingSettings[profile].pass2)
                {
                    if (settings.encodingSettings[profile].sizeType == SizeType.Bitrate)
                    {
                        bitrate = (int)settings.encodingSettings[profile].sizeValue;
                    }
                    else if (settings.encodingSettings[profile].sizeType == SizeType.Size)
                    {
                        
                        try
                        {
                            length = Convert.ToInt32(vfi.length);
                            length = (int)(length / 1000);
                        }
                        catch (Exception)
                        {
                        }

                        try
                        {
                            frames = Convert.ToInt32(vfi.frames);
                        }
                        catch (Exception)
                        {
                        }

                        // use frame count to calculate overhead
                        // to be done...

                        totalSize = GetSize();
                        targetSize = Convert.ToInt64(settings.encodingSettings[profile].sizeValue * 1024.0 * 1024.0);
                        bitrate = (int)((targetSize - totalSize) / 1024 / length); //kbyte/s
                        bitrate *= 8; //kbit/s

                        // no mkv overhead used yet
                    }
                }
                
                string outdir = settings.workingDir;
                if (settings.encodedMovieDir != "") outdir = settings.encodedMovieDir;

                string statsFile = outdir + "\\" + settings.filePrefix + "_stats";

                if (!secondPass)
                {
                    if (!settings.encodingSettings[profile].pass2)
                    {
                        if (!settings.use64bit)
                        {
                            this.Path = settings.x264Path;
                            this.Parameter = settings.encodingSettings[profile].GetParam + " \"" + vfi.encodeAvs + "\" -o \"" + outdir +
                                    "\\" + settings.filePrefix + "_video.mkv\"";
                        }
                        else
                        {
                            this.Path = "cmd.exe";
                            this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                                settings.x264x64Path + "\" " + settings.encodingSettings[profile].GetParam + " --fps " + vfi.fps + " " +
                                " -o \"" + outdir + "\\" +
                                settings.filePrefix + "_video.mkv\"" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                        }
                    }
                    else
                    {
                        if (!settings.use64bit)
                        {
                            this.Path = settings.x264Path;
                            this.Parameter = string.Format(settings.encodingSettings[profile].GetParam, bitrate, statsFile) + " \"" + vfi.encodeAvs + "\" -o NUL";
                        }
                        else
                        {
                            this.Path = "cmd.exe";
                            this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                                settings.x264x64Path + "\" " + string.Format(settings.encodingSettings[profile].GetParam, bitrate, statsFile) + " --fps " + vfi.fps +
                                " -o NUL" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                        }
                    }
                }
                else
                {
                    if (!settings.use64bit)
                    {
                        this.Path = settings.x264Path;
                        this.Parameter = string.Format(settings.encodingSettings[profile].GetSecondParam, bitrate, statsFile) + " \"" + vfi.encodeAvs + "\" -o \"" + outdir +
                            "\\" + settings.filePrefix + "_video.mkv\"";
                    }
                    else
                    {
                        this.Path = "cmd.exe";
                        this.Parameter = "/c \"\"" + settings.avs2yuvPath + "\" -raw \"" + vfi.encodeAvs + "\" -o - | \"" +
                            settings.x264x64Path + "\" " + string.Format(settings.encodingSettings[profile].GetSecondParam, bitrate, statsFile) + " --fps " + vfi.fps + " -o \"" + outdir + "\\" +
                            settings.filePrefix + "_video.mkv\"" + " --input-res " + vfi.cropInfo.resizeX + "x" + vfi.cropInfo.resizeY + "\" -";
                    }
                }
            }
            catch (Exception)
            {   
            }
        }