LPR/Analytics event/alarms get snapshot using JPEGVideoSource.GetFrameAt(time) leads to consume and increase app memory.

All,

I need to get the snapshot for the LPT/analytics event at specified time.

As suggested in last question i am using API JPEGVideoSource.GetFrameAt(time).

The issue is when i use this API to get snapshot my app memory keep increasing too much ( 1-3 GB ) this is very bad.

I am using MIP SDK 2019R2 version.

Please let me know is my way of getting event snapshot is correct & help me resolve memory issue asap.

Hi. Can you please provide your sample? Because we would like to see this symptom.

Sample here

-----------------

private readonly Dictionary<string, JPEGVideoSource> \_cameraJPEGSourceList = new Dictionary<string, JPEGVideoSource>();

public IMilestoneArchiveVideoFrame GetSnapShotAt(string deviceFQID, DateTime frameTimeUtc)

{

  IMilestoneArchiveVideoFrame videoFrame = null;

  try

  {

    JPEGVideoSource source = null;

    JPEGData frame = null;

    if (!\_cameraJPEGSourceList.ContainsKey(deviceFQID))

    {

      Item camera = VideoOS.Platform.Configuration.Instance.GetItem(new Guid(deviceFQID), Kind.Camera);

      if (camera == null)

      {

        Logger.WarnFormat("Unable to get snapshot as Milestone API GetItem() returns null for camera={0}", deviceFQID);

        return videoFrame;

      }

      source = new JPEGVideoSource(camera);

      source.Init();

      \_cameraJPEGSourceList.Add(deviceFQID, source);

    }

    source = \_cameraJPEGSourceList\[deviceFQID\];

    if (source != null) frame = (JPEGData)source.Get(frameTimeUtc);

    if (frame == null) return null;

    videoFrame = new MilestoneArchiveVideoFrame(frame);

  }

  catch (Exception exception)

  {

    Logger.Error(exception);

  }

  return videoFrame;

}

Note:

1.> As you know JPEGVideoSource.Init() need to do to get snapshot frame. Since Init() take bit time hence during start up i do Init() for all cameras hold in dictionary

  So, runitime ( many events/second) i get cameraid JPEGVideoSource and get snapshot frame ( better performance) 

I am using _cameraJPEGSourceList = new Dictionary<string, JPEGVideoSource>();

As mentioned, above code leads to increse memory of app, please guide better way to get event time snapshot (without app mem increase ) for camera

(our production has many events/second)

--------------------

Note: Today , i found cause , after calling JPEGVideoSource.close() memory will NOT increase.

Issue is why milestone API after JPEGVideoSource.Get() complete hold memory must free. ( presently expect to free by external app)

Second, when i do JPEGVideoSource.Close() next time again i need to do JPEGVideoSource.Init ( which takes time , costly when heavy analytics event rate)

Hope you got clear picture now.

If you run the Media Playback Viewer sample you will see how you can continue to get new Jpeg images without leaking memory.

I have a feeling that you get a extraordinary high memory by having an extraordinary big amount of JPEGVideoSource objects active at the same time.

I do not think the JPEGVideoSource has changed.

If I understand the situation correctly you can create and initialize JPEGVideoSources for each camera, and at that point the memory consumption is not big, whenever a JPEGVideoSource.Get is used the memory consumption is increased (expected as image data is retrieved and transcoded), the memory consumption is not reduced before a JPEGVideoSource.Close is done. The combined memory consumption of all the JPEGVideoSources is in this scenario so big that it will be the cause of crashes.

Unfortunately there is no way to have an active JPEGVideoSource clean up and release it memory usage except doing the close.

I suggest that you have a background thread running that for the cameras one by one does a JPEGVideoSource. -Init-Get-Close.

I hope this answers your question and concern. Let me know if you have followup questions.

I checked Playback Viewer sample , this sample for the only one camera so holding and closing Close() once is no problem.

Our app may have 1000+ cameras and need to get snapshot for any cameras as per request and some time frequency is so high. ( many alarms /second) In this case JPEGVideoSource. -Init() is bit time taking.

No choice , As suggested now i will do JPEGVideoSource. -Init-Get-Close.

My suggestion is once you do JPEGVideoSource. -Init-Get() memory hold should auto release when context of alling JPEGVideoSource. -Get() is closed ( after return and image data hold in another variable).

OR next version make flag for JPEGVideoSource. -Get() to auto destroy image data. Then this is up to user to use flag while calling JPEGVideoSource. -Get().

Reason, now days VCA is becoming quite common & getting image snapshot is very basic and there should be efficient ( SDK level) way of memory/cpu aware methods.

Hope this change can implement in next SDK version.

Thanks for support.

I have on your behalf, with basis in this question and discussion, sent an request for enhancement to Milestone Product Management.

This means that your suggestion will be evaluated as input for the prioritization of future development work. I am not able to say when or even if this feature will be developed.