共用方式為


MFCreateTranscodeProfile 函式 (mfidl.h)

建立空的轉碼設定檔物件。

轉碼設定檔會儲存輸出檔案的組態設定。 這些組態設定是由呼叫端指定,並包含音訊和視訊串流屬性、編碼器設定和容器設定。 若要設定這些屬性,呼叫端必須呼叫適當的 IMFTranscodeProfile 方法。

設定的轉碼設定檔會傳遞至 MFCreateTranscodeTopology 函式。 基礎拓撲產生器會使用這些設定來建置轉碼拓撲。

語法

HRESULT MFCreateTranscodeProfile(
  [out] IMFTranscodeProfile **ppTranscodeProfile
);

參數

[out] ppTranscodeProfile

接收轉碼設定檔物件的 IMFTranscodeProfile 介面指標。 呼叫端必須釋放 介面。

傳回值

如果此函式成功,則會傳回 S_OK。 否則,它會傳回 HRESULT 錯誤碼。

備註

MFCreateTranscodeProfile 函式會建立空的轉碼設定檔。 您必須設定可定義媒體類型和容器屬性的轉碼設定檔設定屬性。 使用下列方法來設定設定檔:

如需使用此函式的範例程式碼,請參閱下列主題:

範例

下列範例會建立 Windows Media Audio (WMA) 的轉碼設定檔。

template <class Q>
HRESULT GetCollectionObject(IMFCollection *pCollection, DWORD index, Q **ppObj)
{
    IUnknown *pUnk;
    HRESULT hr = pCollection->GetElement(index, &pUnk);
    if (SUCCEEDED(hr))
    {
        hr = pUnk->QueryInterface(IID_PPV_ARGS(ppObj));
        pUnk->Release();
    }
    return hr;
}

HRESULT CreateTranscodeProfile(IMFTranscodeProfile **ppProfile)
{
    IMFTranscodeProfile *pProfile = NULL;     // Transcode profile.
    IMFCollection   *pAvailableTypes = NULL;  // List of audio media types.
    IMFMediaType    *pAudioType = NULL;       // Audio media type.
    IMFAttributes   *pAudioAttrs = NULL;      // Copy of the audio media type.
    IMFAttributes   *pContainer = NULL;       // Container attributes.

    DWORD dwMTCount = 0;
    
    // Create an empty transcode profile.
    HRESULT hr = MFCreateTranscodeProfile(&pProfile);
    if (FAILED(hr))
    {
        goto done;
    }

    // Get output media types for the Windows Media audio encoder.

    // Enumerate all codecs except for codecs with field-of-use restrictions.
    // Sort the results.

    DWORD dwFlags = 
        (MFT_ENUM_FLAG_ALL & (~MFT_ENUM_FLAG_FIELDOFUSE)) | 
        MFT_ENUM_FLAG_SORTANDFILTER;

    hr = MFTranscodeGetAudioOutputAvailableTypes(MFAudioFormat_WMAudioV9, 
        dwFlags, NULL, &pAvailableTypes);
    if (FAILED(hr))
    {
        goto done;
    }

    hr = pAvailableTypes->GetElementCount(&dwMTCount);
    if (FAILED(hr))
    {
        goto done;
    }
    if (dwMTCount == 0)
    {
        hr = E_FAIL;
        goto done;
    }

    // Get the first audio type in the collection and make a copy.
    hr = GetCollectionObject(pAvailableTypes, 0, &pAudioType);
    if (FAILED(hr))
    {
        goto done;
    }

    hr = MFCreateAttributes(&pAudioAttrs, 0);       
    if (FAILED(hr))
    {
        goto done;
    }

    hr = pAudioType->CopyAllItems(pAudioAttrs);
    if (FAILED(hr))
    {
        goto done;
    }

    // Set the audio attributes on the profile.
    hr = pProfile->SetAudioAttributes(pAudioAttrs);
    if (FAILED(hr))
    {
        goto done;
    }

    // Set the container attributes.
    hr = MFCreateAttributes(&pContainer, 1);
    if (FAILED(hr))
    {
        goto done;
    }

    hr = pContainer->SetGUID(MF_TRANSCODE_CONTAINERTYPE, MFTranscodeContainerType_ASF);
    if (FAILED(hr))
    {
        goto done;
    }

    hr = pProfile->SetContainerAttributes(pContainer);
    if (FAILED(hr))
    {
        goto done;
    }

    *ppProfile = pProfile;
    (*ppProfile)->AddRef();

done:
    SafeRelease(&pProfile);
    SafeRelease(&pAvailableTypes);
    SafeRelease(&pAudioType);
    SafeRelease(&pAudioAttrs);
    SafeRelease(&pContainer);
    return hr;
}

需求

   
最低支援的用戶端 Windows 7 [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2008 R2 [僅限桌面應用程式]
目標平台 Windows
標頭 mfidl.h
程式庫 Mf.lib
Dll Mf.dll

另請參閱

IMFTranscodeProfile

MFTranscodeGetAudioOutputAvailableTypes

媒體基礎函式

轉碼 API