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

Category: windows metro apps games

Question

Hardi_Liang on Fri, 06 Apr 2012 06:49:52


I have found  TransferVideoFrame() in Media engine native C++ playback sample

http://msdn.microsoft.com/en-us/library/windows/desktop/hh448021(v=vs.85).aspx

I want to use it to get the decoded data. My input is a mp4 or wmv file.

I am a newby for DirectX

any suggestion?

Thanks,

Hardi

Replies

Jesse Jiang on Mon, 09 Apr 2012 08:10:00


Hello,

I would suggest you to follow this sample code to using Media Engine.
http://code.msdn.microsoft.com/windowsapps/Media-Engine-Playback-ce1c82f0/

Best regards,
Jesse

JohnYe on Tue, 10 Apr 2012 03:17:24


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.