Partilhar via


Usando a exclusão mútua de taxa de bits múltipla

[A funcionalidade associada a esta página, Windows Media Format 11 SDK, é uma funcionalidade herdada. Foi substituído por Source Reader e Sink Writer. Source Reader e Sink Writer foram otimizados para Windows 10 e Windows 11. A Microsoft recomenda vivamente que o novo código utilize do Leitor de Origem e do Gravador de Separadores em vez de SDK do Windows Media Format 11, sempre que possível. A Microsoft sugere que o código existente que usa as APIs herdadas seja reescrito para usar as novas APIs, se possível.]

A exclusão mútua de múltiplas taxas de bits (MBR) é útil quando se pretende codificar conteúdo para uma variedade de situações de reprodução. Uma saída de vídeo MBR consiste em uma única entrada codificada várias vezes, cada uma com diferentes configurações de taxa de bits. Quando um arquivo com codificação MBR é lido, o leitor determinará qual fluxo usar com base na largura de banda disponível.

O SDK do Windows Media Format suporta codificação MBR para fluxos de vídeo e áudio. Além disso, você pode criar um tipo especial de codificação MBR chamado codificação MBR de vários tamanhos de vídeo. O vídeo MBR de vários tamanhos funciona de forma idêntica ao vídeo MBR normal, exceto que pode especificar diferentes resoluções de imagem para os fluxos de vídeo na exclusão mútua.

O exemplo a seguir demonstra como configurar um perfil para vídeo MBR com vários tamanhos de vídeo. Ele cria um novo perfil com três fluxos de vídeo de diferentes taxas de bits e tamanhos, e os inclui em um objeto de exclusão mútua.

IWMProfileManager*  pProfileMgr = NULL;
IWMProfile*         pProfile    = NULL;
IWMMutualExclusion* pMutex      = NULL;
IWMStreamConfig*    pStream     = NULL;
IWMMediaProps*      pMediaProps = NULL;

WM_MEDIA_TYPE*      pMediaType  = NULL;
DWORD               cbMediaType = 0;

HRESULT hr = S_OK;

// Initialize COM.
hr = CoInitialize(NULL);

// Create a profile manager object.
hr = WMCreateProfileManager(&pProfileMgr);

// Create an empty profile.
hr = pProfileMgr->CreateEmptyProfile(WMT_VER_9_0, &pProfile);

// Give the new profile a name and description.
hr = pProfile->SetName(L"MBR_Video_3_Stream_test");
hr = pProfile->SetDescription(L"Only for use with example code.");

// Create the first stream.
hr = pProfile->CreateNewStream(WMMEDIATYPE_Video, &pStream);

// Get the media properties interface for the new stream.
hr = pStream->QueryInterface(IID_IWMMediaProps, (void**)&pMediaProps);

// Get the media-type structure.
// First, get the size of the media-type structure.
hr = pMediaProps->GetMediaType(NULL, &cbMediaType);

// Allocate memory for the structure based on the retrieved size.
pMediaType = (WM_MEDIA_TYPE*) new BYTE[cbMediaType];

// Retrieve the media-type structure.
hr = pMediaProps->GetMediaType(pMediaType, &cbMediaType);

// Change the video size to 640 x 480.
pMediaType->pbFormat->bmiHeader.biWidth  = 640;
pMediaType->pbFormat->bmiHeader.biHeight = 480;

// Replace the WM_MEDIA_TYPE in the profile with the one just changed.
hr = pMediaProps->SetMediaType(pMediaType);

// Release the media properties interface and delete the structure.
pMediaProps->Release();
pMediaProps = NULL;
delete[] pMediaType;
pMediaType = NULL;

// Set the bit rate to 200.
hr = pStream->SetBitrate(200000);

// Set the stream number.
hr = pStream->SetStreamNumber(1);

// Include the new stream in the profile.
hr = pProfile->AddStream(pStream);

// Release the stream configuration interface.
pStream->Release();
pStream = NULL;

// For the remaining two streams, leave the video at its default size of
// 320 x 240 <entity type="ndash"/>- just change the bit rates.

// Repeat for a 100K stream.
hr = pProfile->CreateNewStream(WMMEDIATYPE_Video, &pStream);
hr = pStream->SetBitrate(100000);
hr = pStream->SetStreamNumber(2);
hr = pProfile->AddStream(pStream);
pStream->Release();
pStream = NULL;

// Repeat for a 56K stream.
hr = pProfile->CreateNewStream(WMMEDIATYPE_Video, &pStream);
hr = pStream->SetBitrate(56000);
hr = pStream->SetStreamNumber(3);
hr = pProfile->AddStream(pStream);
pStream->Release();
pStream = NULL;

// Now that we have three streams, create a mutual exclusion object.
hr = pProfile->CreateNewMutualExclusion(&pMutex);

// Add the three streams to the mutual exclusion.
hr = pMutex->AddStream(1);
hr = pMutex->AddStream(2);
hr = pMutex->AddStream(3);

// Configure the mutual exclusion for MBR video.
hr = pMutex->SetType(CLSID_WMMUTEX_Bitrate);

// Add the mutual exclusion to the profile.
hr = pProfile->AddMutualExclusion(pMutex);

// Release the mutual exclusion object.
pMutex->Release();
pMutex = NULL;

// TODO: Save the profile to a string, and save the string to a file.
// For more information, see To Save a Custom Profile.

// Release remaining interfaces.
pProfile->Release();
pProfile = NULL;

pProfileMgr->Release();
pProfileMgr = NULL;

Interface IWMMediaProps

Interface IWMMutualExclusion

Interface IWMProfile

Interface IWMStreamConfig

Usando a exclusão mútua

WM_MEDIA_TYPE