Share via


Working with ASF Metadata Properties

The ContentInfo object keeps track of properties that are set on the media content during file encoding. These properties are available to the application after the application calls IMFASFContentInfo::ParseHeader. The application can enumerate the file-encoding properties through the IMFMetadata interface.

For a complete list of properties, see the list of attributes in the Format SDK documentation.

Some of these properties, such as variable bit rate (VBR) information, are available to the application through attributes on presentation descriptor, stream descriptors, and media types for the ASF file. For the complete set of these attributes, see the ASF specific attributes listed in Presentation Descriptor Attributes and Stream Descriptor Attributes.

To enumerate metadata properties from the ContentInfo object

  1. Query the ContentInfo object to get a pointer to its implementation of the IMFMetadataProvider interface.

    Note  The ContentInfo object does not support the MF_METADATA_PROVIDER_SERVICE service through IMFGetService.

  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.

Example

The following example code shows how to enumerate the property names and values that are set on the ASF file. For information about the helper macros used in this example, see Using the Media Foundation Code Examples.

/////////////////////////////////////////////////////////////////////
// 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;
    PropVariantInit(&varNames);

    PROPVARIANT varValue;
    PropVariantInit(&varValue);

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

    // Query the ContentInfo object for IMFMetadataProvider.
    CHECK_HR(hr = pContentInfo->QueryInterface(IID_IMFMetadataProvider,
        (void**)&pProvider));

    // 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.
            PropVariantClear(&varValue);
        }
    }
done:
    PropVariantClear(&varNames);
    PropVariantClear(&varValue);
    SAFE_RELEASE (pMetaData);
    SAFE_RELEASE (pProvider);
    return hr;
}

See Also

ASF Support in Media Foundation

Send comments about this topic to Microsoft

Build date: 7/15/2009