public static Bitmap MFrame2Bitmap(ref MFFrame _mFrame, out M_VID_PROPS _vidProps) { // Clone frame to RGB32 MFFrame mFrame = _mFrame; _mFrame.MFClone(out mFrame, eMFrameClone.eMFC_Reference, eMFCC.eMFCC_ARGB32); // FrameVideoGetBytes(out cbPicture, out pbPicture); int cbSize; long pbVideo; mFrame.MFVideoGetBytes(out cbSize, out pbVideo); // Get Props from frame int audioSample; M_AV_PROPS avProps; mFrame.MFAVPropsGet(out avProps, out audioSample); // Create a bitmap from frame Bitmap bmpPicture = new Bitmap(avProps.vidProps.nWidth, Math.Abs(avProps.vidProps.nHeight), avProps.vidProps.nRowBytes, System.Drawing.Imaging.PixelFormat.Format32bppRgb, new IntPtr(pbVideo)); _vidProps = avProps.vidProps; _mFrame = mFrame; return(bmpPicture); }
private void BodyAction(object sender) { try { flagIsOver = false; MFFrame pFrame = (MFFrame)sender; MFFrame clonedFrame; pFrame.MFClone(out clonedFrame, eMFrameClone.eMFC_Video, eMFCC.eMFCC_ARGB32); M_AV_PROPS avProps; int audiosamples; clonedFrame.MFAVPropsGet(out avProps, out audiosamples); int cbPicture; long pbPicture; clonedFrame.MFVideoGetBytes(out cbPicture, out pbPicture); int nRowBytes = avProps.vidProps.nRowBytes; IntPtr ptr = new IntPtr(pbPicture); Image bSource = new Bitmap(avProps.vidProps.nWidth, Math.Abs(avProps.vidProps.nHeight), nRowBytes, PixelFormat.Format32bppRgb, ptr); this.Invoke(new Action(() => MainPreview.SetSource(bSource))); Marshal.ReleaseComObject(clonedFrame); m_nFrameCounter++; if (m_nFrameCounter == 10) { GC.Collect(); m_nFrameCounter = 0; } flagIsOver = true; } catch { flagIsOver = true; } }
public MFFrame DrawTextOnFrame(MFFrame mFrame, string text, int fontSize = 8) { if (fontSize < 0) { throw new ArgumentOutOfRangeException(); } if (!string.IsNullOrEmpty(text)) { MFFrame mFrameClone = null; try { mFrame.MFClone(out mFrameClone, eMFrameClone.eMFC_Full, eMFCC.eMFCC_Default); var overlay = Overlay; mFrameClone.MFPrint(text, fontSize, ref overlay, eMFTextFlags.eMFT_WordBreaks, ""); Marshal.ReleaseComObject(mFrame); return(mFrameClone); } catch { if (mFrameClone != null) { Marshal.ReleaseComObject(mFrameClone); } return(mFrame); } } return(mFrame); }
private void thread_DoWork(CancellationToken token) { while (!token.IsCancellationRequested) { MFFrame frame = null; if (!decoder) { noSignalFrame.MFClone(out frame, eMFrameClone.eMFC_Full, eMFCC.eMFCC_Default); m_objPreview.ReceiverFramePut(frame, -1, ""); } if (decoder) { m_objLive.SourceFrameGet(-1, out frame, ""); m_objPreview.ReceiverFramePut(frame, -1, ""); } if (frame != null) { Marshal.ReleaseComObject(frame); } } }
private bool NextFrame() { if (m_objReader != null) { MFFrame frame = null; MFFrame frameOver = null; MFFrame frameClone = null; M_AV_PROPS props; m_objReader.SourceAVPropsGet(out props); props.vidProps.eVideoFormat = eMVideoFormat.eMVF_HD1080_50i; m_objReader.SourceFrameConvertedGet(ref props, -1, out frame, ""); if (start) { m_objReader.SourceFrameConvertedGet(ref props, 0, out frameOver, ""); //frame.MFOverlayRect(frameOver, null, ref overlayRect, eMFOverlayFlags.eMFOF_Crop, 1, "", ""); //frame.MFOverlay(frameOver, null, 10, 10, 1, "", "ch1"); } frame.MFClone(out frameClone, eMFrameClone.eMFC_Reference, eMFCC.eMFCC_RGB24); m_objPrev.ReceiverFramePut(frameClone, -1, ""); Marshal.ReleaseComObject(frame); if (frameOver != null) { Marshal.ReleaseComObject(frameOver); } if (frameClone != null) { Marshal.ReleaseComObject(frameClone); } } return(true); }