Example #1
0
        void T_KeyFrameGuess()
        {
            bool ffms2_ok = false;

            try
            {
                FFMSWrapper ffmsw = new FFMSWrapper(true);
                ffmsw.UpdateIndexProgress += new FFMSWrapper.IndexingProgressChange(ffmsw_UpdateIndexProgress);
                ffmsw.IndexingCompleted += new FFMSWrapper.IndexingFinished(ffmsw_IndexingCompleted);
                ffmsw.FFMSIndexer(videoInfo.FileName);
                FileInfo fi = new FileInfo(videoInfo.FileName);
                string ffms2_indexfile = Path.Combine(indexDir, fi.Name + ".ffindex");
                if (File.Exists(ffms2_indexfile))
                    ffmsw.FFMSReadIndex(ffms2_indexfile);
                else
                {
                    ffmsw.FFMSDoIndex(true);
                    ffmsw.FFMSWriteIndex(ffms2_indexfile);
                }

                // abrir / cerrar index
                FFMS_SourceData fsd = ffmsw.SourceData;
                FFMS2Track track = new FFMS2Track(fsd);
                track.GetTrack(ffmsw.GetIndex(), 0);

                for (int i = 0; i < track.GetNumFrames(0); i++)
                {
                    FFMS_FrameInfo finfo = track.GetFrameInfo(0, i);
                    if (finfo.KeyFrame == 1)
                        videoInfo.KeyFrames.Add(i);
                }
                ffms2_ok = true;
                SaveCacheSceneDetection(videoInfo.FileName);
                setStatus("Keyframes obtenidos con FFMS2.");
            }
            catch
            {
                if (isVideoLoaded && !isClosing)
                    errorMsg("Error obteniendo keyframes con FFMS2: revisa la configuración de tus códecs.\nSe va a proceder al análisis del vídeo por fuerza bruta, las posiciones pueden no ser exactas.");
                else return;
            }

            // prioridad ffms2 -> dx

            if (!ffms2_ok)
            {
                videoInfo.KeyFrames.Clear();
                captura = new DxScanScenes.Capture(videoInfo.FileName);
                DateTime GuessInit = DateTime.Now;
                captura.EnCambioEscena += new DetectadoCambioEscena(captura_EnCambioEscena);
                captura.EnNuevoFrame += new DetectadoCambioFrame(captura_EnNuevoFrame);
                captura.Start();
                captura.WaitUntilDone();
                TimeSpan GuessDuration = DateTime.Now - GuessInit;
                double velocidad = Math.Round((double)FrameTotal / (double)GuessDuration.TotalSeconds);
                setStatus(captura.DetectedKeyFrames.Count + " escenas detectadas en segundo plano (" + velocidad + " fps).");

                foreach (double sample in captura.DetectedKeyFrames)
                {
                    int conversion = ((int)(sample * videoInfo.FrameRate));
                    videoInfo.KeyFrames.Add(conversion);
                }
                CaptureRes = new Size(captura.m_videoWidth, captura.m_videoHeight);
                SaveCacheSceneDetection(videoInfo.FileName);

                lock (this)
                {
                    captura.Dispose();
                    captura = null;
                }
            }
            UpdateKeyFrameList(true);
            UpdatePanelAnalisis(false);
        }