• Api Documentation
  • Source Code
Search Results for

    Show / Hide Table of Contents
    • JeremyAnsel.DirectX.MediaFoundation
      • MF2DBuffer
      • MFAttributes
      • MFDXGIDeviceManager
      • MFFactory
      • MFHelpers
      • MFMediaBuffer
      • MFMediaFormatGuids
      • MFMediaFormatGuids.Audio
      • MFMediaFormatGuids.Image
      • MFMediaFormatGuids.Video
      • MFMediaType
      • MFMediaTypeGuids
      • MFMediaTypeMajorGuids
      • MFReadWriteGuids
      • MFSample
      • MFSinkWriter
      • MFSinkWriterGuids
      • MFSourceReader
      • MFSourceReaderControlFlags
      • MFSourceReaderFlags
      • MFSourceReaderGuids
      • MFVideoInterlaceMode

    Class MFSample

    The IMFSample interface represents a multimedia sample for a multimedia stream type. An typical example is a video frame, and a notable exception is audio where an IMFSample does not usually represent a single sample of audio, but rather a chunk of audio samples. Note that this allows us to reduce the overhead for representing audio in the pipeline.

    A sample may consist of a multiple buffers as is the case of compressed audio or video samples received from the network or being sent to an ASF media sink or ASF multiplexer.

    The IMFAttributes interface can be used to tag the sample with extra information that is not represented by the IMFSample methods. The MFSampleExtension_xxx GUIDs in mfapi.h define some standard attributes, but custom attributes are allowed and are preserved through the Media Foundation pipeline as well as possible.

    Inheritance
    object
    DXComObject
    MFAttributes
    MFSample
    Implements
    IDisposable
    Inherited Members
    MFAttributes.MFAttributesGuid
    MFAttributes.GetItemType(Guid)
    MFAttributes.GetUINT32(Guid)
    MFAttributes.GetUINT64(Guid)
    MFAttributes.GetDouble(Guid)
    MFAttributes.GetGUID(Guid)
    MFAttributes.GetStringLength(Guid)
    MFAttributes.GetString(Guid)
    MFAttributes.GetUnknown(Guid, Guid)
    MFAttributes.DeleteItem(Guid)
    MFAttributes.DeleteAllItems()
    MFAttributes.SetUINT32(Guid, uint)
    MFAttributes.SetUINT64(Guid, ulong)
    MFAttributes.SetDouble(Guid, double)
    MFAttributes.SetGUID(Guid, Guid)
    MFAttributes.SetString(Guid, string)
    MFAttributes.SetUnknown(Guid, nint)
    MFAttributes.LockStore()
    MFAttributes.UnlockStore()
    MFAttributes.GetCount()
    MFAttributes.CopyAllItems(MFAttributes)
    MFAttributes.GetAttributeUINT32(Guid, uint)
    MFAttributes.GetAttributeUINT64(Guid, ulong)
    MFAttributes.GetAttributeDouble(Guid, double)
    MFAttributes.GetAttribute2UINT32asUINT64(Guid, out uint, out uint)
    MFAttributes.SetAttribute2UINT32asUINT64(Guid, uint, uint)
    MFAttributes.GetAttributeRatio(Guid, out uint, out uint)
    MFAttributes.GetAttributeSize(Guid, out uint, out uint)
    MFAttributes.SetAttributeRatio(Guid, uint, uint)
    MFAttributes.SetAttributeSize(Guid, uint, uint)
    DXComObject.Dispose()
    DXComObject.AddRef()
    DXComObject.Release()
    DXComObject.QueryInterface(in Guid)
    DXComObject.Handle
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: JeremyAnsel.DirectX.MediaFoundation
    Assembly: JeremyAnsel.DirectX.MediaFoundation.dll
    Syntax
    [SecurityCritical]
    public class MFSample : MFAttributes, IDisposable
    Remarks

    MediaFoundation does not provide a synchronized (thread-safe) way to call the IMFSample methods. To guarantee thread-safety, the caller should obtain a lock while working with sample object to prevent access by other threads.

    Constructors

    | Edit this page View Source

    MFSample(nint)

    Initializes a new instance of the MFSample class.

    Declaration
    public MFSample(nint comPtr)
    Parameters
    Type Name Description
    nint comPtr

    Fields

    | Edit this page View Source

    MFSampleGuid

    The interface GUID.

    Declaration
    public static readonly Guid MFSampleGuid
    Field Value
    Type Description
    Guid

    Methods

    | Edit this page View Source

    AddBuffer(MFMediaBuffer)

    The AddBuffer method allows the caller to add a media buffer to the end of current list of buffers in the sample.

    Declaration
    public void AddBuffer(MFMediaBuffer pBuffer)
    Parameters
    Type Name Description
    MFMediaBuffer pBuffer

    Pointer to a buffer object.

    Remarks

    The newly added buffer represents sample data at an offset equal to the previous total length of the sample.

    | Edit this page View Source

    ConvertToContiguousBuffer()

    The GetContiguousBuffer method converts sample with multiple buffers into sample with single buffer and returns a pointer to this buffer.

    Declaration
    public MFMediaBuffer ConvertToContiguousBuffer()
    Returns
    Type Description
    MFMediaBuffer
    Remarks

    This method copies the content of the sample into a contiguous media buffer, and should be used with care.

    | Edit this page View Source

    CopyToBuffer(MFMediaBuffer)

    The CopyToBuffer method allows the caller to copy the sample data to the buffer object provided.

    Declaration
    public void CopyToBuffer(MFMediaBuffer pBuffer)
    Parameters
    Type Name Description
    MFMediaBuffer pBuffer

    Pointer to a buffer object.

    | Edit this page View Source

    GetBufferByIndex(uint)

    The GetBufferByIndex method returns a pointer to the IMFMediaBuffer object at a specified index in the sample.

    Declaration
    public MFMediaBuffer GetBufferByIndex(uint dwIndex)
    Parameters
    Type Name Description
    uint dwIndex

    32 bit value specifying the index of the buffer object requested.

    Returns
    Type Description
    MFMediaBuffer
    | Edit this page View Source

    GetBufferCount()

    The GetBufferCount method returns the count of the buffers in that are currently associated with this sample.

    Declaration
    public uint GetBufferCount()
    Returns
    Type Description
    uint
    Remarks

    It is valid to have a sample with a buffer count of zero. This is considered to be an empty sample.

    | Edit this page View Source

    GetSampleDuration()

    The GetSampleDuration method returns the duration of the sample.

    Declaration
    public ulong GetSampleDuration()
    Returns
    Type Description
    ulong

    If the method succeeds, it returns S_OK. If no the sample does not have a duration MF_E_NO_SAMPLE_DURATION is returned. If this method fails otherwise it returns an error code.

    Remarks

    The duration is specified in 100ns interval units. If the duration is zero, then the sample duration is unknown. In such cases, it is possible that it can be derived from the media type e.g. video frame rate. Application should avoid calculating duration of presentation as sum of sample durations because of possible cumulative error. For example cumulative error for 60fps video on 24 hours interval is 0.1728 seconds. For 60fps, there are 5184000 frames * 166667 100ns/frame = 24 hours + 0.1728 seconds

    | Edit this page View Source

    GetSampleTime()

    The GetSampleTime method returns the presentation time associated with the sample.

    Declaration
    public ulong GetSampleTime()
    Returns
    Type Description
    ulong

    If the method succeeds, it returns S_OK. If no the sample does not have a sample time MF_E_NO_SAMPLE_TIMESTAMP is returned. If this method fails otherwise it returns an error code.

    Remarks

    The presentation time is stored in 100ns interval units.

    | Edit this page View Source

    GetTotalLength()

    The GetTotalLength method returns the total length of all buffers objects in the sample.

    Declaration
    public uint GetTotalLength()
    Returns
    Type Description
    uint
    Remarks

    The total length of the sample is tracked when buffers are added (via AddBuffer), removed (via RemoveBufferByIndex and RemoveAllBuffers).

    | Edit this page View Source

    RemoveAllBuffers()

    The RemoveAllBuffers method allows the caller to remove all buffer objects associated with the sample.

    Declaration
    public void RemoveAllBuffers()
    Remarks

    After this call, the buffer count of the sample is zero i.e. it is an empty sample.

    | Edit this page View Source

    RemoveBufferByIndex(uint)

    The RemoveBufferByIndex method allows the caller to remove a buffer object at a specified index within the list of available buffer objects in the sample.

    Declaration
    public void RemoveBufferByIndex(uint dwIndex)
    Parameters
    Type Name Description
    uint dwIndex

    32 bit value specifying the index.

    Remarks

    The total length of the sample is reduced by the length of the removed buffer, and the offsets of all buffer objects that were at indices greater than dwIndex are shifted up by the length of the removed buffer.

    | Edit this page View Source

    SetSampleDuration(ulong)

    The SetSampleDuration method allows the caller to set the duration of the sample.

    Declaration
    public void SetSampleDuration(ulong hnsSampleDuration)
    Parameters
    Type Name Description
    ulong hnsSampleDuration

    64 bit value specifying the sample duration.

    Remarks

    The duration is specified in 100ns interval units. This value should be set wherever possible to aid in the processing of samples in a multimedia pipeline.

    | Edit this page View Source

    SetSampleTime(ulong)

    The SetSampleTime method allows the caller to set the presentation time associated with the sample.

    Declaration
    public void SetSampleTime(ulong hnsSampleTime)
    Parameters
    Type Name Description
    ulong hnsSampleTime

    64 bit value specifying the presentation time.

    Remarks

    The presentation time is stored in 100ns interval units.

    Implements

    IDisposable
    • Edit this page
    • View Source
    In this article
    Back to top Copyright (c) 2026 Jérémy Ansel