//==================================Method1===========================================
        unsafe void PixelDifferenceSD(IntPtr pBuffer, int BufferLen)
        {
            byte* pb = (byte*)pBuffer;
            int diffcounter = 0;
            if (prevFrame != null)
            {
                for (int x = 0; x < m_videoHeight; x++)
                {
                    for (int y = 0; (y < m_videoWidth); y++)
                    {
                        // calculate color difference for one pixel (between current and previous frame)
                        int d = Math.Abs((*pb) - prevFrame[(x * m_videoWidth + y) * 3]);
                        pb++;
                        d += Math.Abs((*pb) - prevFrame[((x * m_videoWidth + y) * 3) + 1]);
                        pb++;
                        d += Math.Abs((*pb) - prevFrame[((x * m_videoWidth + y) * 3) + 2]);
                        pb++;

                        // if difference is large enough, add 1 to diffcounter
                        if (d > method1_delta2)
                            diffcounter++;
                    }

                }
                if ((double)diffcounter / (m_videoHeight * m_videoWidth) > method1_delta3)
                {
                    currentshot.End = m_Count - 1;
                    shots.Add(currentshot);
                    Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                    currentshot = new Shot("Startframe " + m_Count, m_Count, -1, b);

                }

            }
            else
            {
                Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                currentshot = new Shot("Startframe " + m_Count, 0, -1, b); //-1 is placeholder for end not known
            }
        }
        /// <summary> File name to scan</summary>
        public Capture(string FileName)
        {
            //INTIALISATIE
            methodnr = 1;
            method1_delta2 = 0;
            method1_delta3 = 0;
            method2_tresh = 0;
            method2and3_block_size = 0;
            method2_window_size = 0;
            method3_init_step = 0;
            method3_tresh = 0;
            method4_tresh = 0;
            method4_bins = 0;
            method5_tresh = 0;
            method5and6_bins = 0;
            method5and6_region_size = 0;
            method6_tresh = 0;
            method6_var = 0;
            method6_buffer = 0;

            shots = new List<Shot>();
            prevFrame = null;
            prevFrameBufferLen = 0;
            currentshot = null;
            histogramPrevFrame = null;
            localHistogramPrevFrame = null;
            localHistogramsBuffer = new List<int[][][]>();

            try
            {
                // Set up the capture graph
                SetupGraph(FileName);
            }
            catch
            {
                Dispose();
                throw;
            }
        }
        //==================================Method5===========================================
        private unsafe void LocalHistogramSD(IntPtr pBuffer, int BufferLen)
        {
            // allowed region sizes: 2x2, 4x4,8x8, 16x16 (will fit in test videos)
            int numberOfLocalHist = m_videoWidth * m_videoHeight / method5and6_region_size;
            // one local histogram for each color value (R, G and B)
            int[][][] localHistogramCurrentFrame = new int[numberOfLocalHist][][];

            for (int i = 0; i < numberOfLocalHist; i++)
            {
                // RGB-values per localHistogram
                localHistogramCurrentFrame[i] = new int[3][];
                for (int j = 0; j < 3; j++)
                {
                    // number of bins
                    localHistogramCurrentFrame[i][j] = new int[method5and6_bins];
                }
            }

            // create local histrograms
            CreateLocalHistograms(pBuffer, ref localHistogramCurrentFrame);

            if (prevFrame != null)
            {
                // if difference is large enough
                if (LocalHistogramDifference(ref localHistogramCurrentFrame, ref localHistogramPrevFrame) > method5_tresh)
                {
                    // add shot
                    currentshot.End = m_Count - 1;
                    shots.Add(currentshot);
                    Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                    currentshot = new Shot("Startframe " + m_Count, m_Count, -1, b);
                    localHistogramPrevFrame = localHistogramCurrentFrame;
                }
            }
            else
            {
                Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                currentshot = new Shot("Startframe " + m_Count, 0, -1, b); //-1 is placeholder for end not known
                localHistogramPrevFrame = localHistogramCurrentFrame;
            }
        }
        //==================================Method4===========================================
        private unsafe void GlobalHistogramSD(IntPtr pBuffer, int BufferLen)
        {
            // one histogram for each color value (R, G and B)
            int[][] histogramCurrentFrame = new int[3][];

            for (int i = 0; i < 3; i++)
            {
                // number of bins
                histogramCurrentFrame[i] = new int[method4_bins];
            }

            // Create histogram for current frame
            CreateHistogram(pBuffer, ref histogramCurrentFrame);

            if (prevFrame != null)
            {
                // calculate difference between current and previous frame histogram
                if (HistogramDifference(ref histogramCurrentFrame, ref histogramPrevFrame) > method4_tresh)
                {
                    // add shot
                    currentshot.End = m_Count - 1;
                    shots.Add(currentshot);
                    Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                    currentshot = new Shot("Startframe " + m_Count, m_Count, -1, b);
                    histogramPrevFrame = histogramCurrentFrame;
                }
            }
            else
            {
                Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                currentshot = new Shot("Startframe " + m_Count, 0, -1, b); //-1 is placeholder for end not known
                histogramPrevFrame = histogramCurrentFrame;
            }
        }
        //==================================Method6===========================================
        private unsafe void GeneralizedLocalHistogramSD(IntPtr pBuffer, int BufferLen)
        {
            // constants and allocation
            int numberOfLocalHist = m_videoWidth * m_videoHeight / method5and6_region_size;
            int[][][] localHistogramCurrentFrame = new int[numberOfLocalHist][][];
            for (int i = 0; i < numberOfLocalHist; i++)
            {
                localHistogramCurrentFrame[i] = new int[3][];
                for (int j = 0; j < 3; j++)
                {
                    localHistogramCurrentFrame[i][j] = new int[method5and6_bins];
                }
            }

            // start first shot
            if (prevFrame == null)
            {
                Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                currentshot = new Shot("Startframe " + m_Count, 0, -1, b); //-1 is placeholder for end not known
            }

            // Calculate local histograms of current frame
            CreateLocalHistograms(pBuffer, ref localHistogramCurrentFrame);

            if (localHistogramsBuffer.Count == method6_buffer)
            {
                int count = 0;
                double mean = 0.0;
                double[] differences = LocalHistrogramAllDifferences(ref localHistogramCurrentFrame);

                // how many previous frames differ?
                for (int i = 0; i < differences.Length; i++)
                {
                    mean += (double)differences[i];
                    if (differences[i] > method6_tresh)
                    {
                        count++;
                    }
                }
                mean = mean / method6_buffer;

                // if differences are all larger than threshold => cut
                if (count == method6_buffer)
                {
                    currentshot.End = m_Count - 1;
                    shots.Add(currentshot);
                    Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                    currentshot = new Shot("Startframe " + m_Count, m_Count, -1, b);

                    //flush histogram-buffer
                    localHistogramsBuffer.Clear();
                }

                // id not all differences are larger, but some are above threshold
                if (count > 0 && count < method6_buffer)
                {
                    // calculate variance of differences
                    double var = 0.0;
                    for (int i = 0; i < differences.Length; i++)
                    {
                        var += ((double)differences[i] - mean) * ((double)differences[i] - mean);
                    }
                    var = var / method6_buffer;

                    // if variance is large => gradual transition
                    if (var > method6_var)
                    {
                        currentshot.End = m_Count - 1;
                        shots.Add(currentshot);
                        Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                        currentshot = new Shot("Startframe " + m_Count, m_Count, -1, b);

                        //flush histogram-buffer
                        localHistogramsBuffer.Clear();
                    }

                    // add current to buffer and remove first one
                    localHistogramsBuffer.RemoveAt(0);
                    localHistogramsBuffer.Add(localHistogramCurrentFrame);
                }

                //
                if (count == 0)
                {
                    // add current to buffer and remove first one
                    localHistogramsBuffer.RemoveAt(0);
                    localHistogramsBuffer.Add(localHistogramCurrentFrame);
                }
            }
            else
            {
                // just add local histograms of frame to list untill buffer is full
                localHistogramsBuffer.Add(localHistogramCurrentFrame);
            }
        }
        //==================================Method2===========================================
        unsafe void ExhaustiveMotionEstimation(IntPtr pBuffer, int BufferLen)
        {
            if (prevFrame != null)
            {
                // calculate difference
                double diff = ExhaustiveMotionEstimationCompareHelper(pBuffer, BufferLen);
                if (diff > method2_tresh)
                {
                    // add shot
                    currentshot.End = m_Count - 1;
                    shots.Add(currentshot);
                    Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                    currentshot = new Shot("Startframe " + m_Count, m_Count, -1, b);
                }
            }
            else
            {
                Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                currentshot = new Shot("Startframe " + m_Count, 0, -1, b); //-1 is placeholder for end not known

            }
        }
        //==================================Method6===========================================
        private unsafe void GeneralizedLocalHistogramSD(IntPtr pBuffer, int BufferLen)
        {
            // constants and allocation
            int numberOfLocalHist = m_videoWidth * m_videoHeight / method5and6_region_size;

            int[][][] localHistogramCurrentFrame = new int[numberOfLocalHist][][];
            for (int i = 0; i < numberOfLocalHist; i++)
            {
                localHistogramCurrentFrame[i] = new int[3][];
                for (int j = 0; j < 3; j++)
                {
                    localHistogramCurrentFrame[i][j] = new int[method5and6_bins];
                }
            }

            // start first shot
            if (prevFrame == null)
            {
                Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                currentshot = new Shot("Startframe " + m_Count, 0, -1, b); //-1 is placeholder for end not known
            }

            // Calculate local histograms of current frame
            CreateLocalHistograms(pBuffer, ref localHistogramCurrentFrame);

            if (localHistogramsBuffer.Count == method6_buffer)
            {
                int      count       = 0;
                double   mean        = 0.0;
                double[] differences = LocalHistrogramAllDifferences(ref localHistogramCurrentFrame);

                // how many previous frames differ?
                for (int i = 0; i < differences.Length; i++)
                {
                    mean += (double)differences[i];
                    if (differences[i] > method6_tresh)
                    {
                        count++;
                    }
                }
                mean = mean / method6_buffer;

                // if differences are all larger than threshold => cut
                if (count == method6_buffer)
                {
                    currentshot.End = m_Count - 1;
                    shots.Add(currentshot);
                    Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                    currentshot = new Shot("Startframe " + m_Count, m_Count, -1, b);

                    //flush histogram-buffer
                    localHistogramsBuffer.Clear();
                }

                // id not all differences are larger, but some are above threshold
                if (count > 0 && count < method6_buffer)
                {
                    // calculate variance of differences
                    double var = 0.0;
                    for (int i = 0; i < differences.Length; i++)
                    {
                        var += ((double)differences[i] - mean) * ((double)differences[i] - mean);
                    }
                    var = var / method6_buffer;

                    // if variance is large => gradual transition
                    if (var > method6_var)
                    {
                        currentshot.End = m_Count - 1;
                        shots.Add(currentshot);
                        Bitmap b = DeepCopyBitmapGenerator(pBuffer);
                        currentshot = new Shot("Startframe " + m_Count, m_Count, -1, b);

                        //flush histogram-buffer
                        localHistogramsBuffer.Clear();
                    }

                    // add current to buffer and remove first one
                    localHistogramsBuffer.RemoveAt(0);
                    localHistogramsBuffer.Add(localHistogramCurrentFrame);
                }

                //
                if (count == 0)
                {
                    // add current to buffer and remove first one
                    localHistogramsBuffer.RemoveAt(0);
                    localHistogramsBuffer.Add(localHistogramCurrentFrame);
                }
            }
            else
            {
                // just add local histograms of frame to list untill buffer is full
                localHistogramsBuffer.Add(localHistogramCurrentFrame);
            }
        }