Example #1
0
        public Bitmap generateBackdrop()
        {
            //throw new NotImplementedException();
            VideoFileReader reader = new AForge.Video.FFMPEG.VideoFileReader();

            reader.Open(fullPath);
            int frame = 3000;

            if (frame > reader.FrameCount)
            {
                frame = (int)(reader.FrameCount / 2);
            }
            for (int i = 0; i < frame; i++)
            {
                Bitmap b = reader.ReadVideoFrame();
                b.Dispose();
                //reader.ReadVideoFrame();
            }
            return(reader.ReadVideoFrame());
        }
Example #2
0
        public static List <double> GetByteArrayDifferencesAlternative(string fileName, Action <int> progress)
        {
            var listToReturn = new List <double>();

            byte[] previous        = new byte[] { };
            var    videoFileReader = new AForge.Video.FFMPEG.VideoFileReader();


            videoFileReader.Open(fileName);
            Console.WriteLine("frameCount: " + videoFileReader.FrameCount);
            var fps = videoFileReader.FrameRate;

            var totalSecondsGuess = (double)videoFileReader.FrameCount / (double)videoFileReader.FrameRate;
            var sequentialErrors  = 0;

            for (int i = 0; i < videoFileReader.FrameCount; i++)
            {
                var skipErrorCode = videoFileReader.ReadVideoFrameAndSkipDecode(i);
                if (skipErrorCode == 0)
                {
                    sequentialErrors = 0;
                    var frame     = videoFileReader.ReadVideoFrame();
                    var byteArray = GetBigMapArray(frame, i);
                    if (i > 0)
                    {
                        var avDis = GetAverageDifferenceFromPrevious(byteArray, previous, 20);
                        listToReturn.Add(avDis);
                    }
                    previous = byteArray;


                    var fractionChanges = (double)i / (double)totalSecondsGuess;
                    var percentChanges  = 100 * fractionChanges;
                    progress((int)(Math.Floor(percentChanges)));
                }
                else
                {
                    if (sequentialErrors <= 5)
                    {
                        sequentialErrors++;
                        skipErrorCode = videoFileReader.ReadVideoFrameAndSkipDecode(i + 1);
                        listToReturn.Add(0);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            progress(100);
            return(listToReturn);
        }