共用方式為


指派輸入格式

[與此頁面相關聯的功能 Windows Media Format 11 SDK是舊版功能。 來源讀取器接收寫入器已取代它。 來源讀取器接收寫入器 已針對 Windows 10 和 Windows 11 優化。 Microsoft強烈建議新程式碼盡可能使用 Source ReaderSink Writer,而不用 Windows Media Format 11 SDK,如果可能。 Microsoft建議使用舊版 API 的現有程式代碼,盡可能改寫成使用新的 API。]

當您識別出符合數據的輸入格式時,您可以呼叫 IWMWriter::SetInputProps來設定它供寫入器使用。

針對視訊串流,您必須設定輸入範例中的畫面大小。 下列範例程式代碼示範如何設定和設定視訊輸入。 它會使用 To Enumerate Input Format 區段中定義的 FindInputFormat 函式來取得 24 位 RGB 視訊的輸入格式。 如需使用此程式碼的詳細資訊,請參閱 使用程式碼範例

HRESULT ConfigureVideoInput(IWMWriter* pWriter,
                            DWORD dwInput,
                            GUID guidSubType,
                            LONG lFrameWidth,
                            LONG lFrameHeight)
{
    DWORD   cbSize = 0;
    LONG    lStride = 0;

    IWMInputMediaProps* pProps  = NULL;
    WM_MEDIA_TYPE*      pType   = NULL;
    WMVIDEOINFOHEADER*  pVidHdr = NULL;
    BITMAPINFOHEADER*   pbmi    = NULL;

    // Get the base input format for the required subtype.
    HRESULT hr = FindInputFormat(pWriter, dwInput, guidSubType, &pProps);
    if (FAILED(hr))
    {
        goto Exit;
    }

    // Get the size of the media type structure.
    hr = pProps->GetMediaType(NULL, &cbSize);
    if (FAILED(hr))
    {
        goto Exit;
    }

    // Allocate memory for the media type structure.
    pType = (WM_MEDIA_TYPE*) new (std::nothrow) BYTE[cbSize];
    if (pType == NULL)
    {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }
    
    // Get the media type structure.
    hr = pProps->GetMediaType(pType, &cbSize);
    if (FAILED(hr))
    {
        goto Exit;
    }

    // Adjust the format to match your source images.

    // First set pointers to the video structures.
    pVidHdr = (WMVIDEOINFOHEADER*) pType->pbFormat;
    pbmi  = &(pVidHdr->bmiHeader);
        
    pbmi->biWidth  = lFrameWidth;  
    pbmi->biHeight = lFrameHeight;
    
    // Stride = (width * bytes/pixel), rounded to the next DWORD boundary.
    lStride = (lFrameWidth * (pbmi->biBitCount / 8) + 3) & ~3;


    // Image size = stride * height. 
    pbmi->biSizeImage = lFrameHeight * lStride;

    // Apply the adjusted type to the video input. 
    hr = pProps->SetMediaType(pType);
    if (FAILED(hr))
    {
        goto Exit;
    }

    hr = pWriter->SetInputProps(dwInput, pProps);

Exit:
    delete [] pType;
    SAFE_RELEASE(pProps);
    return hr;
}

處理輸入