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); }
public void UpdatePreview(MFFrame _pFrame) { int nASamples = 0; _pFrame.MFAVPropsGet(out m_avProps, out nASamples); m_objPreview.ReceiverFramePut(_pFrame, -1, ""); }
private bool NextFrame() { // Get request pos and set pause and reverse flags double dblRequest = -1.0; string strParams = string.Empty; // Update player state lock (playerState.stateLock) { if (playerState.state == eState.eST_Pause) { strParams = " pause=true"; } else if (playerState.state == eState.eST_PlayRev || playerState.state == eState.eST_StepRev) { strParams = " reverse=true"; } // Update player state if (playerState.state == eState.eST_StepFwd || playerState.state == eState.eST_StepRev) { // Pause on next iteration - because single frame was requested playerState.state = eState.eST_Pause; } // Get request time and set next cycle request to next frame // -1 as first parameter means "give me next frame", -5 means "give me next next 5th frame" etc, // this works accordingly when the reverse=true parameter is set. // positive values are uninterpreted as "give me frame at position" dblRequest = playerState.dblFrameRequest; playerState.dblFrameRequest = -1 * (int)(playerState.dblRate); } // Next frame cycle: // Get frame from reader and send to preview // Note: Preview keep frame according to frame time MFFrame pFrame = null; lock (objLock) // For prevent reader replace in OpenFile() and overlay change { // Get next frame or frame by position // -1 as first parameter means "give me next frame", -5 means "give me next next 5th frame" etc, // this works accordingly when the reverse=true parameter is set. // positive values are uninterpreted as "give me frame at position" try { if (objMFReader != null) { objMFReader.SourceFrameConvertedGetByTime(ref avProps, dblRequest, -1, out pFrame, strParams); } // Update avProps if (pFrame != null) { int nASamples = 0; pFrame.MFAVPropsGet(out avProps, out nASamples); } } catch (System.Exception ex) { MessageBox.Show("Error occurs during file decoding:\n\n" + ex.Message, playerState.strFileName, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (pFrame != null) { try { objPreview.ReceiverFramePut(pFrame, -1, ""); releaseComObj(pFrame); } catch (System.Exception ex) { MessageBox.Show("Error occurs during frame processing:\n\n" + ex.Message, playerState.strFileName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } // Check for the last frame if ((Time.eFFlags & eMFrameFlags.eMFF_Last) != 0) { lock (playerState.stateLock) { // Pause playback at the end of the file if loop is disabled if (!playerState.bLoop) { pause(); } if (playerState.state == eState.eST_PlayRev) { // Rewind to end in case of reverse playback seek(playerState.dblDuration); } else if (playerState.state == eState.eST_PlayFwd) { // Rewind to start in case of direct playback seek(0); } } } return(true); }
private bool NextFrame() { // Get request pos and set pause and reverse flags double dblRequest = -1.0; string strParams = string.Empty; // Update player state lock (m_playerState.stateLock) { if (m_playerState.state == eState.eST_Pause) { strParams = " pause=true"; } else if (m_playerState.state == eState.eST_PlayRev || m_playerState.state == eState.eST_StepRev) { strParams = " reverse=true"; } // Update player state if (m_playerState.state == eState.eST_StepFwd || m_playerState.state == eState.eST_StepRev) { // Pause on next iteration - because single frame was requested m_playerState.state = eState.eST_Pause; } // Get request time and set next cycle request to next frame // -1 as first parameter means "give me next frame", -5 means "give me next next 5th frame" etc, // this works accordingly when the reverse=true parameter is set. // positive values are uninterpreted as "give me frame at position" dblRequest = m_playerState.dblFrameRequest; m_playerState.dblFrameRequest = -1 * (int)(m_playerState.dblRate); } // Next frame cycle: // Get frame from reader and send to preview // Note: Preview keep frame according to frame time MFFrame pFrame = null; lock (m_objLock) // For prevent reader replace in OpenFile() and overlay change { // Get next frame or frame by position // -1 as first parameter means "give me next frame", -5 means "give me next next 5th frame" etc, // this works accordingly when the reverse=true parameter is set. // positive values are uninterpreted as "give me frame at position" try { if (m_objMFReader != null) { m_objMFReader.SourceFrameConvertedGetByTime(ref m_avProps, dblRequest, -1, out pFrame, strParams + " rate=0.1"); } int samples; pFrame.MFAVPropsGet(out currentProps, out samples); } catch (System.Exception ex) { MessageBox.Show("Error occurs during file decoding:\n\n" + ex.Message, m_playerState.strFileName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } if (pFrame == null) { Thread.Sleep(5); return(true); } try { // Demonstrate overlay - overlay another frame if any if (m_frOverlay != null) { pFrame.MFOverlay(m_frOverlay, null, 50, 100, 0.5, "", ""); } // Show CG object if (checkBoxCG.Checked) { ShowPluggin(m_objCharGen, ref pFrame); if (cgEditor != null) { cgEditor.m_objEditor_FrameProcessed(pFrame, null); } } // Show CC if (checkBoxCC.Checked) { if (m_objCCDisplay != null) { ShowPluggin(m_objCCDisplay, ref pFrame); } } // Show HTML if (checkBoxHTML.Checked) { lock (m_objHTMLLock) { if (m_objOverlayHTML != null) { ShowPluggin(m_objOverlayHTML, ref pFrame); if (overlayHTMLWind != null && !overlayHTMLWind.IsDisposed) { overlayHTMLWind.UpdatePreview(pFrame); } } } } mAudioMeter1.pFrame = pFrame; mAudioMeter1.SetValues(); // Get frame timings pFrame.MFTimeGet(out mTime); double dblDur = 0; m_objMFReader.ReaderDurationGet(out dblDur); if (m_playerState.dblDuration != dblDur) { m_playerState.dblDuration = dblDur; } // Send frame to Renderer SendToRenderer(pFrame); //Send frame to the preview m_objPreview.ReceiverFramePut(pFrame, checkBoxRenderer.Checked ? 0 : -1, ""); //Send to Sink SendToSink(pFrame); //Release frame - DO NOT FORGOT TO DO THIS !!! releaseComObj(pFrame); } catch (System.Exception ex) { MessageBox.Show("Error occurs during frame processing:\n\n" + ex.Message, m_playerState.strFileName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } // Check for the last frame if ((mTime.eFFlags & eMFrameFlags.eMFF_Last) != 0) { lock (m_playerState.stateLock) { // Pause playback at the end of the file if loop is disabled if (!m_playerState.bLoop) { pause(); } if (m_playerState.state == eState.eST_PlayRev) { // Rewind to end in case of reverse playback rewindToEnd(); } else if (m_playerState.state == eState.eST_PlayFwd) { // Rewind to start in case of direct playback rewindToStart(); } } } return(true); }
private void thread_DoWork(CancellationToken token) { while (!token.IsCancellationRequested) { MFFrame pFrame = null; int audioSamples = 0; if (startAudio) { M_AUD_PROPS AduioProps = new M_AUD_PROPS(); try { m_objReaderAudio.SourceFrameGet(-1, out pFrame, ""); m_objAudBuff.BufferFramePut("", pFrame, ""); m_objAudBuff.BufferPropsGet("", out AduioProps, out audioSamples); #region BeforeBuffer pFrame.MFAVPropsGet(out VolumeProps, out asamp); levelOrigin = VolumeProps.ancData.audOriginal.arrVUMeter[0]; leverOutPut = VolumeProps.ancData.audOutput.arrVUMeter[0]; BeginInvoke(new ChangeLabel(UpdateLabel1)); BeginInvoke(new ChangeLabel(UpdateLabel2)); BeginInvoke(new ChangeLabel(UpdateBar)); #endregion Marshal.ReleaseComObject(pFrame); } catch { pFrame = null; MessageBox.Show("Start Audio Part!"); } if (startVideo) { m_objReaderFile.SourceFrameGet(-1, out pFrame, ""); int samples = 0; if (audioSamples > 2000) { m_objAudBuff.BufferFrameFill("", pFrame, ref samples, ""); } m_objPreview.ReceiverFramePut(pFrame, -1, ""); #region AfterBuffer pFrame.MFAVPropsGet(out VolumeProps, out asamp); levelOrigin = VolumeProps.ancData.audOriginal.arrVUMeter[0]; leverOutPut = VolumeProps.ancData.audOutput.arrVUMeter[0]; BeginInvoke(new ChangeLabel(UpdateLabel3)); BeginInvoke(new ChangeLabel(UpdateLabel4)); #endregion m_objAudBuff.BufferRemove("", ref samples); Marshal.ReleaseComObject(pFrame); } } } }
public void UpdateControl() { if (pFrame != null) { try { M_AV_PROPS avProps; int samples; pFrame.MFAVPropsGet(out avProps, out samples); if (arrChannels != null) { for (int i = 0; i < arrChannels.Length; i++) { if (arrChannels[i] != null) { arrChannels[i].Dispose(); } } } arrChannels = new MAudioChannel[avProps.audProps.nChannels]; for (int i = 0; i < avProps.audProps.nChannels; i++) { arrChannels[i] = new MAudioChannel(); arrChannels[i].Parent = this; arrChannels[i].Visible = true; arrChannels[i].ColorLevelBack = ColorLevelBack; arrChannels[i].ColorLevelOrg = ColorLevelOrg; arrChannels[i].ColorLevelHi = ColorLevelHi; arrChannels[i].ColorLevelMid = ColorLevelMid; arrChannels[i].ColorLevelLo = ColorLevelLo; arrChannels[i].ColorOutline = ColorOutline; arrChannels[i].ColorGainSlider = ColorGainSlider; arrChannels[i].Risk = 6; int nTop = 10; arrChannels[i].Location = new Point((int)(arrChannels[i].Bounds.Width * i + fLeftIndent), (int)(Font.Height / 2) + nTop); arrChannels[i].Height = (int)(this.Height - Font.Height / 2.0 - nTop); arrChannels[i].Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom; } float fWidth = avProps.audProps.nChannels > 0 ? (int)(arrChannels[0].Bounds.Width * avProps.audProps.nChannels + fLeftIndent + fRightIndent) : (int)(fLeftIndent + fRightIndent); this.Width = (int)Math.Max(fWidth, 0); if (ChannelsUpdated != null) { ChannelsUpdated(null, null); } Invalidate(); } catch (System.Exception ex) { } } }
private void thread_DoWork(CancellationToken token) { MFFactoryClass _factory = new MFFactoryClass(); while (!token.IsCancellationRequested) { if (decode) { MFFrame frame = null; string path = String.Format(@"\\MLDiskStation\MLFiles\Trash\Roman\NetTestFiles\LG_jazz\LG_jazz\LG_jazz{0:d7}.jpg", index); Debug.WriteLine("Picture:" + index.ToString()); index = ++index == 291 ? 0 : index; //291 is count of pictures in image sequences { Bitmap bmp = (Bitmap)System.Drawing.Image.FromFile(path); Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb); M_AV_PROPS avProps = new M_AV_PROPS(); avProps.vidProps.eVideoFormat = eMVideoFormat.eMVF_HD1080_30p; avProps.vidProps.fccType = eMFCC.eMFCC_RGB32; avProps.vidProps.nWidth = bmp.Width; avProps.vidProps.nHeight = -1 * bmp.Height; // Negative height for top-bottom RGB images (if positive->bottom-top) avProps.vidProps.nRowBytes = bmpData.Stride; // distance between lines _factory.MFFrameCreateFromMem(ref avProps, bmpData.Scan0.ToInt64(), 0, 0, out frame, ""); bmp.UnlockBits(bmpData); bmp.Dispose(); } M_AV_PROPS props; int samples; frame.MFAVPropsGet(out props, out samples); props.vidProps.eVideoFormat = eMVideoFormat.eMVF_HD1080_30p; props.vidProps.dblRate = 30.0; props.vidProps.nAspectX = 16; props.vidProps.nAspectY = 9; MFFrame frameConvert; int nRest = 0; frame.MFConvert(ref props, out frameConvert, out nRest, "", ""); m_objPreview.ReceiverFramePut(frameConvert, 0, ""); m_objWriter.ReceiverFramePut(frameConvert, -1, ""); if (stopWr) { m_objWriter.WriterClose(0); } Marshal.ReleaseComObject(frameConvert); Marshal.ReleaseComObject(frame); GC.Collect(); } } }