-1

In my project i take video frames one by one, compress them into 1x1 pixel and then get its color to store in a List. Problem is, if i take ~9,5 minute video, at 25 fps it only processes about 15-20% before it runs out of memory at 2gb used. But i use 64 bit os and processor, and i dont know how to allocate more ram to my project. Also, List of colors will be read quickly (25-30 times per second) so i dont think that creating temp files is an option, or at least i would like to try allocating more ram. So, question is: how do i allocate more than 2 gb to my .net 4.7 code?

My image processing code:

List<Color> VideoFramesData = new List<Color>();

//fires when i click "parse"  button in my form:   
private void ParseVideoButton_Click(object sender, EventArgs e)
        {
            while (VideoReader.Read()) 
            {
                VideoFramesData.Add(CollapseBitmap(VideoReader.GetFrame()));
            }
        }

//Image downscaling function:

public Color CollapseBitmap(Bitmap bmp)
        {
            Color FrameColor;
            Bitmap result = new Bitmap(1, 1);
            Graphics g = Graphics.FromImage(result);
            g.InterpolationMode = InterpolationMode.NearestNeighbor;

            g.DrawImage(bmp, 0, 0, 1, 1);
            FrameColor = result.GetPixel(0, 0);
            result.Dispose();
            g.Dispose();
            return FrameColor;
        }

  • Something wrong for sure, because 25fps * 60s/min * 9.5min * 3bytes per pixel is about 42 kilobytes! Instead of resizing things, why not just crawl the video frame by frame calculating the average colour per frame just based on the RGB values? this stays away from thousands of Graphics operations – Caius Jard Sep 27 '19 at 20:00
  • 1
    Based on code you've posted there is a good chance that you are missing some `Dispose` calls as you do it by hand rather than letting `using` to deal with all cases... Ignoring that compiling x64 or AnyCPU without "prefer x86" would likely solve your problem – Alexei Levenkov Sep 27 '19 at 20:10

1 Answers1

1

Ok, pinned down my problem: i was not Bitmap.Dispose'ing of bmp function parameter, and turns out, you have to do this. Well, the more i know!