How to save a bitmap raw data by using TransferVideoFrame()

All replies

  • Hello,

    I would suggest you to follow this sample code to using Media Engine.

    Best regards,

    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 9, 2012 8:10 AM
  • hi, hardi:

    I have added capture a frame function in ME sample, to capture a bitmap from d3d surface after transfervideoframe. it works like this: 

    1) create ID2D1factory1, and then CreateDevice;

    2) get dxgisurface from swapchain,  like this: m_spDX11SwapChain->GetBuffer(0, IID_PPV_ARGS(&dxgiBackBuffer)) 

    3) create bitmap from dxgisurface.  like this:  m_d2dContext->CreateBitmapFromDxgiSurface

    4) save bitmap to file.

    4.1) get a IRandomAccessStream from a file,  get Istream from it via system api: CreateStreamOverRandomAccessStream

    4.2) create IWICBitmapEncoder,   Initialize it from  this Istream.

    4.3) create IWICImageEncoder,  call IWICImageEncoder->WriteFrame to transfer d2dbitmap what we got before  to Istream .

    4.4) IWICImageEncoder::commit,  IWICBitmapEncoder::commmit,  Istream::commit 

    5) that's all.

    surely,  if you want to transfer video frame to image source and render it by yourself,  it's another case.

    I have tried solution before consume preview,  and it crashed always on my PC. 

    as I got Media engine sample source code from consume previw,  I didn't try it again,   just apply DXGI manager to media engine and render with d3d device is fine for me.

    ---------------------------------------------- JohnYe from SHANGHAI. email: yechzh@126.com

    Tuesday, April 10, 2012 3:17 AM