Skip to main content
MFCreateMediaBufferFromMediaType function

Allocates a system-memory buffer that is optimal for a specified media type.


HRESULT MFCreateMediaBufferFromMediaType(
  _In_  IMFMediaType   *pMediaType,
  _In_  LONGLONG       llDuration,
  _In_  DWORD          dwMinLength,
  _In_  DWORD          dwMinAlignment,
  _Out_ IMFMediaBuffer **ppBuffer


pMediaType [in]

A pointer to the IMFMediaType interface of the media type.

llDuration [in]

The sample duration. This value is required for audio formats.

dwMinLength [in]

The minimum size of the buffer, in bytes. The actual buffer size might be larger. Specify zero to allocate the default buffer size for the media type.

dwMinAlignment [in]

The minimum memory alignment for the buffer. Specify zero to use the default memory alignment.

ppBuffer [out]

Receives a pointer to the IMFMediaBuffer interface. The caller must release the interface.

Return value

If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.


For video formats, if the format is recognized, the function creates a 2-D buffer that implements the IMF2DBuffer2 interface. Otherwise it creates a linear buffer. To get the IMF2DBuffer2 interface, call QueryInterface on the pointer returned in ppBuffer. If the QueryInterface method fails, use the IMFMediaBuffer interface to access the buffer memory.

For audio formats, the function allocates a buffer that is large enough to contain llDuration audio samples, or dwMinLength, whichever is larger.

This function always allocates system memory. For Direct3D surfaces, use the MFCreateDXGISurfaceBuffer or MFCreateDXSurfaceBuffer function.


Minimum supported client

Windows 8 [desktop apps | UWP apps]

Minimum supported server

Windows Server 2012 [desktop apps | UWP apps]

Minimum supported phone

Windows Phone 8







See also

Media Foundation Functions