Using Video Transforms with the LEADTOOLS Media Foundation Play Control

Microsoft Media Foundation is rapidly gaining ground as more and more people adopt the latest Windows Operating Systems. Naturally, it is growing in popularity among our customers since we released our Media Foundation SDK earlier this year.

LEADTOOLS includes high level controls for handling all of the core Multimedia functionality such as playback, capture and conversion. More advanced applications often implement transforms (previously known as filters in DirectShow) to add special processing to the audio and video streams. One of the most popular and flexible transforms in LEADTOOLS is the Video Callback Transform, which gives you direct access to the raw video data. With that data, and one of LEADTOOLS raster, document or medical imaging SDKs, the possibilities are quite endless.

The following code tip helps crack the egg by playing a video file and saving a still frame to disk as a JPEG:


// Initialize the Callback Transform after setting up the play control
private void AddCallback(object pCallback)
{
   if (lmvCallBkPlay == null)
   {
      playCtrl1.SelectedVideoProcessors.Add(playCtrl1.VideoProcessors.Callback);
      lmvCallBkPlay = playCtrl1.GetSubObject(Leadtools.MediaFoundation.PlayObject.SelVideoProcessor) as LMFVCallback;
      lmvCallBkPlay.ReceiveProcObj = pCallback;
      fCallbackFilterInserted = true;
   }
   else
   {
      lmvCallBkPlay.ReceiveProcObj = pCallback;
      fCallbackFilterInserted = true;
   }
}

// Code for the Callback Transform
public class LEADCallbackPlay : ILMVUserCallback2 
{
   public LEADCallbackPlay(){ }
   ~LEADCallbackPlay(){}
      
   public void ReceiveProc(long pData, int lWidth, int lHeight, int lBitCount, int lSize, int bTopDown)
   {
      Bitmap bmp = new Bitmap(lWidth, lHeight, lBitCount / 8 * lWidth, System.Drawing.Imaging.PixelFormat.Format32bppRgb, new IntPtr(pData));
      bmp.Save("Still_bitmap.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
   }      
}

To download the full example project, check out the original forum post.

About 

LEAD Technologies, Inc.

    Find more about me on:
  • googleplus
This entry was posted in Multimedia Imaging and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *