Example #1
0
        private void RunScript(int scriptType, string trimLine)
        {
            int selectEvery = sectionLength;

            if (settings.AnalysePercent > 0)
            {
                int minAnalyseSections = settings.MinimumAnalyseSections;
                if (settings.MinimumAnalyseSections < settings.MinimumUsefulSections)
                {
                    minAnalyseSections = settings.MinimumUsefulSections;
                }
                if (scriptType == 1)
                {
                    // Field order script. For this, we separatefields, so we have twice as many frames anyway
                    // It saves time, and costs nothing to halve the minimum sections to analyse for this example
                    minAnalyseSections = minAnalyseSections / 2 + 1; // We add one to prevent getting 0;
                }

                selectEvery = (int)((100.0 * (double)sectionLength) / ((double)settings.AnalysePercent));

                // check if we have to modify the SelectRangeEvery parameter
                // = if we are below the minimal to be analysed sections
                if (((double)frameCount / (double)selectEvery) < (int)minAnalyseSections)
                {
                    if (frameCount >= minAnalyseSections * sectionLength)
                    {
                        // there are more frames available as necessary for the minimal alaysis
                        selectEvery = (int)((double)frameCount / (double)minAnalyseSections);
                    }
                    else
                    {
                        // if there aren't enough frames, analyse everything
                        selectEvery = sectionLength;
                    }
                }
            }

            string logFileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), (scriptType == 1) ? "ff_interlace-" + Guid.NewGuid().ToString("N") + ".log" : "interlace-" + Guid.NewGuid().ToString("N") + ".log");

            if (File.Exists(logFileName))
            {
                File.Delete(logFileName);
            }

            string resultScript = ScriptServer.GetDetectionScript(scriptType, script, trimLine, logFileName, selectEvery, sectionLength);

            MethodInvoker mi = delegate {
                try
                {
                    Process(resultScript, logFileName, scriptType);

                    if (!continueWorking)
                    {
                        isStopped = true;
                        return;
                    }

                    if (error)
                    {
                        return;
                    }

                    if (scriptType == 0)
                    {
                        Analyse(selectEvery, sectionLength, frameCount); // detection
                    }
                    else
                    {
                        AnalyseFF(); // field order
                    }
                }
                finally
                {
                    try
                    {
                        File.Delete(logFileName);
                    }
                    catch (Exception)
                    {
                    }
                }
                isStopped = true;
            };

            analyseThread          = new Thread(new ThreadStart(mi));
            analyseThread.Priority = priority;
            analyseThread.Start();
        }