Media Foundation Transform Encoding

This topic explains how to encode media data using the asynchronous Xbox One Media Foundation Transport (MFT).

Important

Beginning with the August 2013 release of the XDK, you must pass in your existing D3D device to use the H.264 encoder MFT. Earlier implementations depended on the MFT to create a D3D device internally. This behavior was changed because the duplicated D3D device caused performance issues. For more information about how to create and pass in your own D3D device, see Initialize the H.264 MFT.

Encoding media data using the asynchronous Xbox One MFT involves the following steps:

  1. Initialize the H.264 MFT
  2. Implement the H.264 Encode Processing Loop
  3. Close the H.264 Encoder MFT

1. Initialize the H.264 MFT

Initializing the H.264 MFT requires the following steps. The code sample H264 Hardware Encoder demonstrates this process.

  1. Call the MFCreateDXGIDeviceManager function to create a DXGI Device Manager.
  2. Pass the IUnknown interface of the existing Microsoft DirectX Graphics Infrastructure (DXGI) device to the IMFDXGIDeviceManager::ResetDevice method of the newly-created DXGI Device Manager.
  3. Initialize the Media Foundation platform.
  4. Create the H.264 encoder MFT.
  5. Unlock the asynchronous encoder (this step is necessary for asynchronous MFT).
  6. Set the output type, encoder parameters, and input type of the H.264 MFT.
  7. Call the IMFTransform::ProcessMessage method to send an MFT_MESSAGE_SET_D3D_MANAGER message to the encoder.
  8. Get the IMFMediaEventGenerator interface from the encoder to use in the processing loop.
  9. Call the ProcessMessage method to send an MFT_MESSAGE_NOTIFY_START_OF_STREAM message to the encoder. This notifies MFT that initial setup is complete and that your app is going to start providing data to encode.

2. Implement the H.264 Encode Processing Loop

Implement the H.264 encode processing loop by processing incoming events from MFT based on the event type, as follows:

3. Close the H.264 Encoder MFT

To close the H.264 Encoder MFT, perform the following steps:

  1. Call the ProcessMessage method to send an MFT_MESSAGE_COMMAND_DRAIN message to the encoder. This forces MFT to generate all of the samples that it has in the buffer.
  2. Receive all processed samples from MFT.
  3. Call the ProcessMessage method to send an MFT_MESSAGE_NOTIFY_END_OF_STREAM message to the encoder.
  4. Shut down the MFT.