Creating an ASF Profile

This topic describes how to create as ASF profile in Microsoft Media Foundation.

Create a New Profile

To create an empty ASF profile, call the MFCreateASFProfile function. This function returns a pointer to the IMFASFProfile interface. The application can use this interface to add streams to the profile, and to configure each of the streams. For more information, see Creating and Configuring ASF Streams.

Optionally, the application can add mutual-exclusion objects to two or more streams. See Using Mutual Exclusion for ASF Streams.

Get the Profile from the ASF ContentInfo Object

An application can get the ASF profile of an existing ASF file from the ASF ContentInfo Object. The profile is already configured and contains settings for the all of the streams in the file.

Initialize the ContentInfo object by parsing the ASF Header Object of the file. This is done through the IMFASFContentInfo::ParseHeader method. After all the Header Objects are read and the ASF library is populated, the profile for this file is generated. The application can get a pointer to this initialized profile by calling IMFASFContentInfo::GetProfile.

Get the Profile from a Presentation Descriptor

You can get the profile object of an existing ASF file from the presentation descriptor for the file, or from the ASF ContentInfo object. In this case, the profile is already configured and contains settings for all of the streams in the file. This can be useful if you want to modify an existing ASF profile. For example, you might wish to re-encode a Windows Media Video file at a lower bit rate.

To get the profile from the presentation descriptor, call MFCreateASFProfileFromPresentationDescriptor. This function parses the presentation descriptor, and populates an ASF profile with information about the media file. The function returns a pointer to the IMFASFProfile interface. You can then use this interface to modify the profile.

To get the presentation descriptor, call one of the following methods:

The following example shows how to create a profile from a presentation descriptor. The function creates a media source for the file, gets the presentation descriptor from the media source, and creates a profile. This example assumes that pszFileName specifies the URL of an ASF file.

HRESULT GetASFProfile(PCWSTR pszFileName, IMFASFProfile** ppProfile)
{
    *ppProfile = NULL;

    IMFSourceResolver* pResolver = NULL;
    IUnknown* pSourceUnk = NULL;
    IMFMediaSource* pSource = NULL;
    IMFPresentationDescriptor* pPD = NULL;

    // Create the source resolver.
    HRESULT hr = MFCreateSourceResolver(&pResolver);

    // Use the source resolver to create the media source.
    if (SUCCEEDED(hr))
    {
        MF_OBJECT_TYPE ObjectType;

        hr = pResolver->CreateObjectFromURL(
                pszFileName,
                MF_RESOLUTION_MEDIASOURCE, 
                NULL,                      
                &ObjectType,               
                &pSourceUnk   
            );
    }

    // Get the IMFMediaSource interface from the media source.
    if (SUCCEEDED(hr))
    {
        hr = pSourceUnk->QueryInterface(IID_PPV_ARGS(&pSource));
    }

    // Get the presentation descriptor.
    if (SUCCEEDED(hr))
    {
        hr = pSource->CreatePresentationDescriptor(&pPD);
    }

    // Get the profile from the presentation descriptor.
    if (SUCCEEDED(hr))
    {
        hr = MFCreateASFProfileFromPresentationDescriptor(pPD, ppProfile);
    }

    SafeRelease(&pResolver);
    SafeRelease(&pSourceUnk);
    SafeRelease(&pSource);
    SafeRelease(&pPD);
    return hr;
}

This example uses SafeRelease to release interface pointers.

ASF Profile