Share via


IWMEncPostViewCollection::get_ViewBandwidth

Windows Media Encoder SDK banner art

The get_ViewBandwidth method retrieves the bit rate of the preview video stream.

Syntax

HRESULT get_ViewBandwidth(
  long*  plBandwidth
);

Parameters

plBandwidth

[out]  Pointer to a long containing the bit rate of the preview stream.

Return Values

If the method succeeds, it returns S_OK. If it fails, it returns an HRESULT error code.

Return code Number Description
E_POINTER 0x80004003 The pointer to the bit rate is NULL.

Remarks

If multiple bit rate streams are produced from a single input stream, you can choose which stream to preview by using the IWMEncPostViewCollection::put_ViewBandwidth method. You can also switch between streams while the encoding process is running. Use the IWMEncProfile2 and IWMEncAudienceObj interfaces to determine which profiles contain multiple audiences.

If you specify a bit rate that does not exist, the first audience lower than the specified bit rate is viewed (or the lowest one if none are lower than the one you specify). For example, the available bit rates for a stream are 100 Kbps and 500 Kbps. If you specify 400 Kbps or 50 Kbps, the 100 Kbps stream is viewed. If you specify anything higher than 500 Kbps, the 500 Kbps stream is viewed.

Example Code

// Include libraries.

#include <windows.h>
#include <atlbase.h>
#include "wmencode.h"
#include "wmencvu.h"

// Declare variables.

    HRESULT hr;
    IWMEncoder* pEncoder;
    IWMEncDataView* pPostview;
    IWMEncDataViewCollection* pPostColl;
    IWMEncPostViewCollection* pPostViewColl;
    IWMEncSourceGroupCollection* pSrcGrpColl;
    IWMEncSourceGroup* pSrcGrp;
    IWMEncSource* pAudSrc;
    IWMEncSource* pVidSrc;
    IWMEncProfileCollection* pProColl;
    IWMEncProfile* pPro;

    long lCount;
    int i;

// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.

hr = CoInitialize(NULL);
if ( SUCCEEDED( hr ) )
{
    hr = CoCreateInstance(CLSID_WMEncoder,
                     NULL,
                     CLSCTX_INPROC_SERVER,
                     IID_IWMEncoder,
                     (void**) &pEncoder);
}

// Retrieve a pointer to an IWMEncSourceGroupCollection
// interface.

if ( SUCCEEDED( hr ) )
{
    hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
}

// Add a source group to the collection.

if ( SUCCEEDED( hr ) )
{
    hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
}

// Add a video and an audio source to the source group.

if ( SUCCEEDED( hr ) )
{
    hr = pSrcGrp->AddSource(WMENC_VIDEO, &pVidSrc);
}
if ( SUCCEEDED( hr ) )
{
    hr = pSrcGrp->AddSource(WMENC_AUDIO, &pAudSrc);
}

// Identify the capture cards.

if ( SUCCEEDED( hr ) )
{
    hr = pVidSrc->SetInput(CComBSTR("DEVICE://Default_Video_Device"));
}
if ( SUCCEEDED( hr ) )
{
    hr = pAudSrc->SetInput(CComBSTR("DEVICE://Default_Audio_Device"));
}

// Choose a profile from the collection. The following code
// example identifies a specific profile that supports
// the production of video streams at 7.0, 11.3, 24.0, and
// 87.1 Kbps.

    CComBSTR bstrName = NULL;
if ( SUCCEEDED( hr ) )
{
    hr = pEncoder->get_ProfileCollection(&pProColl);
}
if ( SUCCEEDED( hr ) )
{
    hr = pProColl->get_Count(&lCount);
}
for (i=0; i<lCount; i++)
{
    if ( SUCCEEDED( hr ) )
    {
        hr = pProColl->Item(i, &pPro);
    }
    if ( SUCCEEDED( hr ) )
    {
        hr = pPro->get_Name(&bstrName);
    }
    if (_wcsicmp(bstrName, CComBSTR("Video for dial-up modems or LAN (28.8 to 100 Kbps)"))==0)
    {
        // Set the profile in the source group.
        if ( SUCCEEDED( hr ) )
        {
            hr = pSrcGrp->put_Profile(CComVariant(pPro));
        }
        break;
    }
}

// Create a postview object.

if ( SUCCEEDED( hr ) )
{
    hr = CoCreateInstance( CLSID_WMEncPreview,
                           NULL,
                           CLSCTX_INPROC_SERVER,
                           IID_IWMEncDataView,
                           (void**)&pPostview);
}

// Retrieve a postview collection.

if ( SUCCEEDED( hr ) )
{
    hr = pVidSrc->get_PostviewCollection( &pPostColl );
}

// Add the postview object to the data view collection. If you set the
// cookie to -1, the encoding process automatically generates a unique
// cookie.

long lCookie = -1;
if ( SUCCEEDED( hr ) )
{
    hr = pPostColl->Add( pPostview, &lCookie);
}

// Retrieve a pointer to the IWMEncPostViewCollection object. This
// object contains the ViewBandWidth property.

if ( SUCCEEDED( hr ) )
{
    hr = pPostColl->QueryInterface(IID_IWMEncPostViewCollection,
                                  (void**) &pPostViewColl);
}

// Identify the video stream to preview by specifying
// the bit rate.

if ( SUCCEEDED( hr ) )
{
    hr = pPostViewColl->put_ViewBandwidth(11300);
}

// Continue configuring the encoding process.
// Initialize the encoding process.

if ( SUCCEEDED( hr ) )
{
    hr = pEncoder->PrepareToEncode(VARIANT_TRUE);
}

// Create a parent window for the postview, and specify the window
// settings for the encoding process. For instance, you can create a
// window by using the Platform SDK function CreateWindow() and pass the
// window handle retrieved from this function to the
// SetViewSetting() method.
// Windows Media Encoder embeds the postview window in the parent window.
// If you do not create a parent window and specify the display
// settings, Windows Media Encoder creates a default window for the
// postview.

HWND hWnd;
if ( SUCCEEDED( hr ) )
{
    hr = pPostview->SetViewSetting((DWORD) lCookie,
                                   sizeof(hWnd),
                                  (BYTE*)&hWnd);
}

// Start the encoding process.

if ( SUCCEEDED( hr ) )
{
    hr = pEncoder->Start();
}

// Start viewing the stream in a pop-up window.

if ( SUCCEEDED( hr ) )
{
    hr = pPostview->Start((DWORD) lCookie);
}

// Release pointers.
if ( pSrcGrpColl )
{
    pSrcGrpColl->Release();
    pSrcGrpColl = NULL;
}
if ( pSrcGrp )
{
    pSrcGrp->Release();
    pSrcGrp = NULL;
}
if ( pAudSrc )
{
    pAudSrc->Release();
    pAudSrc = NULL;
}
if ( pVidSrc )
{
    pVidSrc->Release();
    pVidSrc = NULL;
}
if ( pProColl )
{
    pProColl->Release();
    pProColl = NULL;
}
if ( pPro )
{
    pPro->Release();
    pPro = NULL;
}

if ( pPostview )
{
    pPostview->Release();
    pPostview = NULL;
}
if ( pPostColl )
{
    pPostColl->Release();
    pPostColl = NULL;
}
if ( pPostViewColl )
{
    pPostViewColl->Release();
    pPostViewColl = NULL;
}
if ( pEncoder )
{
    pEncoder->Release();
    pEncoder = NULL;
}

Requirements

Header: wmencvu.h

Library: wmprevu.dll

See Also