IMFSourceReaderEx::AddTransformForStream method

Adds a transform, such as an audio or video effect, to a stream.


HRESULT AddTransformForStream(
  [in] DWORD    dwStreamIndex,
  [in] IUnknown *pTransformOrActivate


dwStreamIndex [in]

The stream to configure. The value can be any of the following.


The zero-based index of a stream.


The first video stream.


The first audio stream.


pTransformOrActivate [in]

A pointer to one of the following:

  • A Media Foundation transform (MFT) that exposes the IMFTransform interface.
  • An MFT activation object that exposes the IMFActivate interface.

Return value

This method can return one of these values.

Return codeDescription



The transform does not support the current stream format, and no conversion was possible. See Remarks for more information.


Invalid request.


The dwStreamIndex parameter is invalid.



This method attempts to add the transform at the end of the current processing chain.

To use this method, make the following sequence of calls:

  1. Call IMFSourceReader::SetCurrentMediaType to set the output type that you want for the stream. In this step, you can specify a media type that contains only the major type and subtype GUIDs. For example, to get 32-bit RGB output, set a major type of MFMediaType_Video and a subtype of MFVideoFormat_RGB32. (For more information, see Media Type GUIDs.)
  2. Call AddTransformForStream. If the Source Reader successfully connects the transform, it sets the output type on the transform.
  3. Call IMFSourceReader::GetCurrentMediaType to get the output type from the transform. This method returns a media type with a complete format description.
  4. Optionally, if you want to modify the output type, call IMFSourceReader::SetCurrentMediaType again to set a complete media type on the transform.

The AddTransformForStream method will not insert a decoder into the processing chain. If the native stream format is encoded, and the transform requires an uncompressed format, call SetCurrentMediaType to set the uncompressed format (step 1 in the previous list). However, the method will insert a video processor to convert between RGB and YUV formats, if required.

The method fails if the source reader was configured with the MF_READWRITE_DISABLE_CONVERTERS or MF_SOURCE_READER_ENABLE_VIDEO_PROCESSING attributes.

In asynchronous mode, the method also fails if a sample request is pending. In that case, wait for the OnReadSample callback to be invoked before calling the method. For more information about using the Source Reader in asynchronous mode, see IMFSourceReader::ReadSample.

You can add a transform at any time during streaming. However, the method does not flush or drain the pipeline before inserting the transform. Therefore, if data is already in the pipeline, the next sample is not guaranteed to have the transform applied.


Minimum supported client

Windows 8 [desktop apps | UWP apps]

Minimum supported server

Windows Server 2012 [desktop apps | UWP apps]



See also

Source Reader