Enumerating MKV Format Compatible Compressors Example for C++

The following code enumerates the valid audio and video compressors for the MKV target format.

// include the LEAD Media Foundation TOOLKIT header 
#include "ltmf.h" 
void EnumMKVCompressors(IltmfConvert *pConvert, HWND hwndParent) 
{ 
   IltmfCompressors *pCompressors; 
   IltmfCompressor *pCompressor; 
   IltmfTargetFormats *pTargetformats; 
   IltmfTargetFormat* pTargetformat; 
   long lCount, lIndex, lValid; 
   BSTR Name; 
   VARIANT_BOOL vbIsLeadTargetFormat; 
    
   // set the target format to MKV 
   pConvert->put_TargetFormat(ltmfConvert_TargetFormat_MKV); 
   pConvert->get_TargetFormats(&pTargetformats); 
   pTargetformats->Item(ltmfConvert_TargetFormat_MKV, &pTargetformat); 
   pTargetformats->Release(); 
    
   // state whether this is a LEAD target format 
   pTargetformat->LeadTargetFormat(&vbIsLeadTargetFormat); 
    
   // LEAD target format, enum compressors through AudioCompressors and VideoCompressors interfaces. 
   if ( vbIsLeadTargetFormat ) 
   { 
      // Audio 
      // get the compressors collection 
      pConvert->get_AudioCompressors(&pCompressors); 
      pCompressors->get_Count(&lCount); 
      for (lIndex = 0; lIndex < lCount; lIndex++) 
      { 
         pCompressors->Item(lIndex, &pCompressor); 
         pCompressor->get_Name(&Name); 
         pTargetformat->IsValidCompressor(Name, &lValid); 
         if (lValid != ltmfTargetFormat_Compressor_Invalid) 
         { 
            // do whatever needed with the valid compressor (i.e. add it to some list) 
         } 
         ::SysFreeString(Name); 
         pCompressor->Release(); 
      } 
      pCompressors->Release(); 
       
      // Video 
      // get the compressors collection 
      pConvert->get_VideoCompressors(&pCompressors); 
      pCompressors->get_Count(&lCount); 
      for (lIndex = 0; lIndex < lCount; lIndex++) 
      { 
         pCompressors->Item(lIndex, &pCompressor); 
         pCompressor->get_Name(&Name); 
         pTargetformat->IsValidCompressor(Name, &lValid); 
         if (lValid != ltmfTargetFormat_Compressor_Invalid) 
         { 
            // do whatever needed with the valid compressor (i.e. add it to some list) 
         } 
         ::SysFreeString(Name); 
         pCompressor->Release(); 
      } 
      pCompressors->Release(); 
   } 
   else 
   { 
      // not LEAD target format, use target format profile dialog. 
      VARIANT_BOOL vbDialog; 
      pTargetformat->HasDialog(ltmfTargetFormat_Dlg_Profile, &vbDialog); 
      if (vbDialog) 
      { 
         pTargetformat->ShowDialog(ltmfTargetFormat_Dlg_Profile, (long)hwndParent); 
      } 
   } 
   pTargetformat->Release(); 
} 

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

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