MFormats SDK: delaying the stream for a specific number of frames (MDelay feature)

The MDelay object delays the incoming stream (from live sources, network streams and files). For example, MDelay allows you to preview a video event from the live source after the event took place without recording it to file. A delay of the stream is precise down to a single frame.


MDelay is available in both MFormats SDK and MPlatform SDK. This article explains how to use MDelay with MPlatfrom.


To work with MDelay in MFormats SDK you need to:


1. Create MDelay object from the MFormats library:


MDelayClass m_objDelay = new MDelayClass();


2. Configure this object. Set necessary features using PropsSet method:


m_objDelay.PropsSet("mdelay.time", "10"); // 10 second delay


3. Process the incoming frame using ProcessFrame method. As a result, both of the frames, delayed and the original, are accessible. For example:


// Incoming frame received from the source
MFFrame pFrame;

// Result (delayed) frame
int nFramesRes;
MFFrame pFrameOut = null;

// Deliver original frame to the object and get delayed one.
m_objDelay.ProcessFrame(pFrame, out pFrameOut, out nFramesRes, "");
if (pFrameOut != null)
{
	// Clear memory of the incoming frame if it is no longer needed
	Marshal.ReleaseComObject(pFrame);
}
// Use the result frame (pFrameOut) as you need: send to the Preview, output to capture card, write to file, etc.


These are the properties of MDelay for PropsSet method:


  • mdelay.time - delay time.
  • mdelay.quality - quality of the recorded signal and possible values from 0 to 100.
  • mdelay.sync_time - minimal step for the web cam video. When the frame length is not equal, some of the frames might be dropped. To avoid such dropping increase this parameter. Default setting of 120 ms provides miniscule dropping.
  • mdelay.split_progressive - to speed up the encoding for the progressive video each frame is split in two half-frames by the fields and is encoded separately. 
  • mdelay.buffer_path - a path to the buffer file.
  • mdelay.buffer_duration - duration of the buffer in seconds. If equal 0 than will be written only to RAM.
  • mdelay.buffer_size_mem - buffer size in RAM in bytes. Values can be written in their short form: 100M 1G 1T 1K.


You can try MDelay feature in the Live input with file mixing sample: