Adding Metadata to the File Sink

The ASF file sink is an implementation of IMFMediaSink provided by Media Foundation that an application can use to archive ASF media data to a file. For information about ASF Media Sinks' object model and general usage, see ASF Media Sinks.

After Creating the ASF file sink, it must be configured with information about the streams and encoding information in the output file. These procedures are described in Adding Stream Information to the ASF File Sink and Setting Properties in the File Sink. In addition, You can also add metadata information includes name/value pairs such as "Author", Title". This topic describes the process of adding metadata information to the file sink so that it appears in the final ASF Header Object.

You can add metadata information to the ASF file sink before building the encoding topology. The ASF ContentInfo object for the file sink keeps track of the metadata properties and are exposed to the application through the IMFMetadata interface. Some of these properties, such as "IsVBR" that indicates if the file contains variable bit rate (VBR) streams, are set automatically by the file sink by parsing the stream encoding properties that are set.

For a complete list of properties, see the "Attribute List" topic in the Format SDK documentation.

Using the IMFMetadata Interface on the ASF File Sink

  1. Query the ASF file sink object to get a pointer to its implementation of the IMFMetadataProvider interface.
  2. Call IMFMetadataProvider::GetMFMetadata to get an IMFMetadata pointer.

    The pPresentationDescriptor parameter is ignored and the application can pass NULL. If the application passes zero as the stream identifier in the dwStreamIdentifier parameter, the method retrieves metadata that applies to the entire ASF file. Otherwise, only the metadata for the stream is retrieved.

  3. Call IMFMetadata::GetAllPropertyNames to retrieve the list of file-encoding properties set on the media content.
  4. Call IMFMetadata::GetProperty to get the property values.


The following example code shows how to enumerate the property names and values that are set on the ASF file.

// Name: ListASFProperties
// Enumerates the metadata properties of the ASF file. 
// pContentInfo: Pointer to the ASF ContentInfo object.

HRESULT ListASFProperties(IMFASFContentInfo *pContentInfo)
    HRESULT hr = S_OK;
    PROPVARIANT varNames;

    PROPVARIANT varValue;

    IMFMetadataProvider* pProvider = NULL;
    IMFMetadata* pMetadata = NULL;

    // Query the ContentInfo object for IMFMetadataProvider.
    CHECK_HR(hr = pContentInfo->QueryInterface(IID_IMFMetadataProvider,

    // Get a pointer to IMFMetadata for file-wide metadata.
    CHECK_HR(hr = pProvider->GetMFMetadata(NULL, 0, 0, &pMetadata));

    // Get the property names that are stored in the metadata object.
    CHECK_HR(hr = pMetadata->GetAllPropertyNames(&varNames));

    // Loop through the properties and get their values.
    if (varNames.vt == (VT_VECTOR | VT_LPWSTR))
        ULONG cElements = varNames.calpwstr.cElems;
        for (ULONG i = 0; i < cElements; i++)
            const WCHAR* sName = varNames.calpwstr.pElems[i];
            CHECK_HR(hr = pMetadata->GetProperty(sName, &varValue));
            //Use the property values. Not shown.
    SAFE_RELEASE (pMetaData);
    SAFE_RELEASE (pProvider);
    return hr;

Related topics

ASF Media Sinks
Pipeline Layer ASF Components
ASF Support in Media Foundation