IMFSample interface

Represents a media sample, which is a container object for media data. For video, a sample typically contains one video frame. For audio data, a sample typically contains multiple audio samples, rather than a single sample of audio.

A media sample contains zero or more buffers. Each buffer manages a block of memory, and is represented by the IMFMediaBuffer interface. A sample can have multiple buffers. The buffers are kept in an ordered list and accessed by index value. It is also valid to have an empty sample with no buffers.


The IMFSample interface has these methods.

Method Description
IMFSample::AddBuffer Adds a buffer to the end of the list of buffers in the sample.
IMFSample::ConvertToContiguousBuffer Converts a sample with multiple buffers into a sample with a single buffer.
IMFSample::CopyToBuffer Copies the sample data to a buffer. This method concatenates the valid data from all of the buffers of the sample, in order.
IMFSample::GetBufferByIndex Gets a buffer from the sample, by index.
IMFSample::GetBufferCount Retrieves the number of buffers in the sample.
IMFSample::GetSampleDuration Retrieves the duration of the sample.
IMFSample::GetSampleFlags Retrieves flags associated with the sample.Currently no flags are defined.
IMFSample::GetSampleTime Retrieves the presentation time of the sample.
IMFSample::GetTotalLength Retrieves the total length of the valid data in all of the buffers in the sample. The length is calculated as the sum of the values retrieved by the IMFMediaBuffer::GetCurrentLength method.
IMFSample::RemoveAllBuffers Removes all of the buffers from the sample.
IMFSample::RemoveBufferByIndex Removes a buffer at a specified index from the sample.
IMFSample::SetSampleDuration Sets the duration of the sample.
IMFSample::SetSampleFlags Sets flags associated with the sample.Currently no flags are defined.
IMFSample::SetSampleTime Sets the presentation time of the sample.


To create a new media sample, call MFCreateSample.


When you call CopyAllItems, inherited from the IMFAttributes interface, on an IMFSample, the sample time, duration, and flags are not copied to the destination sample. You must copy these values to the new sample manually.

This interface is available on the following platforms if the Windows Media Format 11 SDK redistributable components are installed:
  • Windows XP with Service Pack 2 (SP2) and later.
  • Windows XP Media Center Edition 2005 with KB900325 (Windows XP Media Center Edition 2005) and KB925766 (October 2006 Update Rollup for Windows XP Media Center Edition) installed.


Windows version Windows Vista [desktop apps | UWP apps] Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header mfobjects.h (include Mfidl.h)

See Also


Media Foundation Interfaces

Media Samples

Sample Attributes