Home > Archive (Community help, from old helpdesk) > How to stream without hogging memory?

How to stream without hogging memory?

Avatar image
Aug 23, 2015
Archive Agent wrote
I'm using VF to capture occasional BMPs from a USB camera. I want to ignore most of what's streaming by, then grab what's relevant. So I set the Mode to Mode_Video_Preview. The buffered preview stream fills memory quite quickly. If I Pause, the memory fill stops; with Resume it starts again. How do I limit memory use or dispose of the buffer contents? Obviously, I can pause except for brief moments when I want data, but that's awkward. I need a way to just dump the gunk. I have not used CODECs or filters previously, and I'm not using them now. Should I be?

Alex on January 22, 2014 01:53
Completed
0
Vote
Reply
4 Answers
Aug 23, 2015
Archive Agent agent wrote
Roman Minyaylov

Hi

.Net, ActiveX or Delphi SDK?

Which event use? If OnVideoFrame/OnVideoFrameBuffer/OnVideoFrameBitmap used you are do not need to free object from event args.

on January 22, 2014 10:17
Aug 23, 2015
Archive Agent agent wrote
Alex

Delphi SDK. I'm not using any of the OnVideoFrame events. I simply have the camera on and use Frame_GetCurrent. Roughly:
Resume;
{wait 0.5 s to ensure there something in the buffer}
Frame_GetCurrent(mybitmap);
Pause;

The other thing I notice is that the bitmap I get does not seem to have been influenced by contrast, hue, etc. settings -- it's a free run, unconstrained image. That's a clue that I'm not hooking into what is displayed in the streaming video window. Thoughts?

on January 22, 2014 19:32
Aug 23, 2015
Archive Agent agent wrote
Roman Minyaylov

Yes, you must free TBtmap that you get. So, you did something wrong if it eats memory.

Using this way you have access to original image.

on January 22, 2014 20:07
Aug 23, 2015
Archive Agent agent wrote
Alex

Would I be better off with an OnVideoFrame that does something like:

global variables: destinationdesired : bitmap; datadesired : boolean;
{datadesired set to false most of the time. When a frame is desired, set to true;}

procedure videoframeprocessor(sender: tobject);

var
dummybitmap : tbitmap;

try
localbitmap := tbitmap.create;
{insert code to define size and pixel format}
If DataDesired then
begin
DesiredDestinationBitmap.Assign(Frame_GetCurrent(dummybitmap);
datadesired := false; {prevents multiple unintentional frame grabs}
end
Else
begin
Frame_GetCurrent(dummybitmap); {grabs the current frame}
end;
finally
dummybitmap.destory;
end;

on January 22, 2014 20:59