The ltmmConvert object allows the user to recompress multimedia files or convert from one multimedia format to another.
C Source
IltmmConvert* pConvert;CoCreateInstance(&CLSID_ltmmConvert, NULL, CLSCTX_INPROC_SERVER, &IID_IltmmConvert, (void**) &pConvert);
C++ Source
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.
C Source
HWND hwndNotify;#define WM_CONVERTNOTIFY (WM_USER + 1000)IltmmConvert_SetNotifyWindow (pConvert, (long) hwndNotify, WM_CONVERTNOTIFY);
C++ Source
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.
C Source
BSTR bstr;// create a string containing the source file pathbstr = SysAllocString(L"c:\\source.avi");// assign the source file path to the convert objectIltmmConvert_put_SourceFile (pConvert, bstr);// free the stringSysFreeString(bstr);
C++ Source
BSTR bstr;// create a string containing the source file pathbstr = SysAllocString(L"c:\\source.avi");// assign the source file path to the convert objectpConvert->put_SourceFile (bstr);// free the stringSysFreeString(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.
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.
The following code demonstrates how to enumerate the registered audio filters:
C Source
IltmmCompressors* pCompressors;long lCount;long i;// get an interface into audio compressors collectionIltmmConvert_get_AudioCompressors (pConvert, &pCompressors);// get the total number of registered compressorsIltmmCompressors_get_Count (pCompressors, &lCount);// enumerate all of the compressorsfor(i = 0; i < lCount; i++){IltmmCompressor* pCompressor;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith compressorIltmmCompressors_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 selectedIltmmCompressor_get_Selected (pCompressor, &fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the compressor interfaceIUnknown_Release(pCompressor);}// release the compressors interfaceIUnknown_Release(pCompressors);
C++ Source
IltmmCompressors* pCompressors;long lCount;long i;// get an interface into audio compressors collectionpConvert->get_AudioCompressors (&pCompressors);// get the total number of registered compressorspCompressors->get_Count (&lCount);// enumerate all of the compressorsfor(i = 0; i < lCount; i++){IltmmCompressor* pCompressor;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith compressorpCompressors->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 selectedpCompressor->get_Selected (&fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the compressor interfacepCompressor->Release();}// release the compressors interfacepCompressors->Release();
C Source
IltmmCompressors* pCompressors;long lCount;long i;// get an interface into video compressors collectionIltmmConvert_get_VideoCompressors (pConvert, &pCompressors);// get the total number of registered compressorsIltmmCompressors_get_Count (pCompressors, &lCount);// enumerate all of the compressorsfor(i = 0; i < lCount; i++){IltmmCompressor* pCompressor;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith compressorIltmmCompressors_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 selectedIltmmCompressor_get_Selected (pCompressor, &fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the compressor interfaceIUnknown_Release(pCompressor);}// release the compressors interfaceIUnknown_Release(pCompressors);
C++ Source
IltmmCompressors* pCompressors;long lCount;long i;// get an interface into video compressors collectionpConvert->get_VideoCompressors (&pCompressors);// get the total number of registered compressorspCompressors->get_Count (&lCount);// enumerate all of the compressorsfor(i = 0; i < lCount; i++){IltmmCompressor* pCompressor;BSTR bstrName;BSTR bstrFriendlyName;VARIANT_BOOL fSelected;// get an interface for the ith compressorpCompressors->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 selectedpCompressor->get_Selected (&fSelected);//// add additional code here//// free stringsSysFreeString(bstrName);SysFreeString(bstrFriendlyName);// release the compressor interfacepCompressor->Release();}// release the compressors interfacepCompressors->Release();
Note: The only difference between enumerating audio and video compressors is in the initial collection object retrieved.
C Source
IltmmCompressors* pCompressors;// get an interface into audio compressors collectionIltmmConvert_get_AudioCompressors(pConvert, &pCompressors);// select compressorIltmmCompressors_put_Selection (pCompressors, 10);// release collectionIUnknown_Release(pCompressors);
C++ Source
IltmmCompressors* pCompressors;// get an interface into audio compressors collectionpConvert->get_AudioCompressors (&pCompressors);// select compressorpCompressors->put_Selection (10);// release collectionpCompressors->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.
C Source
BSTR bstr;// create a string containing the target file pathbstr = SysAllocString(L"c:\\target.avi");// assign the target file path to the convert objectIltmmConvert_put_TargetFile(pConvert, bstr);// free the stringSysFreeString(bstr);
C++ Source
BSTR bstr;// create a string containing the target file pathbstr = SysAllocString(L"c:\\target.avi");// assign the target file path to the convert objectpConvert->put_TargetFile (bstr);// free the stringSysFreeString(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.
C Source
// set the output format to WAVE audioIltmmConvert_put_TargetFormat (pConvert, ltmmConvert_TargetFormat_WAVE);
C++ Source
// set the output format to WAVE audiopConvert->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.
C Source
HWND hwndMain;// audio compression propertiesIltmmConvert_ShowDialog (pConvert, ltmmConvert_Dlg_AudioCompressor, (long) hwndMain);// video compression propertiesIltmmConvert_ShowDialog(pConvert, ltmmConvert_Dlg_VideoCompressor, (long) hwndMain);// target format propertiesIltmmConvert_ShowDialog(pConvert, ltmmConvert_Dlg_TargetFormat, (long) hwndMain);
C++ Source
HWND hwndMain;// audio compression propertiespConvert->ShowDialog (ltmmConvert_Dlg_AudioCompressor, (long) hwndMain);// video compression propertiespConvert->ShowDialog(ltmmConvert_Dlg_VideoCompressor, (long) hwndMain);// target format propertiespConvert->ShowDialog (ltmmConvert_Dlg_TargetFormat, (long) hwndMain);
You can test for the existence of any dialog with the HasDialog function.
C Source
IltmmConvert_StartConvert (pConvert); C++ Source
pConvert->StartConvert (); LRESULT ConvertWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){if(msg == WM_CONVERTNOTIFY){switch(wParam){case ltmmConvert_Notify_Started:// conversion startedbreak;case ltmmConvert_Notify_Complete:// conversion successfully completedbreak;case ltmmConvert_Notify_ErrorAbort:// a conversion error occurred// the error code is contained in lParambreak;case ltmmConvert_Notify_UserAbort:// the StopConvert function was calledbreak;case ltmmConvert_Notify_Progress:// the current completion percentage is in lParambreak;}}return 0;}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
