Use ltmmConvert to Perform a Simple File Conversion

The ltmmConvert object allows the user to recompress multimedia files or convert from one multimedia format to another.

  1. To begin simple conversion, first create an instance of the ltmmConvert class. Do so using the Win32 CoCreateInstance function as follows:

    C API
    IltmmConvert* pConvert;   
    CoCreateInstance(&CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmConvert, (void**) &pConvert); 
    C++
    IltmmConvert* pConvert;    
    CoCreateInstance(CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, IID_IltmmConvert, (void**) &pConvert); 

    The function creates an instance of ltmmConvert and returns an IltmmConvert interface pointer. It is through the IltmmConvert interface that the conversion process is controlled.

  2. Define a window to send conversion status messages:

    C API
    HWND hwndNotify;    
    #define WM_CONVERTNOTIFY (WM_USER + 1000)    
    IltmmConvert_SetNotifyWindow (pConvert, (long) hwndNotify, WM_CONVERTNOTIFY); 
    C++
    HWND hwndNotify;    
    #define WM_CONVERTNOTIFY (WM_USER + 1000)    
    pConvert->SetNotifyWindow ((long) hwndNotify, WM_CONVERTNOTIFY); 

    The above code instructs the convert object to send WM_CONVERTNOTIFY messages to the window procedure for hwndNotify. The wParam parameter of the window message will contain the notification code.

    Note

    A conversion can be accomplished without the use of the notification window, but the user would be required to poll the object's state to determine when the conversion has finished.

  3. Define the source or input file as demonstrated with the following code:

    C API
    BSTR bstr;    
    // create a string containing the source file path   
    bstr = SysAllocString(L"c:\\source.avi");    
    // assign the source file path to the convert object   
    IltmmConvert_put_SourceFile (pConvert,  bstr);    
    // free the string   
    SysFreeString(bstr); 
    C++
    BSTR bstr;    
    // create a string containing the source file path   
    bstr = SysAllocString(L"c:\\source.avi");   
    // assign the source file path to the convert object   
    pConvert->put_SourceFile (bstr);    
    // free the string   
    SysFreeString(bstr); 

    The code above allocates a string containing an AVI file path and assigns the path to the convert object with a call to put_SourceFile.

  4. Define audio and video compressors to be used for the conversion process. If you do not want to change the current compression, then you should just skip this step. The ltmmConvert object contains audio and video compressor collection objects. These objects allow the user to enumerate the registered audio and video compressors and to select the compressors to use during the conversion process.

  5. The following code demonstrates how to enumerate the registered audio filters:

    C API
    IltmmCompressors* pCompressors; 
    long lCount; 
    long i; 
    // get an interface into audio compressors collection 
    IltmmConvert_get_AudioCompressors (pConvert, &pCompressors); 
    // get the total number of registered compressors 
    IltmmCompressors_get_Count (pCompressors, &lCount); 
    // enumerate all of the compressors 
    for(i = 0; i < lCount; i++) 
    { 
       IltmmCompressor* pCompressor; 
       BSTR bstrName; 
       BSTR bstrFriendlyName; 
       VARIANT_BOOL fSelected; 
       // get an interface for the ith compressor 
       IltmmCompressors_Item (pCompressors, i, &pCompressor); 
       // get the compressors "full name" (used to uniquely identify the compressor) 
       IltmmCompressor_get_Name (pCompressor, &bstrName); 
       // get the compressors "friendly name"  (used for readable display) 
       IltmmCompressor_get_FriendlyName (pCompressor, &bstrFriendlyName); 
       // query whether the compressor is currently selected 
       IltmmCompressor_get_Selected (pCompressor, &fSelected); 
       // 
       // add additional code here 
       // 
       // free strings 
       SysFreeString(bstrName); 
       SysFreeString(bstrFriendlyName); 
       // release the compressor interface 
       IUnknown_Release(pCompressor); 
    } 
    // release the compressors interface 
    IUnknown_Release(pCompressors); 
    C++
    IltmmCompressors* pCompressors; 
    long lCount; 
    long i; 
    // get an interface into audio compressors collection 
    pConvert->get_AudioCompressors (&pCompressors); 
    // get the total number of registered compressors 
    pCompressors->get_Count (&lCount); 
    // enumerate all of the compressors 
    for(i = 0; i < lCount; i++) 
    { 
       IltmmCompressor* pCompressor; 
       BSTR bstrName; 
       BSTR bstrFriendlyName; 
       VARIANT_BOOL fSelected; 
       // get an interface for the ith compressor 
       pCompressors->Item (i, &pCompressor); 
       // get the compressors "full name" (used to uniquely identify the compressor) 
       pCompressor->get_Name (&bstrName); 
       // get the compressors "friendly name"  (used for readable display) 
       pCompressor->get_FriendlyName (&bstrFriendlyName); 
       // query whether the compressor is currently selected 
       pCompressor->get_Selected (&fSelected); 
       // 
       // add additional code here 
       // 
       // free strings 
       SysFreeString(bstrName); 
       SysFreeString(bstrFriendlyName); 
       // release the compressor interface 
       pCompressor->Release(); 
    } 
    // release the compressors interface 
    pCompressors->Release(); 

  6. The registered video compressors can be enumerated with the following code:

    C API
    IltmmCompressors* pCompressors; 
    long lCount; 
    long i; 
    // get an interface into video compressors collection 
    IltmmConvert_get_VideoCompressors (pConvert, &pCompressors); 
    // get the total number of registered compressors 
    IltmmCompressors_get_Count (pCompressors, &lCount); 
    // enumerate all of the compressors 
    for(i = 0; i < lCount; i++) 
    { 
       IltmmCompressor* pCompressor; 
       BSTR bstrName; 
       BSTR bstrFriendlyName; 
       VARIANT_BOOL fSelected; 
       // get an interface for the ith compressor 
       IltmmCompressors_Item (pCompressors, i, &pCompressor); 
       // get the compressors "full name" (used to uniquely identify the compressor) 
       IltmmCompressor_get_Name (pCompressor, &bstrName); 
       // get the compressors "friendly name"  (used for readable display) 
       IltmmCompressor_get_FriendlyName (pCompressor, &bstrFriendlyName); 
       // query whether the compressor is currently selected 
       IltmmCompressor_get_Selected (pCompressor, &fSelected); 
       // 
       // add additional code here 
       // 
       // free strings 
       SysFreeString(bstrName); 
       SysFreeString(bstrFriendlyName); 
       // release the compressor interface 
       IUnknown_Release(pCompressor); 
    } 
    // release the compressors interface 
    IUnknown_Release(pCompressors); 
    C++
    IltmmCompressors* pCompressors; 
    long lCount; 
    long i; 
    // get an interface into video compressors collection 
    pConvert->get_VideoCompressors (&pCompressors); 
    // get the total number of registered compressors 
    pCompressors->get_Count (&lCount); 
    // enumerate all of the compressors 
    for(i = 0; i < lCount; i++) 
    { 
       IltmmCompressor* pCompressor; 
       BSTR bstrName; 
       BSTR bstrFriendlyName; 
       VARIANT_BOOL fSelected; 
       // get an interface for the ith compressor 
       pCompressors->Item (i, &pCompressor); 
       // get the compressors "full name" (used to uniquely identify the compressor) 
       pCompressor->get_Name (&bstrName); 
       // get the compressors "friendly name"  (used for readable display) 
       pCompressor->get_FriendlyName (&bstrFriendlyName); 
       // query whether the compressor is currently selected 
       pCompressor->get_Selected (&fSelected); 
       // 
       // add additional code here 
       // 
       // free strings 
       SysFreeString(bstrName); 
       SysFreeString(bstrFriendlyName); 
       // release the compressor interface 
       pCompressor->Release(); 
    } 
    // release the compressors interface 
    pCompressors->Release(); 

    Note

    The only difference between enumerating audio and video compressors is in the initial collection object retrieved.

  7. An individual compressor can be selected for the conversion process by calling the compressor collection's put_Selection function:

    C API
    IltmmCompressors* pCompressors;    
    // get an interface into audio compressors collection   
    IltmmConvert_get_AudioCompressors(pConvert, &pCompressors);    
    // select compressor 
    IltmmCompressors_put_Selection (pCompressors, 10);    
    // release collection   
    IUnknown_Release(pCompressors); 
    C++
    IltmmCompressors* pCompressors;    
    // get an interface into audio compressors collection   
    pConvert->get_AudioCompressors (&pCompressors);    
    // select compressor   
    pCompressors->put_Selection (10);    
    // release collection   
    pCompressors->Release(); 
    The previous code selects the 10th compressor to be used for the conversion. You can also deselect any compressor by passing a 1 as the item's index.

  8. Define the target or output file. As demonstrated with the following code:

    C API
    BSTR bstr;    
    // create a string containing the target file path   
    bstr = SysAllocString(L"c:\\target.avi");    
    // assign the target file path to the convert object   
    IltmmConvert_put_TargetFile(pConvert,  bstr);    
    // free the string   
    SysFreeString(bstr); 
    C++
    BSTR bstr;    
    // create a string containing the target file path   
    bstr = SysAllocString(L"c:\\target.avi");    
    // assign the target file path to the convert object   
    pConvert->put_TargetFile (bstr);    
    // free the string   
    SysFreeString(bstr); 
    The code above allocates a string containing an AVI file path and assigns the path to the convert object with a call to put_TargetFile.

  9. Optionally, you may decide that you would like to generate an WMV, WAV, or MP3 output file. For information about Windows Media Support, click here. You can change the target format with the following code:

    C API
    // set the output format to WAVE audio   
    IltmmConvert_put_TargetFormat (pConvert, ltmmConvert_TargetFormat_WAVE); 
    C++
    // set the output format to WAVE audio   
    pConvert->put_TargetFormat (ltmmConvert_TargetFormat_WAVE); 
    Some formats require specific compressors. For example, ltmmConvert_TargetFormat_Asf requires that you not select any additional compressors, whereas ltmmConvert_TargetFormat_MPEG1Audio requires that you select a MPEG (MP3) audio compressor.

  10. You can now (optionally) set compressor and format properties using the ShowDialog function:

    C API
    HWND hwndMain;    
    // audio compression properties   
    IltmmConvert_ShowDialog (pConvert, ltmmConvert_Dlg_AudioCompressor, (long) hwndMain);    
    // video compression properties   
    IltmmConvert_ShowDialog(pConvert, ltmmConvert_Dlg_VideoCompressor, (long) hwndMain);    
    // target format properties   
    IltmmConvert_ShowDialog(pConvert, ltmmConvert_Dlg_TargetFormat, (long) hwndMain); 
    C++
    HWND hwndMain;    
    // audio compression properties   
    pConvert->ShowDialog (ltmmConvert_Dlg_AudioCompressor, (long) hwndMain);    
    // video compression properties   
    pConvert->ShowDialog(ltmmConvert_Dlg_VideoCompressor, (long) hwndMain);    
    // target format properties   
    pConvert->ShowDialog (ltmmConvert_Dlg_TargetFormat, (long) hwndMain); 
    You can test for the existence of any dialog with the HasDialog function.

  11. You are now ready to start the conversion. This is accomplished with the following code:

    C API
    IltmmConvert_StartConvert (pConvert); 
    C++
    pConvert->StartConvert (); 

  12. The notification window will be sent messages indicating the current conversion progress:

    LRESULT ConvertWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 
    { 
       if(msg == WM_CONVERTNOTIFY) 
       { 
          switch(wParam) 
          { 
          case ltmmConvert_Notify_Started: 
             // conversion started 
             break; 
          case ltmmConvert_Notify_Complete: 
             // conversion successfully completed 
             break; 
          case ltmmConvert_Notify_ErrorAbort: 
             // a conversion error occurred 
             // the error code is contained in lParam 
             break; 
          case ltmmConvert_Notify_UserAbort: 
             // the StopConvert function was called 
             break; 
          case ltmmConvert_Notify_Progress: 
             // the current completion percentage is in lParam 
             break; 
          } 
       } 
       return 0; 
    } 

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.