Using IAMStreamSelect To Select a Specific Audio Stream from an MPEG File

The IAMStreamSelect is a Direct Show interface for selecting which streams are played and retrieving information about them. An example of logical stream selection would be selecting a particular language (English, German, or French for example) from a set of audio streams that encode different national languages.

To use IAMStreamSelect to select a specific audio stream from an MPEG file with multiple audio streams, perform the following steps:

  1. Create an instance of ltmmPlay class:

    C API
    IltmmPlay* pPlay; 
    CoCreateInstance(&CLSID_ltmmPlay, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmPlay, (void**) &pPlay); 
    C++
    IltmmPlay* pPlay;   
    CoCreateInstance(&CLSID_ltmmPlay, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmPlay, (void**) &pPlay); 

  2. Set the source file:

    C API
    BSTR bstr;    
    // create a string containing the source file path   
    bstr = SysAllocString(L"C:\\MultipleAudio.mpg");    
    // assign the source file path to the play object   
    IltmmPlay_put_SourceFile(pPlay,  bstr);    
    // free the string   
    SysFreeString(bstr); 
    C++
    BSTR bstr;    
    // create a string containing the source file path   
    bstr = SysAllocString(L"C:\\MultipleAudio.mpg");   
    // assign the source file path to the play object   
    pPlay->put_SourceFile(bstr);    
    // free the string   
    SysFreeString(bstr); 

  3. The IAMStreamSelect is usually exposed by the file splitter (Demultiplexer), so you need to get a pointer to the splitter object:

    C API
    IUnknown* pSplitter;   
    IltmmPlay_GetSubObject (pPlay ,ltmmPlay_Object_Splitter, & pSplitter); 
    C++
    IUnknown* pSplitter;   
    pPlay->GetSubObject (ltmmPlay_Object_Splitter, & pSplitter); 

  4. Query for the IAMStreamSelect interface:

    C API
    IAMStreamSelect *pStreamSel = NULL;   
    IUnknown_QueryInterface(pSplitter, &IID_IAMStreamSelect, (void**)& pStreamSel);   
    IUnknown_Release(pSplitter); 
    C++
    IAMStreamSelect *pStreamSel = NULL;   
    pSplitter->QueryInterface(&IID_IAMStreamSelect, (void**)&pStreamSel);   
    pSplitter->Release(); 

  5. Use the IAMStreamSelect interface to select one of the available audio streams in the file:

    C API
    // retrieve the number of available streams in the file 
    DWORD dwCount; 
    int nIndex; 
    BOOL bAudio = FALSE; 
    BOOL bEnable = FALSE; 
    AM_MEDIA_TYPE *pmt; 
    DWORD dwFlags; 
    LCID lcid; 
    DWORD dwGroup; 
    WCHAR *pszName; 
    IUnknown *pObject; 
    IUnknown *pUnk; 
    IAMStreamSelect_Count(pStreamSel , &dwCount); 
    for( nIndex = 0; nIndex<dwCount; nIndex++ ) 
    { 
    // get information about the stream, and decide if this is an audio stream and you want to enable it: 
       IAMStreamSelect_Info(pStreamSel , nIndex, &pmt, &dwFlags, &lcid, &dwGroup, &pzsName, &pObject, &pUnk); 
        
       // based on your selection criterion 
       if( bAudio && bEnable ) 
          IAMStreamSelect_Enable(pStreamSel, nIndex, AMSTREAMSELECTENABLE_ENABLE); 
    } 
    IUnknown_Release(pStreamSel); 
    C++
    // retrieve the number of available streams in the file 
    DWORD dwCount; 
    int nIndex; 
    BOOL bAudio = FALSE; 
    BOOL bEnable = FALSE; 
    AM_MEDIA_TYPE *pmt; 
    DWORD dwFlags; 
    LCID lcid; 
    DWORD dwGroup; 
    WCHAR *pszName; 
    IUnknown *pObject; 
    IUnknown *pUnk; 
     
    pStreamSel->Count(&dwCount); 
    for( nIndex = 0; nIndex<dwCount; nIndex++ ) 
    { 
    // get information about the stream, and decide if this is an audio stream and you want to enable it: 
       pStreamSel->Info(nIndex, &pmt, &dwFlags, &lcid, &dwGroup, &pzsName, &pObject, &pUnk); 
        
       // based on your selection criterion 
       if( bAudio && bEnable ) 
          pStreamSel->Enable(nIndex,       AMSTREAMSELECTENABLE_ENABLE); 
    } 
    pStreamSel->Release(); 

  6. Play the file:

    C API
    IltmmPlay_Run (pPlay); 
    C++
    pPlay->Run (); 

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Multimedia C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.