/// <summary>
        /// Поиск ключевых кадров (второй проход алгоритма)
        /// </summary>
        /// <param name="videoFileName">Имя видеофайла</param>
        /// <param name="frameWidth">Ширина кадра</param>
        /// <param name="frameHeight">Высотка кадра</param>
        /// <param name="framesDifferences">Разница кадров</param>
        /// <param name="treshold">Порог</param>
        /// <returns></returns>
        private List<GreyVideoFrame> GetKeyFrames(string videoFileName, int frameWidth, int frameHeight,
            List<int> framesDifferences, double treshold)
        {
            try
            {
                List<GreyVideoFrame> keyFrames = new List<GreyVideoFrame>();
                ImageConvertor imageConvertor = new ImageConvertor();

                string videoPath = System.IO.Path.GetDirectoryName(videoFileName);
                string framesDirName = Path.Combine(videoPath, "VideoFrames");
                if (!Directory.Exists(framesDirName))
                    Directory.CreateDirectory(framesDirName);

                Capture capture = new Capture(videoFileName);
                Image<Gray, Byte> frame = capture.QueryGrayFrame().Resize(frameWidth, frameHeight, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
                AddKeyFrameFunction(keyFrames, frame, Path.Combine(framesDirName, "0.jpg"), 0, true);

                int framesDifferencesNumber = framesDifferences.Count;
                int previousFrameNumber = 0;
             //   BitmapConvertor bitmapConvertor = new BitmapConvertor();
                for (int i = 0; i < framesDifferencesNumber; i++)
                {
                    frame = capture.QueryGrayFrame();
                    if (framesDifferences[i] > treshold && i + 1 != previousFrameNumber + 1)
                    {
                        int frameNumber = i + 1;
                        previousFrameNumber = i + 1;
                        frame = capture.QueryGrayFrame().Resize(frameWidth, frameHeight, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
                        AddKeyFrameFunction(keyFrames, frame, Path.Combine(framesDirName, frameNumber.ToString() + ".jpg"), frameNumber, true);
                    }
                    if (i == framesDifferencesNumber - 1)
                        keyFrameExtractedEvent(i, i + 1, true);
                    else
                        keyFrameExtractedEvent(i, i + 1, false);
                }
                return keyFrames;
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
        /// <summary>
        /// Извлечение ключевых кадров из списка кадров
        /// </summary>
        /// <param name="videoFileName">Имя видео файла</param>
        /// <param name="frameWidth">Ширина кадра</param>
        /// <param name="frameHeight">Высота кадра</param>
        /// <param name="keyFramesInformation">Список нужных кадров</param>
        /// <returns>Ключевые кадры</returns>
        private List<GreyVideoFrame> GetKeyFrames(string videoFileName, int frameWidth, int frameHeight, List<KeyFrameIOInformation> keyFramesInformation)
        {
            try
            {
                List<GreyVideoFrame> keyFrames = new List<GreyVideoFrame>();
                ImageConvertor imageConvertor = new ImageConvertor();

                string videoPath = System.IO.Path.GetDirectoryName(videoFileName);
                string framesDirName = Path.Combine(videoPath, "VideoFrames");
                if (!Directory.Exists(framesDirName))
                    Directory.CreateDirectory(framesDirName);

                Capture capture = new Capture(videoFileName);
                Image<Gray, Byte> frame = capture.QueryGrayFrame();

                int frameNumber = 0;
                CheckKeyFrameAndAddIfInList(keyFrames, keyFramesInformation, frame, framesDirName, frameNumber, frameWidth, frameHeight);
                if (frame != null)
                {
                    keyFrameExtractedEvent(frameNumber, frameNumber + 1, false);
                    do
                    {
                        frame = capture.QueryGrayFrame();
                        ++frameNumber;
                        CheckKeyFrameAndAddIfInList(keyFrames, keyFramesInformation, frame, framesDirName, frameNumber, frameWidth, frameHeight);
                        if (frame != null)
                            keyFrameExtractedEvent(frameNumber, frameNumber + 1, false);
                        else
                            keyFrameExtractedEvent(frameNumber, frameNumber + 1, true);
                    }
                    while (frame != null);
                }
                else
                    keyFrameExtractedEvent(frameNumber, frameNumber + 1, true);
                return keyFrames;
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
        /// <summary>
        /// Поиск ключевых кадров видео
        /// </summary>
        /// <param name="frames">Все серые кадры</param>
        /// <param name="coloredFrames">Все цветные кадры</param>
        /// <param name="framesDifferences">Разницы кадров</param>
        /// <param name="treshold">Порог</param>
        /// <returns>Ключевые кадры</returns>
        private List<GreyVideoFrame> GetKeyFrames(List<Image<Gray, Byte>> frames, List<Image<Bgr, Byte>> coloredFrames,
            List<int> framesDifferences, double treshold)
        {
            try
            {
                ImageConvertor imageConvertor = new ImageConvertor();

                List<GreyVideoFrame> keyFrames = new List<GreyVideoFrame>();
                GreyVideoFrame firstKeyFrame = new GreyVideoFrame();
                firstKeyFrame.FrameNumber = 0;
                firstKeyFrame.Frame = imageConvertor.ConvertColor(frames[0]);
                keyFrames.Add(firstKeyFrame);

                int framesDifferencesNumber = framesDifferences.Count;
                int previousFrameNumber = 0;
                for (int i = 0; i < framesDifferencesNumber; i++)
                {
                    if (framesDifferences[i] > treshold && i + 1 != previousFrameNumber + 1)
                    {
                        GreyVideoFrame keyFrame = new GreyVideoFrame();
                        keyFrame.FrameNumber = i + 1;
                        previousFrameNumber = i + 1;
                        keyFrame.OriginalFrame = coloredFrames[i + 1];
                        keyFrame.Frame = imageConvertor.ConvertColor(frames[i + 1]);
                        keyFrames.Add(keyFrame);
                    }
                    if (i == framesDifferencesNumber - 1)
                        keyFrameExtractedEvent(i, i + 1, true);
                    else
                        keyFrameExtractedEvent(i, i + 1, false);
                }
                return keyFrames;
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }