IWMEncProfile2::EnumAudioCodec

Windows Media Encoder SDK banner art

The EnumAudioCodec method retrieves the name and FOURCC value of a specific audio codec.

Syntax

HRESULT EnumAudioCodec(
  long  lCodecIndex,
  VARIANT*  pvarName,
  long*  lFormatTag
);

Parameters

lCodecIndex

[in]  long containing the audio codec index.

pvarName

[out]  Pointer to a VARIANT specifying the name.

lFormatTag

[out]  Pointer to a long that indicates the FOURCC value of the audio codec.

Return Values

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

Return code Number Description
E_POINTER 0x80004003 The pointer to the name or FourCC value is NULL.

Remarks

Use the IWMEncAudienceObj::get_AudioCodec method to retrieve the index of the audio codec that is used by the current profile. Use the get_AudioCodecCount method to retrieve the total number of audio codecs available in the current profile, which is determined by the variable bit rate (VBR) mode that is specified for the audio stream.

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 the index of the audio codec that is used by the current
    // audience.
    long lAudCodec;
    if ( SUCCEEDED( hr ) )
    {
        hr = pAudnc->get_AudioCodec (0, &lAudCodec); 
    }

    // Retrieve the index of the audio format that is used by the current
    // audio codec.
    long lAudFormat;
    if ( SUCCEEDED( hr ) )
    {
        hr = pAudnc->get_AudioFormat(0, &lAudFormat);
    }

    // Using the audio codec index, retrieve its name and FOURCC value.
    long lAud4cc; 
    CComVariant vAudCodecName;
    if ( SUCCEEDED( hr ) )
    {
        hr = pPro2->EnumAudioCodec(lAudCodec, &vAudCodecName, &lAud4cc);
    }

    // Use the audio format index to retrieve information such as its name.
    long lAudVal1;
    CComVariant vAudFormatName;
    CComVariant vChannels;
    CComVariant vSRate; 
    CComVariant vBitSample;
    if ( SUCCEEDED( hr ) )
    {
        hr = pPro2->EnumAudioFormat (lAudCodec, lAudFormat, &vAudFormatName, &vSRate, &vChannels, &vBitSample, &lAudVal1); 
    }

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

Requirements

Header: wmencode.h

Library: wmenc.exe

See Also