IWMEncAudienceObj::put_VideoKeyFrameDistance

Windows Media Encoder SDK banner art

The put_VideoKeyFrameDistance method specifies the video key frame setting.

Syntax

HRESULT put_VideoKeyFrameDistance(
  short  iRenderSiteIndex,
  WMENC_LONGLONG  llKFS
);

Parameters

iRenderSiteIndex

[in]  short containing the audience stream index. Because an audience can only contain one stream of each type, iRenderSiteIndex must be zero.

llKFS

[in]  A WMENC_LONGLONG indicating the key frame interval. When retrieving this value, divide by 1000 for seconds, and multiply the interval by 1000 when setting this value.

Return Values

If the method succeeds, it returns S_OK. If it fails, it supports the IErrorInfo interface and returns an HRESULT error code.

Remarks

The video key-frame interval indicates the number of seconds that separates key frames. For high-motion content, use a smaller value, which results in more key frames and a larger file size. For content with static backgrounds, use a higher value, which results in fewer key frames and a smaller file size.

The WMENC_LONGLONG data type is a typedef from the CURRENCY type. A 64-bit integer is needed to hold the elapsed time, and CURRENCY is the only 64-bit integer type that Automation supports. However, CURRENCY is a fixed-point type that has the decimal point moved four places to the left. Therefore, to display the CURRENCY value as a true integer and retrieve the correct elapsed time, you must multiply the value pointed to by 10,000.

To manipulate the value, you can use the following:

    llKFS.int64

Example Code

// Include libraries.
#include <windows.h>
#include <atlbase.h>
#include <comdef.h>
#include "C:\WMSDK\WMEncSDK9\include\wmencode.h"

    // Declare variables.
    HRESULT hr;
    IWMEncoder* pEncoder;
    IWMEncProfileCollection* pProColl;
    IWMEncProfile* pPro;

    IWMEncProfile2* pPro2;
    IWMEncAudienceObj* pAudnc;

    // 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 specific profile.
    if ( SUCCEEDED( hr ) )
    {
        hr = pEncoder->get_ProfileCollection(&pProColl);
    }
    if ( SUCCEEDED( hr ) )
    {
        hr = pProColl->Item(11, &pPro);
    }

    if ( SUCCEEDED( hr ) )
    {
        hr = CoCreateInstance(CLSID_WMEncProfile2,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IWMEncProfile2,
            (void**) &pPro2);
    }

    if ( SUCCEEDED( hr ) )
    {
        hr = pPro2->LoadFromIWMProfile(pPro);
    }

    // Retrieve the first audience in the profile.
    if ( SUCCEEDED( hr ) )
    {
        hr = pPro2->get_Audience(0, &pAudnc);
    }

    // Retrieve a value indicating the key frame interval.
    WMENC_LONGLONG lVidFrameInt;
    if ( SUCCEEDED( hr ) )
    {
        hr = pAudnc->get_VideoKeyFrameDistance(0, &lVidFrameInt);
    }

    // Set a new value indicating the key frame interval. 
    lVidFrameInt.int64 = 4000*10000;     // 4 seconds.
    if ( SUCCEEDED( hr ) )
    {
        hr = pAudnc->put_VideoKeyFrameDistance(0, lVidFrameInt);
    }

    // Release pointers.
    if ( pAudnc )
    {
        pAudnc->Release();
        pAudnc = NULL;
    }
    if ( pPro2 )
    {
        pPro2->Release();
        pPro2 = NULL;
    }

Requirements

Header: wmencode.h

Library: wmenc.exe

See Also