Esempio n. 1
0
        public static VideoStream OpenFile(string fileName)
        {
            List<string> allEngines = TangraVideo.EnumVideoEngines().ToList();

            var allEnginesByAttemptOrder = new List<string>(allEngines);
            allEnginesByAttemptOrder.RemoveAt(TangraConfig.Settings.Generic.AviRenderingEngineIndex);
            allEnginesByAttemptOrder.Insert(0, allEngines[TangraConfig.Settings.Generic.AviRenderingEngineIndex]);

            Dictionary<int, string> allEnginesByIndex = allEnginesByAttemptOrder.ToDictionary(x => allEngines.IndexOf(x), x => x);

            Exception lastError = null;

            foreach (int engineIdx in allEnginesByIndex.Keys)
            {
                try
                {
                    TangraVideo.SetVideoEngine(engineIdx);

                    VideoFileInfo fileInfo = TangraVideo.OpenFile(fileName);

                    TangraContext.Current.RenderingEngine = allEnginesByIndex[engineIdx];

                    var rv = new VideoStream(fileInfo, fileName);

                    // Try to load the first frame to be sure that it is going to work, before accepting this video engine for rendering
                    rv.GetPixelmap(fileInfo.FirstFrame);

                    UsageStats.Instance.ProcessedAviFiles++;

                    if (allEnginesByIndex[engineIdx] == "VideoForWindows")
                        UsageStats.Instance.VideoForWindowsUsed++;
                    else if (allEnginesByIndex[engineIdx] == "DirectShow")
                        UsageStats.Instance.DirectShowUsed++;

                    UsageStats.Instance.Save();

                    return rv;
                }
                catch (Exception ex)
                {
                    lastError = ex;
                }
            }

            throw new InvalidVideoFileException(lastError != null
                ? lastError.Message
                : "None of the rendering engines was able to open the file.");
        }